From aa49ea2759c8e563dc68bee84164d5eba34faba5 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 15:33:55 +0900 Subject: [PATCH 1/8] Fix debug rhino8 path --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 65c7c81b48979c78aa2071261c97b8d8b43f27ca Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 15:35:19 +0900 Subject: [PATCH 2/8] Add to use .tunny_env folder --- Tunny/Handler/PythonInstaller.cs | 23 ++++++++++++----------- Tunny/UI/OptimizationWindow.cs | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Tunny/Handler/PythonInstaller.cs b/Tunny/Handler/PythonInstaller.cs index 69a4836d..f31168cc 100644 --- a/Tunny/Handler/PythonInstaller.cs +++ b/Tunny/Handler/PythonInstaller.cs @@ -7,7 +7,8 @@ namespace Tunny.Handler { public static class PythonInstaller { - public static string Path { get; set; } = "."; + public static string TunnyEnvPath { get; private set; } = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "/.tunny_env"; + public static string ComponentFolderPath { get; set; } public static void Run(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; @@ -20,18 +21,18 @@ public static void Run(object sender, DoWorkEventArgs e) private static string[] UnzipLibraries() { - if (Directory.Exists(Path + "/python")) + if (Directory.Exists(TunnyEnvPath + "/python")) { - Directory.Delete(Path + "/python", true); + Directory.Delete(TunnyEnvPath + "/python", true); } - ZipFile.ExtractToDirectory(Path + "/Lib/python.zip", Path + "/python"); + ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/python.zip", TunnyEnvPath + "/python"); - if (Directory.Exists(Path + "/Lib/whl")) + if (Directory.Exists(TunnyEnvPath + "/Lib/whl")) { - Directory.Delete(Path + "/Lib/whl", true); + Directory.Delete(TunnyEnvPath + "/Lib/whl", true); } - ZipFile.ExtractToDirectory(Path + "/Lib/whl.zip", Path + "/Lib/whl"); - return Directory.GetFiles(Path + "/Lib/whl"); + ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/whl.zip", TunnyEnvPath + "/Lib/whl"); + return Directory.GetFiles(TunnyEnvPath + "/Lib/whl"); } private static void InstallPackages(BackgroundWorker worker, string[] packageList) @@ -40,11 +41,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 = TunnyEnvPath + "/python/python.exe", Arguments = "-m pip install --no-deps " + packageList[i], WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, @@ -61,7 +62,7 @@ private static void InstallPackages(BackgroundWorker worker, string[] packageLis internal static string GetEmbeddedPythonPath() { - return Path + "/python"; + return TunnyEnvPath + "/python"; } } } diff --git a/Tunny/UI/OptimizationWindow.cs b/Tunny/UI/OptimizationWindow.cs index fbe56e52..388870f6 100644 --- a/Tunny/UI/OptimizationWindow.cs +++ b/Tunny/UI/OptimizationWindow.cs @@ -43,7 +43,8 @@ public OptimizationWindow(FishingComponent component) private void RunPythonInstaller() { - PythonInstaller.Path = _component.GhInOut.ComponentFolder; + + PythonInstaller.ComponentFolderPath = _component.GhInOut.ComponentFolder; if (_settings.CheckPythonLibraries) { var installer = new PythonInstallDialog() From 5f7504dd8b01b7602c3b743fd995237acb0fca8f Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 16:46:16 +0900 Subject: [PATCH 3/8] Update default studyname to empty --- Tunny/Settings/TunnySettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 6d8cd34a7413944bef3dd5c158a8e1be5a615f87 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 16:46:37 +0900 Subject: [PATCH 4/8] Add TunnyVariables.cs --- Tunny/Util/TunnyVariables.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Tunny/Util/TunnyVariables.cs diff --git a/Tunny/Util/TunnyVariables.cs b/Tunny/Util/TunnyVariables.cs new file mode 100644 index 00000000..87e0ebb3 --- /dev/null +++ b/Tunny/Util/TunnyVariables.cs @@ -0,0 +1,12 @@ +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"); + } +} From f262d40d6f8ced4e18f00240f1d67be2e3f47676 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 16:47:28 +0900 Subject: [PATCH 5/8] Update setting.json path to .tunny_env --- Tunny/Settings/Storage.cs | 2 +- Tunny/UI/OptimizationWindow.cs | 5 +++-- Tunny/UI/OptimizeWindowTab/FileTab.cs | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) 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/UI/OptimizationWindow.cs b/Tunny/UI/OptimizationWindow.cs index 388870f6..2f8b0213 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 { @@ -83,7 +84,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)); @@ -94,7 +95,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 } }; 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(); From 63dc7d7e69dfac6ad33dc7f60ef312f9d5d7e172 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 16:55:26 +0900 Subject: [PATCH 6/8] Update settings.json save path --- Tunny/UI/OptimizationWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tunny/UI/OptimizationWindow.cs b/Tunny/UI/OptimizationWindow.cs index 2f8b0213..f91b0f45 100644 --- a/Tunny/UI/OptimizationWindow.cs +++ b/Tunny/UI/OptimizationWindow.cs @@ -125,7 +125,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(); From b031a05c13321f3c83d45e1f006a5a9cdc56d6ed Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 16:56:31 +0900 Subject: [PATCH 7/8] Update PythonInstaller to use TunnyVariables --- Tunny/Handler/PythonInstaller.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Tunny/Handler/PythonInstaller.cs b/Tunny/Handler/PythonInstaller.cs index f31168cc..733e36f8 100644 --- a/Tunny/Handler/PythonInstaller.cs +++ b/Tunny/Handler/PythonInstaller.cs @@ -3,11 +3,12 @@ using System.IO; using System.IO.Compression; +using Tunny.Util; + namespace Tunny.Handler { public static class PythonInstaller { - public static string TunnyEnvPath { get; private set; } = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "/.tunny_env"; public static string ComponentFolderPath { get; set; } public static void Run(object sender, DoWorkEventArgs e) { @@ -21,18 +22,19 @@ public static void Run(object sender, DoWorkEventArgs e) private static string[] UnzipLibraries() { - if (Directory.Exists(TunnyEnvPath + "/python")) + string envPath = TunnyVariables.TunnyEnvPath; + if (Directory.Exists(envPath + "/python")) { - Directory.Delete(TunnyEnvPath + "/python", true); + Directory.Delete(envPath + "/python", true); } - ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/python.zip", TunnyEnvPath + "/python"); + ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/python.zip", envPath + "/python"); - if (Directory.Exists(TunnyEnvPath + "/Lib/whl")) + if (Directory.Exists(envPath + "/Lib/whl")) { - Directory.Delete(TunnyEnvPath + "/Lib/whl", true); + Directory.Delete(envPath + "/Lib/whl", true); } - ZipFile.ExtractToDirectory(ComponentFolderPath + "/Lib/whl.zip", TunnyEnvPath + "/Lib/whl"); - return Directory.GetFiles(TunnyEnvPath + "/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) @@ -45,7 +47,7 @@ private static void InstallPackages(BackgroundWorker worker, string[] packageLis worker.ReportProgress((int)progress, "Now installing " + packageName + "..."); var startInfo = new ProcessStartInfo { - FileName = TunnyEnvPath + "/python/python.exe", + FileName = TunnyVariables.TunnyEnvPath + "/python/python.exe", Arguments = "-m pip install --no-deps " + packageList[i], WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, @@ -62,7 +64,7 @@ private static void InstallPackages(BackgroundWorker worker, string[] packageLis internal static string GetEmbeddedPythonPath() { - return TunnyEnvPath + "/python"; + return TunnyVariables.TunnyEnvPath + "/python"; } } } From 76015b7cab6f59237ddbebe266a11dce35016271 Mon Sep 17 00:00:00 2001 From: hrntsm Date: Thu, 28 Dec 2023 17:05:22 +0900 Subject: [PATCH 8/8] Fix CodeFactor issues --- Tunny/UI/OptimizationWindow.cs | 1 - Tunny/Util/TunnyVariables.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Tunny/UI/OptimizationWindow.cs b/Tunny/UI/OptimizationWindow.cs index f91b0f45..6ae0c732 100644 --- a/Tunny/UI/OptimizationWindow.cs +++ b/Tunny/UI/OptimizationWindow.cs @@ -44,7 +44,6 @@ public OptimizationWindow(FishingComponent component) private void RunPythonInstaller() { - PythonInstaller.ComponentFolderPath = _component.GhInOut.ComponentFolder; if (_settings.CheckPythonLibraries) { diff --git a/Tunny/Util/TunnyVariables.cs b/Tunny/Util/TunnyVariables.cs index 87e0ebb3..e262c3fd 100644 --- a/Tunny/Util/TunnyVariables.cs +++ b/Tunny/Util/TunnyVariables.cs @@ -5,7 +5,6 @@ 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"); }