@@ -114,6 +114,14 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
114
114
return ;
115
115
}
116
116
117
+ if ( Context . API . PluginModified ( plugin . ID ) )
118
+ {
119
+ Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
120
+ string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_modified_error" ) ,
121
+ plugin . Name ) ) ;
122
+ return ;
123
+ }
124
+
117
125
string message ;
118
126
if ( Settings . AutoRestartAfterChanging )
119
127
{
@@ -158,7 +166,8 @@ await DownloadFileAsync(
158
166
if ( cts . IsCancellationRequested )
159
167
return ;
160
168
else
161
- Install ( plugin , filePath ) ;
169
+ if ( ! Install ( plugin , filePath ) )
170
+ return ;
162
171
}
163
172
catch ( HttpRequestException e )
164
173
{
@@ -273,6 +282,7 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
273
282
select
274
283
new
275
284
{
285
+ existingPlugin . Metadata . ID ,
276
286
pluginUpdateSource . Name ,
277
287
pluginUpdateSource . Author ,
278
288
CurrentVersion = existingPlugin . Metadata . Version ,
@@ -302,6 +312,14 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
302
312
IcoPath = x . IcoPath ,
303
313
Action = e =>
304
314
{
315
+ if ( Context . API . PluginModified ( x . ID ) )
316
+ {
317
+ Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
318
+ string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_modified_error" ) ,
319
+ x . Name ) ) ;
320
+ return false ;
321
+ }
322
+
305
323
string message ;
306
324
if ( Settings . AutoRestartAfterChanging )
307
325
{
@@ -421,6 +439,14 @@ await DownloadFileAsync(
421
439
IcoPath = icoPath ,
422
440
AsyncAction = async e =>
423
441
{
442
+ if ( resultsForUpdate . All ( x => Context . API . PluginModified ( x . ID ) ) )
443
+ {
444
+ Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_install_error_title" ) ,
445
+ string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_modified_error" ) ,
446
+ string . Join ( " " , resultsForUpdate . Select ( x => x . Name ) ) ) ) ;
447
+ return false ;
448
+ }
449
+
424
450
string message ;
425
451
if ( Settings . AutoRestartAfterChanging )
426
452
{
@@ -442,6 +468,7 @@ await DownloadFileAsync(
442
468
return false ;
443
469
}
444
470
471
+ var anyPluginSuccess = false ;
445
472
await Task . WhenAll ( resultsForUpdate . Select ( async plugin =>
446
473
{
447
474
var downloadToFilePath = Path . Combine ( Path . GetTempPath ( ) ,
@@ -462,6 +489,8 @@ await DownloadFileAsync(
462
489
if ( ! await Context . API . UpdatePluginAsync ( plugin . PluginExistingMetadata , plugin . PluginNewUserPlugin ,
463
490
downloadToFilePath ) )
464
491
return ;
492
+
493
+ anyPluginSuccess = true ;
465
494
}
466
495
catch ( Exception ex )
467
496
{
@@ -474,6 +503,8 @@ await DownloadFileAsync(
474
503
}
475
504
} ) ) ;
476
505
506
+ if ( ! anyPluginSuccess ) return false ;
507
+
477
508
if ( Settings . AutoRestartAfterChanging )
478
509
{
479
510
Context . API . ShowMsg ( Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
@@ -682,7 +713,7 @@ internal async ValueTask<List<Result>> RequestInstallOrUpdateAsync(string search
682
713
return Search ( results , search ) ;
683
714
}
684
715
685
- private void Install ( UserPlugin plugin , string downloadedFilePath )
716
+ private bool Install ( UserPlugin plugin , string downloadedFilePath )
686
717
{
687
718
if ( ! File . Exists ( downloadedFilePath ) )
688
719
throw new FileNotFoundException ( $ "Plugin { plugin . ID } zip file not found at { downloadedFilePath } ",
@@ -691,10 +722,12 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
691
722
try
692
723
{
693
724
if ( ! Context . API . InstallPlugin ( plugin , downloadedFilePath ) )
694
- return ;
725
+ return false ;
695
726
696
727
if ( ! plugin . IsFromLocalInstallPath )
697
728
File . Delete ( downloadedFilePath ) ;
729
+
730
+ return true ;
698
731
}
699
732
catch ( FileNotFoundException e )
700
733
{
@@ -716,6 +749,8 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
716
749
plugin . Name ) ) ;
717
750
Context . API . LogException ( ClassName , e . Message , e ) ;
718
751
}
752
+
753
+ return false ;
719
754
}
720
755
721
756
internal List < Result > RequestUninstall ( string search )
@@ -751,7 +786,10 @@ internal List<Result> RequestUninstall(string search)
751
786
MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
752
787
{
753
788
Context . API . HideMainWindow ( ) ;
754
- await UninstallAsync ( x . Metadata ) ;
789
+ if ( ! await UninstallAsync ( x . Metadata ) )
790
+ {
791
+ return false ;
792
+ }
755
793
if ( Settings . AutoRestartAfterChanging )
756
794
{
757
795
Context . API . RestartApp ( ) ;
@@ -776,24 +814,22 @@ internal List<Result> RequestUninstall(string search)
776
814
return Search ( results , search ) ;
777
815
}
778
816
779
- private async Task UninstallAsync ( PluginMetadata plugin )
817
+ private async Task < bool > UninstallAsync ( PluginMetadata plugin )
780
818
{
781
819
try
782
820
{
783
821
var removePluginSettings = Context . API . ShowMsgBox (
784
822
Context . API . GetTranslation ( "plugin_pluginsmanager_keep_plugin_settings_subtitle" ) ,
785
823
Context . API . GetTranslation ( "plugin_pluginsmanager_keep_plugin_settings_title" ) ,
786
824
button : MessageBoxButton . YesNo ) == MessageBoxResult . No ;
787
- if ( ! await Context . API . UninstallPluginAsync ( plugin , removePluginSettings ) )
788
- {
789
- return ;
790
- }
825
+ return await Context . API . UninstallPluginAsync ( plugin , removePluginSettings ) ;
791
826
}
792
827
catch ( ArgumentException e )
793
828
{
794
829
Context . API . LogException ( ClassName , e . Message , e ) ;
795
830
Context . API . ShowMsgError ( Context . API . GetTranslation ( "plugin_pluginsmanager_uninstall_error_title" ) ,
796
831
string . Format ( Context . API . GetTranslation ( "plugin_pluginsmanager_plugin_modified_error" ) , plugin . Name ) ) ;
832
+ return false ;
797
833
}
798
834
}
799
835
}
0 commit comments