1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.PluginInfrastructure;
|
---|
24 | using Microsoft.Win32;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.Problems.ExternalEvaluation.Scilab {
|
---|
27 | /// <summary>
|
---|
28 | /// Plugin class for HeuristicLab.Problems.ExternalEvaluation.Scilab plugin.
|
---|
29 | /// </summary>
|
---|
30 | [Plugin("HeuristicLab.Problems.ExternalEvaluation.Scilab", "3.3.8.$WCREV$")]
|
---|
31 | [PluginFile("HeuristicLab.Problems.ExternalEvaluation.Scilab-3.3.dll", PluginFileType.Assembly)]
|
---|
32 | [PluginFile("DotNet-Component-SciLab.dll",PluginFileType.Assembly)]
|
---|
33 | [PluginFile("Scilab License.txt", PluginFileType.License)]
|
---|
34 | [PluginDependency("HeuristicLab.Collections", "3.3")]
|
---|
35 | [PluginDependency("HeuristicLab.Common", "3.3")]
|
---|
36 | [PluginDependency("HeuristicLab.Core", "3.3")]
|
---|
37 | [PluginDependency("HeuristicLab.Data", "3.3")]
|
---|
38 | [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
|
---|
39 | [PluginDependency("HeuristicLab.Operators", "3.3")]
|
---|
40 | [PluginDependency("HeuristicLab.Parameters", "3.3")]
|
---|
41 | [PluginDependency("HeuristicLab.Persistence", "3.3")]
|
---|
42 | [PluginDependency("HeuristicLab.Problems.ParameterOptimization", "3.3")]
|
---|
43 | public class HeuristicLabProblemsExternalEvaluationScilabPlugin : PluginBase {
|
---|
44 | private const string registryKey = @"SOFTWARE\Scilab";
|
---|
45 | private const string scilab_Install = @"LASTINSTALL";
|
---|
46 | private const string scilab_PATH = @"SCIPATH";
|
---|
47 |
|
---|
48 | private static bool loadedOnce = false;
|
---|
49 |
|
---|
50 | public override void OnLoad() {
|
---|
51 | base.OnLoad();
|
---|
52 | if (loadedOnce) return;
|
---|
53 |
|
---|
54 | var currentPath = Environment.GetEnvironmentVariable("path");
|
---|
55 | if (currentPath == null) return;
|
---|
56 |
|
---|
57 | var scilabPath = GetScilabInstallPath();
|
---|
58 | if (string.IsNullOrEmpty(scilabPath)) return;
|
---|
59 |
|
---|
60 | Environment.SetEnvironmentVariable("path", scilabPath + ";" + currentPath);
|
---|
61 | }
|
---|
62 |
|
---|
63 | private string GetScilabInstallPath() {
|
---|
64 | using (var registryLocalMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default)) {
|
---|
65 | using (var registryScilab = registryLocalMachine.OpenSubKey(registryKey)) {
|
---|
66 | if (registryScilab == null) return string.Empty;
|
---|
67 | var scilabVersion = registryScilab.GetValue(scilab_Install);
|
---|
68 | if (scilabVersion == null) return string.Empty;
|
---|
69 | using (var registryScilabVersion = registryScilab.OpenSubKey(scilabVersion.ToString())) {
|
---|
70 | if (registryScilabVersion == null) return string.Empty;
|
---|
71 | var scilabPath = registryScilabVersion.GetValue(scilab_PATH);
|
---|
72 | if (scilabPath == null) return string.Empty;
|
---|
73 | string path = scilabPath.ToString();
|
---|
74 | path += @"\bin";
|
---|
75 | return path;
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|