@@ -210,9 +210,9 @@ public static async Task InitializePluginsAsync()
210210 {
211211 var failed = string . Join ( "," , failedPlugins . Select ( x => x . Metadata . Name ) ) ;
212212 API . ShowMsg (
213- InternationalizationManager . Instance . GetTranslation ( "failedToInitializePluginsTitle" ) ,
213+ API . GetTranslation ( "failedToInitializePluginsTitle" ) ,
214214 string . Format (
215- InternationalizationManager . Instance . GetTranslation ( "failedToInitializePluginsMessage" ) ,
215+ API . GetTranslation ( "failedToInitializePluginsMessage" ) ,
216216 failed
217217 ) ,
218218 "" ,
@@ -281,7 +281,7 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
281281 return results ;
282282 }
283283
284- public static void UpdatePluginMetadata ( List < Result > results , PluginMetadata metadata , Query query )
284+ public static void UpdatePluginMetadata ( IReadOnlyList < Result > results , PluginMetadata metadata , Query query )
285285 {
286286 foreach ( var r in results )
287287 {
@@ -439,7 +439,7 @@ public static bool PluginModified(string uuid)
439439 public static void UpdatePlugin ( PluginMetadata existingVersion , UserPlugin newVersion , string zipFilePath )
440440 {
441441 InstallPlugin ( newVersion , zipFilePath , checkModified : false ) ;
442- UninstallPlugin ( existingVersion , removeSettings : false , checkModified : false ) ;
442+ UninstallPlugin ( existingVersion , removePluginFromSettings : false , removePluginSettings : false , checkModified : false ) ;
443443 _modifiedPlugins . Add ( existingVersion . ID ) ;
444444 }
445445
@@ -454,9 +454,9 @@ public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
454454 /// <summary>
455455 /// Uninstall a plugin.
456456 /// </summary>
457- public static void UninstallPlugin ( PluginMetadata plugin , bool removeSettings = true )
457+ public static void UninstallPlugin ( PluginMetadata plugin , bool removePluginFromSettings = true , bool removePluginSettings = false )
458458 {
459- UninstallPlugin ( plugin , removeSettings , true ) ;
459+ UninstallPlugin ( plugin , removePluginFromSettings , removePluginSettings , true ) ;
460460 }
461461
462462 #endregion
@@ -521,22 +521,78 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
521521
522522 FilesFolders . CopyAll ( pluginFolderPath , newPluginPath , ( s ) => API . ShowMsgBox ( s ) ) ;
523523
524- Directory . Delete ( tempFolderPluginPath , true ) ;
524+ try
525+ {
526+ if ( Directory . Exists ( tempFolderPluginPath ) )
527+ Directory . Delete ( tempFolderPluginPath , true ) ;
528+ }
529+ catch ( Exception e )
530+ {
531+ Log . Exception ( $ "|PluginManager.InstallPlugin|Failed to delete temp folder { tempFolderPluginPath } ", e ) ;
532+ }
525533
526534 if ( checkModified )
527535 {
528536 _modifiedPlugins . Add ( plugin . ID ) ;
529537 }
530538 }
531539
532- internal static void UninstallPlugin ( PluginMetadata plugin , bool removeSettings , bool checkModified )
540+ internal static void UninstallPlugin ( PluginMetadata plugin , bool removePluginFromSettings , bool removePluginSettings , bool checkModified )
533541 {
534542 if ( checkModified && PluginModified ( plugin . ID ) )
535543 {
536544 throw new ArgumentException ( $ "Plugin { plugin . Name } has been modified") ;
537545 }
538546
539- if ( removeSettings )
547+ if ( removePluginSettings )
548+ {
549+ if ( AllowedLanguage . IsDotNet ( plugin . Language ) ) // for the plugin in .NET, we can use assembly loader
550+ {
551+ var assemblyLoader = new PluginAssemblyLoader ( plugin . ExecuteFilePath ) ;
552+ var assembly = assemblyLoader . LoadAssemblyAndDependencies ( ) ;
553+ var assemblyName = assembly . GetName ( ) . Name ;
554+
555+ // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
556+ // so we need to remove it from the api instance
557+ var method = API . GetType ( ) . GetMethod ( "RemovePluginSettings" ) ;
558+ var pluginJsonStorage = method ? . Invoke ( API , new object [ ] { assemblyName } ) ;
559+
560+ // if there exists a json storage for current plugin, we need to delete the directory path
561+ if ( pluginJsonStorage != null )
562+ {
563+ var deleteMethod = pluginJsonStorage . GetType ( ) . GetMethod ( "DeleteDirectory" ) ;
564+ try
565+ {
566+ deleteMethod ? . Invoke ( pluginJsonStorage , null ) ;
567+ }
568+ catch ( Exception e )
569+ {
570+ Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
571+ API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
572+ string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
573+ }
574+ }
575+ }
576+ else // the plugin with json prc interface
577+ {
578+ var pluginPair = AllPlugins . FirstOrDefault ( p => p . Metadata . ID == plugin . ID ) ;
579+ if ( pluginPair != null && pluginPair . Plugin is JsonRPCPlugin jsonRpcPlugin )
580+ {
581+ try
582+ {
583+ jsonRpcPlugin . DeletePluginSettingsDirectory ( ) ;
584+ }
585+ catch ( Exception e )
586+ {
587+ Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
588+ API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
589+ string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
590+ }
591+ }
592+ }
593+ }
594+
595+ if ( removePluginFromSettings )
540596 {
541597 Settings . Plugins . Remove ( plugin . ID ) ;
542598 AllPlugins . RemoveAll ( p => p . Metadata . ID == plugin . ID ) ;
0 commit comments