@@ -546,50 +546,41 @@ internal static void UninstallPlugin(PluginMetadata plugin, bool removePluginFro
546
546
547
547
if ( removePluginSettings )
548
548
{
549
- if ( AllowedLanguage . IsDotNet ( plugin . Language ) ) // for the plugin in .NET, we can use assembly loader
549
+ // For dotnet plugins, we need to remove their PluginJsonStorage instance
550
+ if ( AllowedLanguage . IsDotNet ( plugin . Language ) )
550
551
{
551
- // if user want to remove the plugin settings, we cannot call save method for the plugin json storage instance of this plugin
552
- // so we need to remove it from the api instance
553
552
var method = API . GetType ( ) . GetMethod ( "RemovePluginSettings" ) ;
554
- var pluginJsonStorage = method ? . Invoke ( API , new object [ ] { plugin . AssemblyName } ) ;
553
+ method ? . Invoke ( API , new object [ ] { plugin . AssemblyName } ) ;
554
+ }
555
555
556
- // if there exists a json storage for current plugin, we need to delete the directory path
557
- if ( pluginJsonStorage != null )
558
- {
559
- var deleteMethod = pluginJsonStorage . GetType ( ) . GetMethod ( "DeleteDirectory" ) ;
560
- try
561
- {
562
- deleteMethod ? . Invoke ( pluginJsonStorage , null ) ;
563
- }
564
- catch ( Exception e )
565
- {
566
- Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
567
- API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
568
- string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
569
- }
570
- }
556
+ try
557
+ {
558
+ var pluginSettingsDirectory = plugin . PluginSettingsDirectoryPath ;
559
+ if ( Directory . Exists ( pluginSettingsDirectory ) )
560
+ Directory . Delete ( pluginSettingsDirectory , true ) ;
571
561
}
572
- else // the plugin with json prc interface
562
+ catch ( Exception e )
573
563
{
574
- var pluginPair = AllPlugins . FirstOrDefault ( p => p . Metadata . ID == plugin . ID ) ;
575
- if ( pluginPair != null && pluginPair . Plugin is JsonRPCPlugin jsonRpcPlugin )
576
- {
577
- try
578
- {
579
- jsonRpcPlugin . DeletePluginSettingsDirectory ( ) ;
580
- }
581
- catch ( Exception e )
582
- {
583
- Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin json folder for { plugin . Name } ", e ) ;
584
- API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
585
- string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
586
- }
587
- }
564
+ Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin settings folder for { plugin . Name } ", e ) ;
565
+ API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginSettingsTitle" ) ,
566
+ string . Format ( API . GetTranslation ( "failedToRemovePluginSettingsMessage" ) , plugin . Name ) ) ;
588
567
}
589
568
}
590
569
591
570
if ( removePluginFromSettings )
592
571
{
572
+ try
573
+ {
574
+ var pluginCacheDirectory = plugin . PluginCacheDirectoryPath ;
575
+ if ( Directory . Exists ( pluginCacheDirectory ) )
576
+ Directory . Delete ( pluginCacheDirectory , true ) ;
577
+ }
578
+ catch ( Exception e )
579
+ {
580
+ Log . Exception ( $ "|PluginManager.UninstallPlugin|Failed to delete plugin cache folder for { plugin . Name } ", e ) ;
581
+ API . ShowMsg ( API . GetTranslation ( "failedToRemovePluginCacheTitle" ) ,
582
+ string . Format ( API . GetTranslation ( "failedToRemovePluginCacheMessage" ) , plugin . Name ) ) ;
583
+ }
593
584
Settings . Plugins . Remove ( plugin . ID ) ;
594
585
AllPlugins . RemoveAll ( p => p . Metadata . ID == plugin . ID ) ;
595
586
}
0 commit comments