3
3
using Flow . Launcher . Infrastructure ;
4
4
using Flow . Launcher . Infrastructure . Http ;
5
5
using Flow . Launcher . Infrastructure . Logger ;
6
- using Flow . Launcher . Infrastructure . UserSettings ;
7
6
using Flow . Launcher . Plugin . SharedCommands ;
8
7
using System ;
9
8
using System . Collections . Generic ;
10
- using System . Diagnostics ;
11
9
using System . IO ;
12
10
using System . Linq ;
13
11
using System . Net . Http ;
@@ -99,13 +97,12 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
99
97
if ( Context . API . GetAllPlugins ( )
100
98
. Any ( x => x . Metadata . ID == plugin . ID && x . Metadata . Version . CompareTo ( plugin . Version ) < 0 ) )
101
99
{
102
- if ( MessageBox . Show ( Context . API . GetTranslation ( "plugin_pluginsmanager_update_exists" ) ,
103
- Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
104
- MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
105
- Context
106
- . API
107
- . ChangeQuery (
108
- $ "{ Context . CurrentPluginMetadata . ActionKeywords . FirstOrDefault ( ) } { Settings . UpdateCommand } { plugin . Name } ") ;
100
+ var updateDetail = ! plugin . IsFromLocalInstallPath ? plugin . Name : plugin . LocalInstallPath ;
101
+
102
+ Context
103
+ . API
104
+ . ChangeQuery (
105
+ $ "{ Context . CurrentPluginMetadata . ActionKeywords . FirstOrDefault ( ) } { Settings . UpdateCommand } { updateDetail } ") ;
109
106
110
107
var mainWindow = Application . Current . MainWindow ;
111
108
mainWindow . Show ( ) ;
@@ -147,12 +144,17 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
147
144
148
145
try
149
146
{
150
- if ( File . Exists ( filePath ) )
147
+ if ( ! plugin . IsFromLocalInstallPath )
151
148
{
152
- File . Delete ( filePath ) ;
153
- }
149
+ if ( File . Exists ( filePath ) )
150
+ File . Delete ( filePath ) ;
154
151
155
- await Http . DownloadAsync ( plugin . UrlDownload , filePath ) . ConfigureAwait ( false ) ;
152
+ await Http . DownloadAsync ( plugin . UrlDownload , filePath ) . ConfigureAwait ( false ) ;
153
+ }
154
+ else
155
+ {
156
+ filePath = plugin . LocalInstallPath ;
157
+ }
156
158
157
159
Install ( plugin , filePath ) ;
158
160
}
@@ -193,24 +195,38 @@ internal async ValueTask<List<Result>> RequestUpdateAsync(string search, Cancell
193
195
{
194
196
await PluginsManifest . UpdateManifestAsync ( token , usePrimaryUrlOnly ) ;
195
197
198
+ var pluginFromLocalPath = null as UserPlugin ;
199
+ var updateFromLocalPath = false ;
200
+
201
+ if ( FilesFolders . IsZipFilePath ( search , checkFileExists : true ) )
202
+ {
203
+ pluginFromLocalPath = Utilities . GetPluginInfoFromZip ( search ) ;
204
+ pluginFromLocalPath . LocalInstallPath = search ;
205
+ updateFromLocalPath = true ;
206
+ }
207
+
208
+ var updateSource = ! updateFromLocalPath
209
+ ? PluginsManifest . UserPlugins
210
+ : new List < UserPlugin > { pluginFromLocalPath } ;
211
+
196
212
var resultsForUpdate = (
197
213
from existingPlugin in Context . API . GetAllPlugins ( )
198
- join pluginFromManifest in PluginsManifest . UserPlugins
199
- on existingPlugin . Metadata . ID equals pluginFromManifest . ID
200
- where String . Compare ( existingPlugin . Metadata . Version , pluginFromManifest . Version ,
214
+ join pluginUpdateSource in updateSource
215
+ on existingPlugin . Metadata . ID equals pluginUpdateSource . ID
216
+ where string . Compare ( existingPlugin . Metadata . Version , pluginUpdateSource . Version ,
201
217
StringComparison . InvariantCulture ) <
202
- 0 // if current version precedes manifest version
218
+ 0 // if current version precedes version of the plugin from update source (e.g. PluginsManifest)
203
219
&& ! PluginManager . PluginModified ( existingPlugin . Metadata . ID )
204
220
select
205
221
new
206
222
{
207
- pluginFromManifest . Name ,
208
- pluginFromManifest . Author ,
223
+ pluginUpdateSource . Name ,
224
+ pluginUpdateSource . Author ,
209
225
CurrentVersion = existingPlugin . Metadata . Version ,
210
- NewVersion = pluginFromManifest . Version ,
226
+ NewVersion = pluginUpdateSource . Version ,
211
227
existingPlugin . Metadata . IcoPath ,
212
228
PluginExistingMetadata = existingPlugin . Metadata ,
213
- PluginNewUserPlugin = pluginFromManifest
229
+ PluginNewUserPlugin = pluginUpdateSource
214
230
} ) . ToList ( ) ;
215
231
216
232
if ( ! resultsForUpdate . Any ( ) )
@@ -261,13 +277,21 @@ where String.Compare(existingPlugin.Metadata.Version, pluginFromManifest.Version
261
277
262
278
_ = Task . Run ( async delegate
263
279
{
264
- if ( File . Exists ( downloadToFilePath ) )
280
+ if ( ! x . PluginNewUserPlugin . IsFromLocalInstallPath )
265
281
{
266
- File . Delete ( downloadToFilePath ) ;
267
- }
282
+ if ( File . Exists ( downloadToFilePath ) )
283
+ {
284
+ File . Delete ( downloadToFilePath ) ;
285
+ }
268
286
269
- await Http . DownloadAsync ( x . PluginNewUserPlugin . UrlDownload , downloadToFilePath )
270
- . ConfigureAwait ( false ) ;
287
+ await Http . DownloadAsync ( x . PluginNewUserPlugin . UrlDownload , downloadToFilePath )
288
+ . ConfigureAwait ( false ) ;
289
+ }
290
+ else
291
+ {
292
+ downloadToFilePath = x . PluginNewUserPlugin . LocalInstallPath ;
293
+ }
294
+
271
295
272
296
PluginManager . UpdatePlugin ( x . PluginExistingMetadata , x . PluginNewUserPlugin ,
273
297
downloadToFilePath ) ;
@@ -396,7 +420,7 @@ await Http.DownloadAsync(plugin.PluginNewUserPlugin.UrlDownload, downloadToFileP
396
420
results = results . Prepend ( updateAllResult ) ;
397
421
}
398
422
399
- return Search ( results , search ) ;
423
+ return ! updateFromLocalPath ? Search ( results , search ) : results . ToList ( ) ;
400
424
}
401
425
402
426
internal bool PluginExists ( string id )
@@ -470,6 +494,42 @@ internal List<Result> InstallFromWeb(string url)
470
494
return new List < Result > { result } ;
471
495
}
472
496
497
+ internal List < Result > InstallFromLocalPath ( string localPath )
498
+ {
499
+ var plugin = Utilities . GetPluginInfoFromZip ( localPath ) ;
500
+
501
+ plugin . LocalInstallPath = localPath ;
502
+
503
+ return new List < Result >
504
+ {
505
+ new Result
506
+ {
507
+ Title = $ "{ plugin . Name } by { plugin . Author } ",
508
+ SubTitle = plugin . Description ,
509
+ IcoPath = plugin . IcoPath ,
510
+ Action = e =>
511
+ {
512
+ if ( Settings . WarnFromUnknownSource )
513
+ {
514
+ if ( ! InstallSourceKnown ( plugin . Website )
515
+ && MessageBox . Show ( string . Format (
516
+ Context . API . GetTranslation ( "plugin_pluginsmanager_install_unknown_source_warning" ) ,
517
+ Environment . NewLine ) ,
518
+ Context . API . GetTranslation (
519
+ "plugin_pluginsmanager_install_unknown_source_warning_title" ) ,
520
+ MessageBoxButton . YesNo ) == MessageBoxResult . No )
521
+ return false ;
522
+ }
523
+
524
+ Application . Current . MainWindow . Hide ( ) ;
525
+ _ = InstallOrUpdateAsync ( plugin ) ;
526
+
527
+ return ShouldHideWindow ;
528
+ }
529
+ }
530
+ } ;
531
+ }
532
+
473
533
private bool InstallSourceKnown ( string url )
474
534
{
475
535
var author = url . Split ( '/' ) [ 3 ] ;
@@ -489,6 +549,9 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string search, Can
489
549
&& search . Split ( '.' ) . Last ( ) == zip )
490
550
return InstallFromWeb ( search ) ;
491
551
552
+ if ( FilesFolders . IsZipFilePath ( search , checkFileExists : true ) )
553
+ return InstallFromLocalPath ( search ) ;
554
+
492
555
var results =
493
556
PluginsManifest
494
557
. UserPlugins
@@ -522,10 +585,13 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
522
585
if ( ! File . Exists ( downloadedFilePath ) )
523
586
throw new FileNotFoundException ( $ "Plugin { plugin . ID } zip file not found at { downloadedFilePath } ",
524
587
downloadedFilePath ) ;
588
+
525
589
try
526
590
{
527
591
PluginManager . InstallPlugin ( plugin , downloadedFilePath ) ;
528
- File . Delete ( downloadedFilePath ) ;
592
+
593
+ if ( ! plugin . IsFromLocalInstallPath )
594
+ File . Delete ( downloadedFilePath ) ;
529
595
}
530
596
catch ( FileNotFoundException e )
531
597
{
0 commit comments