@@ -51,7 +51,7 @@ internal PluginsManager(PluginInitContext context, Settings settings)
51
51
52
52
private Task _downloadManifestTask = Task . CompletedTask ;
53
53
54
- internal Task UpdateManifestAsync ( )
54
+ internal Task UpdateManifestAsync ( bool silent = false )
55
55
{
56
56
if ( _downloadManifestTask . Status == TaskStatus . Running )
57
57
{
@@ -60,10 +60,11 @@ internal Task UpdateManifestAsync()
60
60
else
61
61
{
62
62
_downloadManifestTask = PluginsManifest . UpdateTask ;
63
- _downloadManifestTask . ContinueWith ( _ =>
64
- Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_update_failed_title" ) ,
65
- Context . API . GetTranslation ( "plugin_pluginsmanager_update_failed_subtitle" ) , icoPath , false ) ,
66
- TaskContinuationOptions . OnlyOnFaulted ) ;
63
+ if ( ! silent )
64
+ _downloadManifestTask . ContinueWith ( _ =>
65
+ Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_update_failed_title" ) ,
66
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_failed_subtitle" ) , icoPath , false ) ,
67
+ TaskContinuationOptions . OnlyOnFaulted ) ;
67
68
return _downloadManifestTask ;
68
69
}
69
70
}
@@ -113,8 +114,8 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
113
114
. Any ( x => x . Metadata . ID == plugin . ID && x . Metadata . Version . CompareTo ( plugin . Version ) < 0 ) )
114
115
{
115
116
if ( MessageBox . Show ( Context . API . GetTranslation ( "plugin_pluginsmanager_update_exists" ) ,
116
- Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
117
- MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
117
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
118
+ MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
118
119
Context
119
120
. API
120
121
. ChangeQuery (
@@ -138,13 +139,13 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
138
139
Environment . NewLine , Environment . NewLine ) ;
139
140
140
141
if ( MessageBox . Show ( message , Context . API . GetTranslation ( "plugin_pluginsmanager_install_title" ) ,
141
- MessageBoxButton . YesNo ) == MessageBoxResult . No )
142
+ MessageBoxButton . YesNo ) == MessageBoxResult . No )
142
143
return ;
143
144
144
145
// at minimum should provide a name, but handle plugin that is not downloaded from plugins manifest and is a url download
145
146
var downloadFilename = string . IsNullOrEmpty ( plugin . Version )
146
- ? $ "{ plugin . Name } -{ Guid . NewGuid ( ) } .zip"
147
- : $ "{ plugin . Name } -{ plugin . Version } .zip";
147
+ ? $ "{ plugin . Name } -{ Guid . NewGuid ( ) } .zip"
148
+ : $ "{ plugin . Name } -{ plugin . Version } .zip";
148
149
149
150
var filePath = Path . Combine ( DataLocation . PluginsDirectory , downloadFilename ) ;
150
151
@@ -161,7 +162,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
161
162
{
162
163
if ( e is HttpRequestException )
163
164
MessageBox . Show ( Context . API . GetTranslation ( "plugin_pluginsmanager_download_error" ) ,
164
- Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ) ;
165
+ Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ) ;
165
166
166
167
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
167
168
string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_subtitle" ) ,
@@ -173,7 +174,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
173
174
}
174
175
175
176
Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_title" ) ,
176
- Context . API . GetTranslation ( "plugin_pluginsmanager_install_success_restart" ) ) ;
177
+ Context . API . GetTranslation ( "plugin_pluginsmanager_install_success_restart" ) ) ;
177
178
178
179
Context . API . RestartApp ( ) ;
179
180
}
@@ -241,8 +242,8 @@ where existingPlugin.Metadata.Version.CompareTo(pluginFromManifest.Version) <
241
242
Environment . NewLine , Environment . NewLine ) ;
242
243
243
244
if ( MessageBox . Show ( message ,
244
- Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
245
- MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
245
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
246
+ MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
246
247
{
247
248
Uninstall ( x . PluginExistingMetadata , false ) ;
248
249
@@ -277,11 +278,10 @@ await Http.DownloadAsync(x.PluginNewUserPlugin.UrlDownload, downloadToFilePath)
277
278
278
279
return false ;
279
280
} ,
280
- ContextData =
281
+ ContextData =
281
282
new UserPlugin
282
283
{
283
- Website = x . PluginNewUserPlugin . Website ,
284
- UrlSourceCode = x . PluginNewUserPlugin . UrlSourceCode
284
+ Website = x . PluginNewUserPlugin . Website , UrlSourceCode = x . PluginNewUserPlugin . UrlSourceCode
285
285
}
286
286
} ) ;
287
287
@@ -340,21 +340,24 @@ internal List<Result> InstallFromWeb(string url)
340
340
if ( Settings . WarnFromUnknownSource )
341
341
{
342
342
if ( ! InstallSourceKnown ( plugin . UrlDownload )
343
- && MessageBox . Show ( string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_unknown_source_warning" ) ,
344
- Environment . NewLine ) ,
345
- Context . API . GetTranslation ( "plugin_pluginsmanager_install_unknown_source_warning_title" ) ,
346
- MessageBoxButton . YesNo ) == MessageBoxResult . No )
343
+ && MessageBox . Show ( string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_unknown_source_warning" ) ,
344
+ Environment . NewLine ) ,
345
+ Context . API . GetTranslation ( "plugin_pluginsmanager_install_unknown_source_warning_title" ) ,
346
+ MessageBoxButton . YesNo ) == MessageBoxResult . No )
347
347
return false ;
348
348
}
349
349
350
350
Application . Current . MainWindow . Hide ( ) ;
351
351
_ = InstallOrUpdate ( plugin ) ;
352
-
352
+
353
353
return ShouldHideWindow ;
354
354
}
355
355
} ;
356
356
357
- return new List < Result > { result } ;
357
+ return new List < Result >
358
+ {
359
+ result
360
+ } ;
358
361
}
359
362
360
363
private bool InstallSourceKnown ( string url )
@@ -377,7 +380,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdate(string searchName,
377
380
378
381
var searchNameWithoutKeyword = searchName . Replace ( Settings . HotKeyInstall , string . Empty , StringComparison . OrdinalIgnoreCase ) . Trim ( ) ;
379
382
380
- if ( Uri . IsWellFormedUriString ( searchNameWithoutKeyword , UriKind . Absolute )
383
+ if ( Uri . IsWellFormedUriString ( searchNameWithoutKeyword , UriKind . Absolute )
381
384
&& searchNameWithoutKeyword . Split ( '.' ) . Last ( ) == zip )
382
385
return InstallFromWeb ( searchNameWithoutKeyword ) ;
383
386
@@ -438,21 +441,21 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
438
441
if ( string . IsNullOrEmpty ( metadataJsonFilePath ) || string . IsNullOrEmpty ( pluginFolderPath ) )
439
442
{
440
443
MessageBox . Show ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_errormetadatafile" ) ,
441
- Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ) ;
442
-
443
- throw new FileNotFoundException (
444
+ Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ) ;
445
+
446
+ throw new FileNotFoundException (
444
447
string . Format ( "Unable to find plugin.json from the extracted zip file, or this path {0} does not exist" , pluginFolderPath ) ) ;
445
448
}
446
449
447
450
if ( SameOrLesserPluginVersionExists ( metadataJsonFilePath ) )
448
451
{
449
452
MessageBox . Show ( string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_duplicate" ) , plugin . Name ) ,
450
- Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ) ;
453
+ Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ) ;
451
454
452
455
throw new InvalidOperationException (
453
456
string . Format ( "A plugin with the same ID and version already exists, " +
454
- "or the version is greater than this downloaded plugin {0}" ,
455
- plugin . Name ) ) ;
457
+ "or the version is greater than this downloaded plugin {0}" ,
458
+ plugin . Name ) ) ;
456
459
}
457
460
458
461
var directory = string . IsNullOrEmpty ( plugin . Version ) ? $ "{ plugin . Name } -{ Guid . NewGuid ( ) } " : $ "{ plugin . Name } -{ plugin . Version } ";
@@ -491,8 +494,8 @@ internal List<Result> RequestUninstall(string search)
491
494
Environment . NewLine , Environment . NewLine ) ;
492
495
493
496
if ( MessageBox . Show ( message ,
494
- Context . API . GetTranslation ( "plugin_pluginsmanager_uninstall_title" ) ,
495
- MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
497
+ Context . API . GetTranslation ( "plugin_pluginsmanager_uninstall_title" ) ,
498
+ MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
496
499
{
497
500
Application . Current . MainWindow . Hide ( ) ;
498
501
Uninstall ( x . Metadata ) ;
@@ -554,8 +557,8 @@ private bool SameOrLesserPluginVersionExists(string metadataPath)
554
557
{
555
558
var newMetadata = JsonSerializer . Deserialize < PluginMetadata > ( File . ReadAllText ( metadataPath ) ) ;
556
559
return Context . API . GetAllPlugins ( )
557
- . Any ( x => x . Metadata . ID == newMetadata . ID
558
- && newMetadata . Version . CompareTo ( x . Metadata . Version ) <= 0 ) ;
560
+ . Any ( x => x . Metadata . ID == newMetadata . ID
561
+ && newMetadata . Version . CompareTo ( x . Metadata . Version ) <= 0 ) ;
559
562
}
560
563
}
561
- }
564
+ }
0 commit comments