@@ -544,38 +544,56 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro
544
544
throw new ArgumentException ( $ "Plugin { plugin . Name } has been modified") ;
545
545
}
546
546
547
- if ( removePluginFromSettings )
548
- {
549
- Settings . Plugins . Remove ( plugin . ID ) ;
550
- AllPlugins . RemoveAll ( p => p . Metadata . ID == plugin . ID ) ;
551
- }
552
-
553
547
if ( removePluginSettings )
554
548
{
555
- var assemblyLoader = new PluginAssemblyLoader ( plugin . ExecuteFilePath ) ;
556
- var assembly = assemblyLoader . LoadAssemblyAndDependencies ( ) ;
557
- var assemblyName = assembly . GetName ( ) . Name ;
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 ;
558
554
559
- // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
560
- // so we need to remove it from the api instance
561
- var method = API . GetType ( ) . GetMethod ( "RemovePluginSettings" ) ;
562
- var pluginJsonStorage = method ? . Invoke ( API , new object [ ] { assemblyName } ) ;
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 } ) ;
563
559
564
- // if there exists a json storage for current plugin, we need to delete the directory path
565
- if ( pluginJsonStorage != null )
566
- {
567
- var deleteMethod = pluginJsonStorage . GetType ( ) . GetMethod ( "DeleteDirectory" ) ;
568
- try
560
+ // if there exists a json storage for current plugin, we need to delete the directory path
561
+ if ( pluginJsonStorage != null )
569
562
{
570
- deleteMethod ? . Invoke ( pluginJsonStorage , null ) ;
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
+ }
571
572
}
572
- catch ( Exception e )
573
+ }
574
+ else // the plugin with json prc interface
575
+ {
576
+ var pluginPair = AllPlugins . FirstOrDefault ( p => p . Metadata . ID == plugin . ID ) ;
577
+ if ( pluginPair != null && pluginPair . Plugin is JsonRPCPlugin jsonRpcPlugin )
573
578
{
574
- Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { assemblyName } ", e ) ;
579
+ try
580
+ {
581
+ jsonRpcPlugin . DeletePluginSettingsDirectory ( ) ;
582
+ }
583
+ catch ( Exception e )
584
+ {
585
+ Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
586
+ }
575
587
}
576
588
}
577
589
}
578
590
591
+ if ( removePluginFromSettings )
592
+ {
593
+ Settings . Plugins . Remove ( plugin . ID ) ;
594
+ AllPlugins . RemoveAll ( p => p . Metadata . ID == plugin . ID ) ;
595
+ }
596
+
579
597
// Marked for deletion. Will be deleted on next start up
580
598
using var _ = File . CreateText ( Path . Combine ( plugin . PluginDirectory , "NeedDelete.txt" ) ) ;
581
599
0 commit comments