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,55 @@ 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
72
if ( ! string . IsNullOrEmpty ( selectedFile ) )
73
+ {
72
74
PluginsSettingsFilePath = selectedFile ;
73
-
75
+ }
74
76
// Nothing selected because user pressed cancel from the file dialog window
75
- if ( string . IsNullOrEmpty ( selectedFile ) )
76
- InstallEnvironment ( ) ;
77
+ else
78
+ {
79
+ var forceDownloadMessage = string . Format (
80
+ API . GetTranslation ( "runtimeExecutableInvalidChooseDownload" ) ,
81
+ Language ,
82
+ EnvName ,
83
+ Environment . NewLine
84
+ ) ;
85
+
86
+ // Let users select valid path or choose to download
87
+ while ( string . IsNullOrEmpty ( selectedFile ) )
88
+ {
89
+ if ( API . ShowMsgBox ( forceDownloadMessage , string . Empty , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
90
+ {
91
+ // Continue select file
92
+ selectedFile = GetFileFromDialog ( msg , FileDialogFilter ) ;
93
+ }
94
+ else
95
+ {
96
+ // User selected no, break the loop
97
+ break ;
98
+ }
99
+ }
100
+
101
+ if ( ! string . IsNullOrEmpty ( selectedFile ) )
102
+ {
103
+ PluginsSettingsFilePath = selectedFile ;
104
+ }
105
+ else
106
+ {
107
+ InstallEnvironment ( ) ;
108
+ }
109
+ }
77
110
}
78
111
else
79
112
{
@@ -86,7 +119,7 @@ internal IEnumerable<PluginPair> Setup()
86
119
}
87
120
else
88
121
{
89
- API . ShowMsgBox ( string . Format ( InternationalizationManager . Instance . GetTranslation ( "runtimePluginUnableToSetExecutablePath" ) , Language ) ) ;
122
+ API . ShowMsgBox ( string . Format ( API . GetTranslation ( "runtimePluginUnableToSetExecutablePath" ) , Language ) ) ;
90
123
Log . Error ( "PluginsLoader" ,
91
124
$ "Not able to successfully set { EnvName } path, setting's plugin executable path variable is still an empty string.",
92
125
$ "{ Language } Environment") ;
@@ -99,13 +132,11 @@ internal IEnumerable<PluginPair> Setup()
99
132
100
133
private void EnsureLatestInstalled ( string expectedPath , string currentPath , string installedDirPath )
101
134
{
102
- if ( expectedPath == currentPath )
103
- return ;
135
+ if ( expectedPath == currentPath ) return ;
104
136
105
137
FilesFolders . RemoveFolderIfExists ( installedDirPath , ( s ) => API . ShowMsgBox ( s ) ) ;
106
138
107
139
InstallEnvironment ( ) ;
108
-
109
140
}
110
141
111
142
internal abstract PluginPair CreatePluginPair ( string filePath , PluginMetadata metadata ) ;
@@ -126,7 +157,7 @@ private IEnumerable<PluginPair> SetPathForPluginPairs(string filePath, string la
126
157
return pluginPairs ;
127
158
}
128
159
129
- private string GetFileFromDialog ( string title , string filter = "" )
160
+ private static string GetFileFromDialog ( string title , string filter = "" )
130
161
{
131
162
var dlg = new OpenFileDialog
132
163
{
@@ -140,7 +171,6 @@ private string GetFileFromDialog(string title, string filter = "")
140
171
141
172
var result = dlg . ShowDialog ( ) ;
142
173
return result == DialogResult . OK ? dlg . FileName : string . Empty ;
143
-
144
174
}
145
175
146
176
/// <summary>
@@ -183,31 +213,33 @@ public static void PreStartPluginExecutablePathUpdate(Settings settings)
183
213
else
184
214
{
185
215
if ( IsUsingPortablePath ( settings . PluginSettings . PythonExecutablePath , DataLocation . PythonEnvironmentName ) )
216
+ {
186
217
settings . PluginSettings . PythonExecutablePath
187
218
= GetUpdatedEnvironmentPath ( settings . PluginSettings . PythonExecutablePath ) ;
219
+ }
188
220
189
221
if ( IsUsingPortablePath ( settings . PluginSettings . NodeExecutablePath , DataLocation . NodeEnvironmentName ) )
222
+ {
190
223
settings . PluginSettings . NodeExecutablePath
191
224
= GetUpdatedEnvironmentPath ( settings . PluginSettings . NodeExecutablePath ) ;
225
+ }
192
226
}
193
227
}
194
228
195
229
private static bool IsUsingPortablePath ( string filePath , string pluginEnvironmentName )
196
230
{
197
- if ( string . IsNullOrEmpty ( filePath ) )
198
- return false ;
231
+ if ( string . IsNullOrEmpty ( filePath ) ) return false ;
199
232
200
233
// DataLocation.PortableDataPath returns the current portable path, this determines if an out
201
234
// of date path is also a portable path.
202
- var portableAppEnvLocation = $ "UserData\\ { DataLocation . PluginEnvironments } \\ { pluginEnvironmentName } " ;
235
+ var portableAppEnvLocation = Path . Combine ( "UserData" , DataLocation . PluginEnvironments , pluginEnvironmentName ) ;
203
236
204
237
return filePath . Contains ( portableAppEnvLocation ) ;
205
238
}
206
239
207
240
private static bool IsUsingRoamingPath ( string filePath )
208
241
{
209
- if ( string . IsNullOrEmpty ( filePath ) )
210
- return false ;
242
+ if ( string . IsNullOrEmpty ( filePath ) ) return false ;
211
243
212
244
return filePath . StartsWith ( DataLocation . RoamingDataPath ) ;
213
245
}
@@ -217,8 +249,8 @@ private static string GetUpdatedEnvironmentPath(string filePath)
217
249
var index = filePath . IndexOf ( DataLocation . PluginEnvironments ) ;
218
250
219
251
// get the substring after "Environments" because we can not determine it dynamically
220
- var ExecutablePathSubstring = filePath . Substring ( index + DataLocation . PluginEnvironments . Count ( ) ) ;
221
- return $ "{ DataLocation . PluginEnvironmentsPath } { ExecutablePathSubstring } ";
252
+ var executablePathSubstring = filePath [ ( index + DataLocation . PluginEnvironments . Length ) .. ] ;
253
+ return $ "{ DataLocation . PluginEnvironmentsPath } { executablePathSubstring } ";
222
254
}
223
255
}
224
256
}
0 commit comments