@@ -880,111 +880,116 @@ internal static bool InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
880880 var tempFolderPluginPath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
881881 System . IO . Compression . ZipFile . ExtractToDirectory ( zipFilePath , tempFolderPluginPath ) ;
882882
883- if ( ! plugin . IsFromLocalInstallPath )
884- File . Delete ( zipFilePath ) ;
885-
886- var pluginFolderPath = GetContainingFolderPathAfterUnzip ( tempFolderPluginPath ) ;
887-
888- var metadataJsonFilePath = string . Empty ;
889- if ( File . Exists ( Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ) )
890- metadataJsonFilePath = Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ;
891-
892- if ( string . IsNullOrEmpty ( metadataJsonFilePath ) || string . IsNullOrEmpty ( pluginFolderPath ) )
893- {
894- PublicApi . Instance . ShowMsgError ( Localize . failedToInstallPluginTitle ( plugin . Name ) ,
895- Localize . fileNotFoundMessage ( pluginFolderPath ) ) ;
896- return false ;
897- }
898-
899- PluginMetadata newMetadata ;
900883 try
901884 {
902- newMetadata = JsonSerializer . Deserialize < PluginMetadata > ( File . ReadAllText ( metadataJsonFilePath ) ) ??
903- throw new JsonException ( "Deserialized metadata is null" ) ;
904- }
905- catch ( Exception ex )
906- {
907- PublicApi . Instance . ShowMsgError ( Localize . failedToInstallPluginTitle ( plugin . Name ) ,
908- Localize . pluginJsonInvalidOrCorrupted ( ) ) ;
909- PublicApi . Instance . LogException ( ClassName ,
910- $ "Failed to deserialize plugin metadata for plugin { plugin . Name } from file { metadataJsonFilePath } ", ex ) ;
911- return false ;
912- }
885+ if ( ! plugin . IsFromLocalInstallPath )
886+ File . Delete ( zipFilePath ) ;
913887
914- if ( SameOrLesserPluginVersionExists ( newMetadata ) )
915- {
916- PublicApi . Instance . ShowMsgError ( Localize . failedToInstallPluginTitle ( plugin . Name ) ,
917- Localize . pluginExistAlreadyMessage ( ) ) ;
918- return false ;
919- }
888+ var pluginFolderPath = GetContainingFolderPathAfterUnzip ( tempFolderPluginPath ) ;
920889
921- if ( ! IsMinimumAppVersionSatisfied ( newMetadata . Name , newMetadata . MinimumAppVersion ) )
922- {
923- // Ask users if they want to install the plugin that doesn't satisfy the minimum app version requirement
924- if ( PublicApi . Instance . ShowMsgBox (
925- Localize . pluginMinimumAppVersionUnsatisfiedMessage ( newMetadata . Name , Environment . NewLine ) ,
926- Localize . pluginMinimumAppVersionUnsatisfiedTitle ( newMetadata . Name , newMetadata . MinimumAppVersion ) ,
927- MessageBoxButton . YesNo ) == MessageBoxResult . No )
890+ var metadataJsonFilePath = string . Empty ;
891+ if ( File . Exists ( Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ) )
892+ metadataJsonFilePath = Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ;
893+
894+ if ( string . IsNullOrEmpty ( metadataJsonFilePath ) || string . IsNullOrEmpty ( pluginFolderPath ) )
928895 {
896+ PublicApi . Instance . ShowMsgError ( Localize . failedToInstallPluginTitle ( plugin . Name ) ,
897+ Localize . fileNotFoundMessage ( pluginFolderPath ) ) ;
929898 return false ;
930899 }
931- }
932900
933- var folderName = string . IsNullOrEmpty ( plugin . Version ) ? $ "{ plugin . Name } -{ Guid . NewGuid ( ) } " : $ "{ plugin . Name } -{ plugin . Version } ";
901+ PluginMetadata newMetadata ;
902+ try
903+ {
904+ newMetadata = JsonSerializer . Deserialize < PluginMetadata > ( File . ReadAllText ( metadataJsonFilePath ) ) ??
905+ throw new JsonException ( "Deserialized metadata is null" ) ;
906+ }
907+ catch ( Exception ex )
908+ {
909+ PublicApi . Instance . ShowMsgError ( Localize . failedToInstallPluginTitle ( plugin . Name ) ,
910+ Localize . pluginJsonInvalidOrCorrupted ( ) ) ;
911+ PublicApi . Instance . LogException ( ClassName ,
912+ $ "Failed to deserialize plugin metadata for plugin { plugin . Name } from file { metadataJsonFilePath } ", ex ) ;
913+ return false ;
914+ }
934915
935- var defaultPluginIDs = new List < string >
916+ if ( SameOrLesserPluginVersionExists ( newMetadata ) )
936917 {
937- "0ECADE17459B49F587BF81DC3A125110" , // BrowserBookmark
938- "CEA0FDFC6D3B4085823D60DC76F28855" , // Calculator
939- "572be03c74c642baae319fc283e561a8" , // Explorer
940- "6A122269676E40EB86EB543B945932B9" , // PluginIndicator
941- "9f8f9b14-2518-4907-b211-35ab6290dee7" , // PluginsManager
942- "b64d0a79-329a-48b0-b53f-d658318a1bf6" , // ProcessKiller
943- "791FC278BA414111B8D1886DFE447410" , // Program
944- "D409510CD0D2481F853690A07E6DC426" , // Shell
945- "CEA08895D2544B019B2E9C5009600DF4" , // Sys
946- "0308FD86DE0A4DEE8D62B9B535370992" , // URL
947- "565B73353DBF4806919830B9202EE3BF" , // WebSearch
948- "5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
949- } ;
918+ PublicApi . Instance . ShowMsgError ( Localize . failedToInstallPluginTitle ( plugin . Name ) ,
919+ Localize . pluginExistAlreadyMessage ( ) ) ;
920+ return false ;
921+ }
950922
951- // Treat default plugin differently, it needs to be removable along with each flow release
952- var installDirectory = ! defaultPluginIDs . Any ( x => x == plugin . ID )
953- ? DataLocation . PluginsDirectory
954- : Constant . PreinstalledDirectory ;
923+ if ( ! IsMinimumAppVersionSatisfied ( newMetadata . Name , newMetadata . MinimumAppVersion ) )
924+ {
925+ // Ask users if they want to install the plugin that doesn't satisfy the minimum app version requirement
926+ if ( PublicApi . Instance . ShowMsgBox (
927+ Localize . pluginMinimumAppVersionUnsatisfiedMessage ( newMetadata . Name , Environment . NewLine ) ,
928+ Localize . pluginMinimumAppVersionUnsatisfiedTitle ( newMetadata . Name , newMetadata . MinimumAppVersion ) ,
929+ MessageBoxButton . YesNo ) == MessageBoxResult . No )
930+ {
931+ return false ;
932+ }
933+ }
955934
956- var newPluginPath = Path . Combine ( installDirectory , folderName ) ;
935+ var folderName = string . IsNullOrEmpty ( plugin . Version ) ? $ " { plugin . Name } - { Guid . NewGuid ( ) } " : $ " { plugin . Name } - { plugin . Version } " ;
957936
958- FilesFolders . CopyAll ( pluginFolderPath , newPluginPath , ( s ) => PublicApi . Instance . ShowMsgBox ( s ) ) ;
937+ var defaultPluginIDs = new List < string >
938+ {
939+ "0ECADE17459B49F587BF81DC3A125110" , // BrowserBookmark
940+ "CEA0FDFC6D3B4085823D60DC76F28855" , // Calculator
941+ "572be03c74c642baae319fc283e561a8" , // Explorer
942+ "6A122269676E40EB86EB543B945932B9" , // PluginIndicator
943+ "9f8f9b14-2518-4907-b211-35ab6290dee7" , // PluginsManager
944+ "b64d0a79-329a-48b0-b53f-d658318a1bf6" , // ProcessKiller
945+ "791FC278BA414111B8D1886DFE447410" , // Program
946+ "D409510CD0D2481F853690A07E6DC426" , // Shell
947+ "CEA08895D2544B019B2E9C5009600DF4" , // Sys
948+ "0308FD86DE0A4DEE8D62B9B535370992" , // URL
949+ "565B73353DBF4806919830B9202EE3BF" , // WebSearch
950+ "5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
951+ } ;
952+
953+ // Treat default plugin differently, it needs to be removable along with each flow release
954+ var installDirectory = ! defaultPluginIDs . Any ( x => x == plugin . ID )
955+ ? DataLocation . PluginsDirectory
956+ : Constant . PreinstalledDirectory ;
957+
958+ var newPluginPath = Path . Combine ( installDirectory , folderName ) ;
959+
960+ FilesFolders . CopyAll ( pluginFolderPath , newPluginPath , ( s ) => PublicApi . Instance . ShowMsgBox ( s ) ) ;
961+
962+ // Check if marker file exists and delete it
963+ try
964+ {
965+ var markerFilePath = Path . Combine ( newPluginPath , DataLocation . PluginDeleteFile ) ;
966+ if ( File . Exists ( markerFilePath ) )
967+ File . Delete ( markerFilePath ) ;
968+ }
969+ catch ( Exception e )
970+ {
971+ PublicApi . Instance . LogException ( ClassName , $ "Failed to delete plugin marker file in { newPluginPath } ", e ) ;
972+ }
959973
960- // Check if marker file exists and delete it
961- try
962- {
963- var markerFilePath = Path . Combine ( newPluginPath , DataLocation . PluginDeleteFile ) ;
964- if ( File . Exists ( markerFilePath ) )
965- File . Delete ( markerFilePath ) ;
966- }
967- catch ( Exception e )
968- {
969- PublicApi . Instance . LogException ( ClassName , $ "Failed to delete plugin marker file in { newPluginPath } ", e ) ;
970- }
974+ if ( checkModified )
975+ {
976+ ModifiedPlugins . Add ( plugin . ID ) ;
977+ }
971978
972- try
973- {
974- if ( Directory . Exists ( tempFolderPluginPath ) )
975- Directory . Delete ( tempFolderPluginPath , true ) ;
976- }
977- catch ( Exception e )
978- {
979- PublicApi . Instance . LogException ( ClassName , $ "Failed to delete temp folder { tempFolderPluginPath } ", e ) ;
979+ return true ;
980980 }
981-
982- if ( checkModified )
981+ finally
983982 {
984- ModifiedPlugins . Add ( plugin . ID ) ;
983+ try
984+ {
985+ if ( Directory . Exists ( tempFolderPluginPath ) )
986+ Directory . Delete ( tempFolderPluginPath , true ) ;
987+ }
988+ catch ( Exception e )
989+ {
990+ PublicApi . Instance . LogException ( ClassName , $ "Failed to delete temp folder { tempFolderPluginPath } ", e ) ;
991+ }
985992 }
986-
987- return true ;
988993 }
989994
990995 internal static async Task < bool > UninstallPluginAsync ( PluginMetadata plugin , bool removePluginFromSettings , bool removePluginSettings , bool checkModified )
0 commit comments