From 76c0f03bc2a9e658893b45ef31fb8d88c603e716 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 25 Oct 2022 21:03:01 +1100 Subject: [PATCH] update python directory to python file directory --- .../ExternalPlugins/PluginEnvironment.cs | 80 +++++++++---------- Flow.Launcher.Core/Plugin/PluginsLoader.cs | 4 - .../UserSettings/PluginSettings.cs | 2 +- Flow.Launcher/Languages/en.xaml | 2 +- Flow.Launcher/SettingWindow.xaml | 6 +- Flow.Launcher/SettingWindow.xaml.cs | 4 +- 6 files changed, 46 insertions(+), 52 deletions(-) diff --git a/Flow.Launcher.Core/ExternalPlugins/PluginEnvironment.cs b/Flow.Launcher.Core/ExternalPlugins/PluginEnvironment.cs index a9a4b7f19..1b6838d31 100644 --- a/Flow.Launcher.Core/ExternalPlugins/PluginEnvironment.cs +++ b/Flow.Launcher.Core/ExternalPlugins/PluginEnvironment.cs @@ -9,8 +9,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; namespace Flow.Launcher.Core.ExternalPlugins @@ -61,8 +59,8 @@ namespace Flow.Launcher.Core.ExternalPlugins switch (languageType) { case AllowedLanguage.Python: - if (!string.IsNullOrEmpty(pluginSettings.PythonDirectory) && FilesFolders.LocationExists(pluginSettings.PythonDirectory)) - return SetPathForPluginPairs($"{pluginSettings.PythonDirectory}\\{PythonExecutable}", languageType); + if (!string.IsNullOrEmpty(pluginSettings.PythonFilePath) && FilesFolders.FileExists(pluginSettings.PythonFilePath)) + return SetPathForPluginPairs($"{pluginSettings.PythonFilePath}\\{PythonExecutable}", languageType); break; case AllowedLanguage.TypeScript: @@ -82,37 +80,39 @@ namespace Flow.Launcher.Core.ExternalPlugins $"and you will be prompted to select the folder that contains the {environment} executable", string.Empty, MessageBoxButtons.YesNo) == DialogResult.No) { - var dlg = new OpenFileDialog - { - InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), - Multiselect = false, - CheckFileExists = true, - CheckPathExists = true, - Title = $"Please select the {environment} executable" - }; + var msg = $"Please select the {environment} executable"; + var selectedFile = string.Empty; - var result = dlg.ShowDialog(); - if (result == DialogResult.OK) + switch (languageType) { - switch (languageType) - { - case AllowedLanguage.Python: - Constant.PythonPath = dlg.FileName; - pluginSettings.PythonDirectory = Constant.PythonPath; - break; - case AllowedLanguage.TypeScript: - case AllowedLanguage.JavaScript: - Constant.NodePath = dlg.FileName; + case AllowedLanguage.Python: + selectedFile = GetFileFromDialog(msg, "Python|pythonw.exe"); + + if (!string.IsNullOrEmpty(selectedFile)) + { + Constant.PythonPath = selectedFile; + pluginSettings.PythonFilePath = Constant.PythonPath; + } + break; + + case AllowedLanguage.TypeScript: + case AllowedLanguage.JavaScript: + selectedFile = GetFileFromDialog(msg); + + if (!string.IsNullOrEmpty(selectedFile)) + { + Constant.NodePath = selectedFile; pluginSettings.NodeFilePath = Constant.NodePath; - break; - default: - break; - } + } + break; + + default: + break; } - else - { + + // Nothing selected because user pressed cancel from the file dialog window + if (string.IsNullOrEmpty(selectedFile)) InstallEnvironment(languageType); - } } else { @@ -121,19 +121,19 @@ namespace Flow.Launcher.Core.ExternalPlugins switch (languageType) { - case AllowedLanguage.Python when FilesFolders.FileExists(Constant.PythonPath) && !string.IsNullOrEmpty(pluginSettings.PythonDirectory): - return SetPathForPluginPairs(Constant.PythonPath, languageType); + case AllowedLanguage.Python when FilesFolders.FileExists(pluginSettings.PythonFilePath) && !string.IsNullOrEmpty(Constant.PythonPath): + return SetPathForPluginPairs(pluginSettings.PythonFilePath, languageType); - case AllowedLanguage.TypeScript when FilesFolders.FileExists(Constant.NodePath) && !string.IsNullOrEmpty(pluginSettings.NodeFilePath): - case AllowedLanguage.JavaScript when FilesFolders.FileExists(Constant.NodePath) && !string.IsNullOrEmpty(pluginSettings.NodeFilePath): + case AllowedLanguage.TypeScript when FilesFolders.FileExists(pluginSettings.NodeFilePath) && !string.IsNullOrEmpty(Constant.NodePath): + case AllowedLanguage.JavaScript when FilesFolders.FileExists(pluginSettings.NodeFilePath) && !string.IsNullOrEmpty(Constant.NodePath): return SetPathForPluginPairs(pluginSettings.NodeFilePath, languageType); default: MessageBox.Show( "Unable to set Python executable path, please try from Flow's settings (scroll down to the bottom)."); Log.Error("PluginsLoader", - $"Not able to successfully set Python path, the PythonDirectory variable is still an empty string.", - "PythonPlugins"); + $"Not able to successfully set Python path, setting's PythonFilePath variable is still an empty string.", + "PluginEnvironment"); return new List(); } @@ -142,17 +142,16 @@ namespace Flow.Launcher.Core.ExternalPlugins private void InstallEnvironment(string languageType) { switch (languageType) - { + {//TODO: UPDATE TO USE CENTRALISED PLUGINENVIRONMENT FOLDER case AllowedLanguage.Python: var pythonDirPath = Path.Combine(DataLocation.DataDirectory(), "PythonEmbeddable"); FilesFolders.RemoveFolderIfExists(pythonDirPath); // Python 3.8.9 is used for Windows 7 compatibility DroplexPackage.Drop(App.python_3_8_9_embeddable, pythonDirPath).Wait(); - - pluginSettings.PythonDirectory = pythonDirPath; + Constant.PythonPath = Path.Combine(pythonDirPath, PythonExecutable); - + pluginSettings.PythonFilePath = Constant.PythonPath; break; case AllowedLanguage.TypeScript: @@ -164,7 +163,6 @@ namespace Flow.Launcher.Core.ExternalPlugins Constant.NodePath = Path.Combine(nodeDirPath, $"node-v16.18.0-win-x64\\{NodeExecutable}"); pluginSettings.NodeFilePath = Constant.NodePath; - break; default: diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs index 377715bdc..40bef79f9 100644 --- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs +++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs @@ -1,17 +1,13 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; using System.Windows.Forms; -using Droplex; using Flow.Launcher.Core.ExternalPlugins; -using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; -using Flow.Launcher.Plugin.SharedCommands; using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch; namespace Flow.Launcher.Core.Plugin diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index 68409f3f9..e1fad2723 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -5,7 +5,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings { public class PluginsSettings : BaseModel { - public string PythonDirectory { get; set; } // IS FILE PATH BUT CHANGE NAME TO FILE PATH?? + public string PythonFilePath { get; set; } public string NodeFilePath { get; set; } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index c28c43d81..92f2dbded 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -56,7 +56,7 @@ Select the file manager to use when opening the folder. Default Web Browser Setting for New Tab, New Window, Private Mode. - Python Directory + Python Path Node.js Path Please select the Node.js executable Please select pythonw.exe diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 61527f7c2..7646bab32 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -905,17 +905,17 @@ - + + Text="{Binding Settings.PluginSettings.PythonFilePath, TargetNullValue='No Setting'}" />