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 ;
3
+ using System . IO ;
7
4
using System . Linq ;
8
5
using System . Windows ;
9
6
using System . Windows . Forms ;
10
- using Flow . Launcher . Core . Resource ;
11
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 ;
12
12
13
13
namespace Flow . Launcher . Core . ExternalPlugins . Environments
14
14
{
@@ -42,8 +42,11 @@ internal AbstractPluginEnvironment(List<PluginMetadata> pluginMetadataList, Plug
42
42
43
43
internal IEnumerable < PluginPair > Setup ( )
44
44
{
45
+ // If no plugin is using the language, return empty list
45
46
if ( ! PluginMetadataList . Any ( o => o . Language . Equals ( Language , StringComparison . OrdinalIgnoreCase ) ) )
47
+ {
46
48
return new List < PluginPair > ( ) ;
49
+ }
47
50
48
51
if ( ! string . IsNullOrEmpty ( PluginsSettingsFilePath ) && FilesFolders . FileExists ( PluginsSettingsFilePath ) )
49
52
{
@@ -55,24 +58,55 @@ internal IEnumerable<PluginPair> Setup()
55
58
}
56
59
57
60
var noRuntimeMessage = string . Format (
58
- InternationalizationManager . Instance . GetTranslation ( "runtimePluginInstalledChooseRuntimePrompt" ) ,
61
+ API . GetTranslation ( "runtimePluginInstalledChooseRuntimePrompt" ) ,
59
62
Language ,
60
63
EnvName ,
61
64
Environment . NewLine
62
65
) ;
63
66
if ( API . ShowMsgBox ( noRuntimeMessage , string . Empty , MessageBoxButton . YesNo ) == MessageBoxResult . No )
64
67
{
65
- var msg = string . Format ( InternationalizationManager . Instance . GetTranslation ( "runtimePluginChooseRuntimeExecutable" ) , EnvName ) ;
66
- string selectedFile ;
68
+ var msg = string . Format ( API . GetTranslation ( "runtimePluginChooseRuntimeExecutable" ) , EnvName ) ;
67
69
68
- selectedFile = GetFileFromDialog ( msg , FileDialogFilter ) ;
70
+ var selectedFile = GetFileFromDialog ( msg , FileDialogFilter ) ;
69
71
70
72
if ( ! string . IsNullOrEmpty ( selectedFile ) )
73
+ {
71
74
PluginsSettingsFilePath = selectedFile ;
72
-
75
+ }
73
76
// Nothing selected because user pressed cancel from the file dialog window
74
- if ( string . IsNullOrEmpty ( selectedFile ) )
75
- 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
+ }
76
110
}
77
111
else
78
112
{
@@ -85,7 +119,7 @@ internal IEnumerable<PluginPair> Setup()
85
119
}
86
120
else
87
121
{
88
- API . ShowMsgBox ( string . Format ( InternationalizationManager . Instance . GetTranslation ( "runtimePluginUnableToSetExecutablePath" ) , Language ) ) ;
122
+ API . ShowMsgBox ( string . Format ( API . GetTranslation ( "runtimePluginUnableToSetExecutablePath" ) , Language ) ) ;
89
123
Log . Error ( "PluginsLoader" ,
90
124
$ "Not able to successfully set { EnvName } path, setting's plugin executable path variable is still an empty string.",
91
125
$ "{ Language } Environment") ;
@@ -98,13 +132,11 @@ internal IEnumerable<PluginPair> Setup()
98
132
99
133
private void EnsureLatestInstalled ( string expectedPath , string currentPath , string installedDirPath )
100
134
{
101
- if ( expectedPath == currentPath )
102
- return ;
135
+ if ( expectedPath == currentPath ) return ;
103
136
104
137
FilesFolders . RemoveFolderIfExists ( installedDirPath , ( s ) => API . ShowMsgBox ( s ) ) ;
105
138
106
139
InstallEnvironment ( ) ;
107
-
108
140
}
109
141
110
142
internal abstract PluginPair CreatePluginPair ( string filePath , PluginMetadata metadata ) ;
@@ -116,13 +148,16 @@ private IEnumerable<PluginPair> SetPathForPluginPairs(string filePath, string la
116
148
foreach ( var metadata in PluginMetadataList )
117
149
{
118
150
if ( metadata . Language . Equals ( languageToSet , StringComparison . OrdinalIgnoreCase ) )
151
+ {
152
+ metadata . AssemblyName = string . Empty ;
119
153
pluginPairs . Add ( CreatePluginPair ( filePath , metadata ) ) ;
154
+ }
120
155
}
121
156
122
157
return pluginPairs ;
123
158
}
124
159
125
- private string GetFileFromDialog ( string title , string filter = "" )
160
+ private static string GetFileFromDialog ( string title , string filter = "" )
126
161
{
127
162
var dlg = new OpenFileDialog
128
163
{
@@ -136,7 +171,6 @@ private string GetFileFromDialog(string title, string filter = "")
136
171
137
172
var result = dlg . ShowDialog ( ) ;
138
173
return result == DialogResult . OK ? dlg . FileName : string . Empty ;
139
-
140
174
}
141
175
142
176
/// <summary>
@@ -179,31 +213,33 @@ public static void PreStartPluginExecutablePathUpdate(Settings settings)
179
213
else
180
214
{
181
215
if ( IsUsingPortablePath ( settings . PluginSettings . PythonExecutablePath , DataLocation . PythonEnvironmentName ) )
216
+ {
182
217
settings . PluginSettings . PythonExecutablePath
183
218
= GetUpdatedEnvironmentPath ( settings . PluginSettings . PythonExecutablePath ) ;
219
+ }
184
220
185
221
if ( IsUsingPortablePath ( settings . PluginSettings . NodeExecutablePath , DataLocation . NodeEnvironmentName ) )
222
+ {
186
223
settings . PluginSettings . NodeExecutablePath
187
224
= GetUpdatedEnvironmentPath ( settings . PluginSettings . NodeExecutablePath ) ;
225
+ }
188
226
}
189
227
}
190
228
191
229
private static bool IsUsingPortablePath ( string filePath , string pluginEnvironmentName )
192
230
{
193
- if ( string . IsNullOrEmpty ( filePath ) )
194
- return false ;
231
+ if ( string . IsNullOrEmpty ( filePath ) ) return false ;
195
232
196
233
// DataLocation.PortableDataPath returns the current portable path, this determines if an out
197
234
// of date path is also a portable path.
198
- var portableAppEnvLocation = $ "UserData\\ { DataLocation . PluginEnvironments } \\ { pluginEnvironmentName } " ;
235
+ var portableAppEnvLocation = Path . Combine ( "UserData" , DataLocation . PluginEnvironments , pluginEnvironmentName ) ;
199
236
200
237
return filePath . Contains ( portableAppEnvLocation ) ;
201
238
}
202
239
203
240
private static bool IsUsingRoamingPath ( string filePath )
204
241
{
205
- if ( string . IsNullOrEmpty ( filePath ) )
206
- return false ;
242
+ if ( string . IsNullOrEmpty ( filePath ) ) return false ;
207
243
208
244
return filePath . StartsWith ( DataLocation . RoamingDataPath ) ;
209
245
}
@@ -213,8 +249,8 @@ private static string GetUpdatedEnvironmentPath(string filePath)
213
249
var index = filePath . IndexOf ( DataLocation . PluginEnvironments ) ;
214
250
215
251
// get the substring after "Environments" because we can not determine it dynamically
216
- var ExecutablePathSubstring = filePath . Substring ( index + DataLocation . PluginEnvironments . Count ( ) ) ;
217
- return $ "{ DataLocation . PluginEnvironmentsPath } { ExecutablePathSubstring } ";
252
+ var executablePathSubstring = filePath [ ( index + DataLocation . PluginEnvironments . Length ) .. ] ;
253
+ return $ "{ DataLocation . PluginEnvironmentsPath } { executablePathSubstring } ";
218
254
}
219
255
}
220
256
}
0 commit comments