Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.ExternalEvaluation Scientific/DotNetScilab/cs_example/Util.cs @ 10355

Last change on this file since 10355 was 10126, checked in by mkommend, 11 years ago

#2082: Forgot to add Util.cs.

File size: 1.5 KB
Line 
1using System;
2using Microsoft.Win32;
3
4namespace cs_example {
5  class Util {
6    private const string registryKey = @"SOFTWARE\Scilab";
7    private const string scilab_Install = @"LASTINSTALL";
8    private const string scilab_PATH = @"SCIPATH";
9
10    public static void AddScilabInstalltionPathToEnvironment() {
11      var currentPath = Environment.GetEnvironmentVariable("path");
12      if (currentPath == null) return;
13
14      var scilabPath = GetScilabInstallPath();
15      if (string.IsNullOrEmpty(scilabPath)) return;
16
17      Environment.SetEnvironmentVariable("path", scilabPath + ";" + currentPath);
18    }
19
20    private static string GetScilabInstallPath() {
21      using (var registryLocalMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)) {
22        using (var registryScilab = registryLocalMachine.OpenSubKey(registryKey)) {
23          if (registryScilab == null) return string.Empty;
24          var scilabVersion = registryScilab.GetValue(scilab_Install);
25          if (scilabVersion == null) return string.Empty;
26          using (var registryScilabVersion = registryScilab.OpenSubKey(scilabVersion.ToString())) {
27            if (registryScilabVersion == null) return string.Empty;
28            var scilabPath = registryScilabVersion.GetValue(scilab_PATH);
29            if (scilabPath == null) return string.Empty;
30            string path = scilabPath.ToString();
31            path += @"\bin";
32            return path;
33          }
34        }
35      }
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.