diff --git a/.vscode/launch.json b/.vscode/launch.json index 97883820..a1a2d325 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "C:/Program Files/Rhino/System/Rhino.exe", + "program": "C:/Program Files/Rhino 8/System/Rhino.exe", "args": ["/nosplash"], "cwd": "${workspaceFolder}", "console": "internalConsole", diff --git a/Tunny/Handler/PythonInstaller.cs b/Tunny/Handler/PythonInstaller.cs index 69a4836d..733e36f8 100644 --- a/Tunny/Handler/PythonInstaller.cs +++ b/Tunny/Handler/PythonInstaller.cs @@ -3,11 +3,13 @@ using System.IO; using System.IO.Compression; +using Tunny.Util; + namespace Tunny.Handler { public static class PythonInstaller { - public static string Path { get; set; } = "."; + public static string ComponentFolderPath { get; set; } public static void Run(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; @@ -20,18 +22,19 @@ public static void Run(object sender, DoWorkEventArgs e) private static string[] UnzipLibraries() { - if (Directory.Exists(Path + "/python")) + string envPath = TunnyVariables.TunnyEnvPath; + if (Directory.Exists(envPath + "/python")) { - Directory.Delete(Path + "/python", true); + Directory.Delete(envPath + "/python", true); } - ZipFile.ExtractToDirectory(Path + "/Lib/python.zip", Path + "/python"); + ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/python.zip", envPath + "/python"); - if (Directory.Exists(Path + "/Lib/whl")) + if (Directory.Exists(envPath + "/Lib/whl")) { - Directory.Delete(Path + "/Lib/whl", true); + Directory.Delete(envPath + "/Lib/whl", true); } - ZipFile.ExtractToDirectory(Path + "/Lib/whl.zip", Path + "/Lib/whl"); - return Directory.GetFiles(Path + "/Lib/whl"); + ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/whl.zip", envPath + "/Lib/whl"); + return Directory.GetFiles(envPath + "/Lib/whl"); } private static void InstallPackages(BackgroundWorker worker, string[] packageList) @@ -40,11 +43,11 @@ private static void InstallPackages(BackgroundWorker worker, string[] packageLis for (int i = 0; i < num; i++) { double progress = (double)i / num * 100d; - string packageName = System.IO.Path.GetFileName(packageList[i]).Split('-')[0]; + string packageName = Path.GetFileName(packageList[i]).Split('-')[0]; worker.ReportProgress((int)progress, "Now installing " + packageName + "..."); var startInfo = new ProcessStartInfo { - FileName = Path + "/python/python.exe", + FileName = TunnyVariables.TunnyEnvPath + "/python/python.exe", Arguments = "-m pip install --no-deps " + packageList[i], WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, @@ -61,7 +64,7 @@ private static void InstallPackages(BackgroundWorker worker, string[] packageLis internal static string GetEmbeddedPythonPath() { - return Path + "/python"; + return TunnyVariables.TunnyEnvPath + "/python"; } } } diff --git a/Tunny/Settings/Storage.cs b/Tunny/Settings/Storage.cs index f54f79eb..99e6b2d7 100644 --- a/Tunny/Settings/Storage.cs +++ b/Tunny/Settings/Storage.cs @@ -6,7 +6,7 @@ namespace Tunny.Settings { public class Storage { - public string Path { get; set; } = "/fish.log"; + public string Path { get; set; } = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/fish.log"; public StorageType Type { get; set; } = StorageType.Journal; public string GetOptunaStoragePath() diff --git a/Tunny/Settings/TunnySettings.cs b/Tunny/Settings/TunnySettings.cs index 5cccfffb..8bd9f4af 100644 --- a/Tunny/Settings/TunnySettings.cs +++ b/Tunny/Settings/TunnySettings.cs @@ -9,7 +9,7 @@ public class TunnySettings public string Version { get; set; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); public Optimize Optimize { get; set; } = new Optimize(); public Result Result { get; set; } = new Result(); - public string StudyName { get; set; } = "study1"; + public string StudyName { get; set; } = string.Empty; public Storage Storage { get; set; } = new Storage(); public bool CheckPythonLibraries { get; set; } = true; diff --git a/Tunny/UI/OptimizationWindow.cs b/Tunny/UI/OptimizationWindow.cs index fbe56e52..6ae0c732 100644 --- a/Tunny/UI/OptimizationWindow.cs +++ b/Tunny/UI/OptimizationWindow.cs @@ -9,6 +9,7 @@ using Tunny.Handler; using Tunny.Settings; using Tunny.Solver; +using Tunny.Util; namespace Tunny.UI { @@ -43,7 +44,7 @@ public OptimizationWindow(FishingComponent component) private void RunPythonInstaller() { - PythonInstaller.Path = _component.GhInOut.ComponentFolder; + PythonInstaller.ComponentFolderPath = _component.GhInOut.ComponentFolder; if (_settings.CheckPythonLibraries) { var installer = new PythonInstallDialog() @@ -82,7 +83,7 @@ public void BGDispose() private void LoadSettingJson() { - string settingsPath = _component.GhInOut.ComponentFolder + @"\Settings.json"; + string settingsPath = TunnyVariables.OptimizeSettingsPath; if (File.Exists(settingsPath)) { _settings = TunnySettings.Deserialize(File.ReadAllText(settingsPath)); @@ -93,7 +94,7 @@ private void LoadSettingJson() { Storage = new Settings.Storage { - Path = _component.GhInOut.ComponentFolder + @"\fish.log", + Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "fish.log"), Type = StorageType.Journal } }; @@ -123,7 +124,7 @@ private void FormClosingXButton(object sender, FormClosingEventArgs e) var ghCanvas = Owner as GH_DocumentEditor; ghCanvas?.EnableUI(); GetUIValues(); - _settings.Serialize(_component.GhInOut.ComponentFolder + @"\Settings.json"); + _settings.Serialize(TunnyVariables.OptimizeSettingsPath); //TODO: use cancelAsync to stop the background worker safely optimizeBackgroundWorker?.Dispose(); diff --git a/Tunny/UI/OptimizeWindowTab/FileTab.cs b/Tunny/UI/OptimizeWindowTab/FileTab.cs index eec3ac86..712a38f9 100644 --- a/Tunny/UI/OptimizeWindowTab/FileTab.cs +++ b/Tunny/UI/OptimizeWindowTab/FileTab.cs @@ -5,6 +5,7 @@ using Tunny.Settings; using Tunny.Storage; +using Tunny.Util; namespace Tunny.UI { @@ -59,7 +60,7 @@ private void OutputDebugLogButton_Click(object sender, EventArgs e) using (var process = new Process()) { process.StartInfo.FileName = "PowerShell.exe"; - process.StartInfo.Arguments = $"tree {_component.GhInOut.ComponentFolder} /f > {_component.GhInOut.ComponentFolder}\\debug.log"; + process.StartInfo.Arguments = $"tree {_component.GhInOut.ComponentFolder} /f > {TunnyVariables.TunnyEnvPath}\\debug.log"; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); diff --git a/Tunny/Util/TunnyVariables.cs b/Tunny/Util/TunnyVariables.cs new file mode 100644 index 00000000..e262c3fd --- /dev/null +++ b/Tunny/Util/TunnyVariables.cs @@ -0,0 +1,11 @@ +using System; +using System.IO; + +namespace Tunny.Util +{ + public static class TunnyVariables + { + public static string TunnyEnvPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + ".tunny_env"); + public static string OptimizeSettingsPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".tunny_env", "settings.json"); + } +}