1
- using Flow . Launcher . Infrastructure . Logger ;
2
- using Flow . Launcher . Infrastructure . UserSettings ;
3
- using Flow . Launcher . Plugin ;
4
- using Flow . Launcher . Plugin . SharedCommands ;
5
- using System ;
1
+ using System ;
6
2
using System . Collections . Generic ;
7
3
using System . IO ;
8
4
using System . Linq ;
9
5
using System . Windows ;
10
6
using System . Windows . Forms ;
11
- using Flow . Launcher . Core . Resource ;
12
7
using CommunityToolkit . Mvvm . DependencyInjection ;
8
+ using Flow . Launcher . Infrastructure . Logger ;
9
+ using Flow . Launcher . Infrastructure . UserSettings ;
10
+ using Flow . Launcher . Plugin ;
11
+ using Flow . Launcher . Plugin . SharedCommands ;
13
12
14
13
namespace Flow . Launcher . Core . ExternalPlugins . Environments
15
14
{
@@ -43,8 +42,11 @@ internal AbstractPluginEnvironment(List<PluginMetadata> pluginMetadataList, Plug
43
42
44
43
internal IEnumerable < PluginPair > Setup ( )
45
44
{
45
+ // If no plugin is using the language, return empty list
46
46
if ( ! PluginMetadataList . Any ( o => o . Language . Equals ( Language , StringComparison . OrdinalIgnoreCase ) ) )
47
+ {
47
48
return new List < PluginPair > ( ) ;
49
+ }
48
50
49
51
if ( ! string . IsNullOrEmpty ( PluginsSettingsFilePath ) && FilesFolders . FileExists ( PluginsSettingsFilePath ) )
50
52
{
@@ -56,24 +58,21 @@ internal IEnumerable<PluginPair> Setup()
56
58
}
57
59
58
60
var noRuntimeMessage = string . Format (
59
- InternationalizationManager . Instance . GetTranslation ( "runtimePluginInstalledChooseRuntimePrompt" ) ,
61
+ API . GetTranslation ( "runtimePluginInstalledChooseRuntimePrompt" ) ,
60
62
Language ,
61
63
EnvName ,
62
64
Environment . NewLine
63
65
) ;
64
66
if ( API . ShowMsgBox ( noRuntimeMessage , string . Empty , MessageBoxButton . YesNo ) == MessageBoxResult . No )
65
67
{
66
- var msg = string . Format ( InternationalizationManager . Instance . GetTranslation ( "runtimePluginChooseRuntimeExecutable" ) , EnvName ) ;
67
- string selectedFile ;
68
+ var msg = string . Format ( API . GetTranslation ( "runtimePluginChooseRuntimeExecutable" ) , EnvName ) ;
68
69
69
- selectedFile = GetFileFromDialog ( msg , FileDialogFilter ) ;
70
+ var selectedFile = GetFileFromDialog ( msg , FileDialogFilter ) ;
70
71
71
- if ( ! string . IsNullOrEmpty ( selectedFile ) )
72
- PluginsSettingsFilePath = selectedFile ;
72
+ if ( ! string . IsNullOrEmpty ( selectedFile ) ) PluginsSettingsFilePath = selectedFile ;
73
73
74
74
// Nothing selected because user pressed cancel from the file dialog window
75
- if ( string . IsNullOrEmpty ( selectedFile ) )
76
- InstallEnvironment ( ) ;
75
+ if ( string . IsNullOrEmpty ( selectedFile ) ) InstallEnvironment ( ) ;
77
76
}
78
77
else
79
78
{
@@ -86,7 +85,7 @@ internal IEnumerable<PluginPair> Setup()
86
85
}
87
86
else
88
87
{
89
- API . ShowMsgBox ( string . Format ( InternationalizationManager . Instance . GetTranslation ( "runtimePluginUnableToSetExecutablePath" ) , Language ) ) ;
88
+ API . ShowMsgBox ( string . Format ( API . GetTranslation ( "runtimePluginUnableToSetExecutablePath" ) , Language ) ) ;
90
89
Log . Error ( "PluginsLoader" ,
91
90
$ "Not able to successfully set { EnvName } path, setting's plugin executable path variable is still an empty string.",
92
91
$ "{ Language } Environment") ;
@@ -99,13 +98,11 @@ internal IEnumerable<PluginPair> Setup()
99
98
100
99
private void EnsureLatestInstalled ( string expectedPath , string currentPath , string installedDirPath )
101
100
{
102
- if ( expectedPath == currentPath )
103
- return ;
101
+ if ( expectedPath == currentPath ) return ;
104
102
105
103
FilesFolders . RemoveFolderIfExists ( installedDirPath , ( s ) => API . ShowMsgBox ( s ) ) ;
106
104
107
105
InstallEnvironment ( ) ;
108
-
109
106
}
110
107
111
108
internal abstract PluginPair CreatePluginPair ( string filePath , PluginMetadata metadata ) ;
@@ -126,7 +123,7 @@ private IEnumerable<PluginPair> SetPathForPluginPairs(string filePath, string la
126
123
return pluginPairs ;
127
124
}
128
125
129
- private string GetFileFromDialog ( string title , string filter = "" )
126
+ private static string GetFileFromDialog ( string title , string filter = "" )
130
127
{
131
128
var dlg = new OpenFileDialog
132
129
{
@@ -140,7 +137,6 @@ private string GetFileFromDialog(string title, string filter = "")
140
137
141
138
var result = dlg . ShowDialog ( ) ;
142
139
return result == DialogResult . OK ? dlg . FileName : string . Empty ;
143
-
144
140
}
145
141
146
142
/// <summary>
@@ -183,31 +179,33 @@ public static void PreStartPluginExecutablePathUpdate(Settings settings)
183
179
else
184
180
{
185
181
if ( IsUsingPortablePath ( settings . PluginSettings . PythonExecutablePath , DataLocation . PythonEnvironmentName ) )
182
+ {
186
183
settings . PluginSettings . PythonExecutablePath
187
184
= GetUpdatedEnvironmentPath ( settings . PluginSettings . PythonExecutablePath ) ;
185
+ }
188
186
189
187
if ( IsUsingPortablePath ( settings . PluginSettings . NodeExecutablePath , DataLocation . NodeEnvironmentName ) )
188
+ {
190
189
settings . PluginSettings . NodeExecutablePath
191
190
= GetUpdatedEnvironmentPath ( settings . PluginSettings . NodeExecutablePath ) ;
191
+ }
192
192
}
193
193
}
194
194
195
195
private static bool IsUsingPortablePath ( string filePath , string pluginEnvironmentName )
196
196
{
197
- if ( string . IsNullOrEmpty ( filePath ) )
198
- return false ;
197
+ if ( string . IsNullOrEmpty ( filePath ) ) return false ;
199
198
200
199
// DataLocation.PortableDataPath returns the current portable path, this determines if an out
201
200
// of date path is also a portable path.
202
- var portableAppEnvLocation = $ "UserData\\ { DataLocation . PluginEnvironments } \\ { pluginEnvironmentName } " ;
201
+ var portableAppEnvLocation = Path . Combine ( "UserData" , DataLocation . PluginEnvironments , pluginEnvironmentName ) ;
203
202
204
203
return filePath . Contains ( portableAppEnvLocation ) ;
205
204
}
206
205
207
206
private static bool IsUsingRoamingPath ( string filePath )
208
207
{
209
- if ( string . IsNullOrEmpty ( filePath ) )
210
- return false ;
208
+ if ( string . IsNullOrEmpty ( filePath ) ) return false ;
211
209
212
210
return filePath . StartsWith ( DataLocation . RoamingDataPath ) ;
213
211
}
@@ -217,7 +215,7 @@ private static string GetUpdatedEnvironmentPath(string filePath)
217
215
var index = filePath . IndexOf ( DataLocation . PluginEnvironments ) ;
218
216
219
217
// get the substring after "Environments" because we can not determine it dynamically
220
- var ExecutablePathSubstring = filePath . Substring ( index + DataLocation . PluginEnvironments . Count ( ) ) ;
218
+ var ExecutablePathSubstring = filePath [ ( index + DataLocation . PluginEnvironments . Length ) .. ] ;
221
219
return $ "{ DataLocation . PluginEnvironmentsPath } { ExecutablePathSubstring } ";
222
220
}
223
221
}
0 commit comments