diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 64e097379..47edc21c2 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -366,18 +366,28 @@ namespace Flow.Launcher.Core.Plugin return _modifiedPlugins.Contains(uuid); } - public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVersion, string downloadedFilePath) + + /// + /// Update a plugin to new version, from a zip file. Will Delete zip after updating. + /// + public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath) { - InstallPlugin(newVersion, downloadedFilePath, checkModified:false); + InstallPlugin(newVersion, zipFilePath, checkModified:false); UninstallPlugin(existingVersion, removeSettings:false, checkModified:false); _modifiedPlugins.Add(existingVersion.ID); } - public static void InstallPlugin(UserPlugin plugin, string downloadedFilePath) + /// + /// Install a plugin. Will Delete zip after updating. + /// + public static void InstallPlugin(UserPlugin plugin, string zipFilePath) { - InstallPlugin(plugin, downloadedFilePath, true); + InstallPlugin(plugin, zipFilePath, true); } + /// + /// Uninstall a plugin. + /// public static void UninstallPlugin(PluginMetadata plugin, bool removeSettings = true) { UninstallPlugin(plugin, removeSettings, true); @@ -387,7 +397,7 @@ namespace Flow.Launcher.Core.Plugin #region Internal functions - internal static void InstallPlugin(UserPlugin plugin, string downloadedFilePath, bool checkModified) + internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool checkModified) { if (checkModified && PluginModified(plugin.ID)) { @@ -395,21 +405,10 @@ namespace Flow.Launcher.Core.Plugin throw new ArgumentException($"Plugin {plugin.Name} {plugin.ID} has been modified.", nameof(plugin)); } - var tempFolderPath = Path.Combine(Path.GetTempPath(), "flowlauncher"); - var tempFolderPluginPath = Path.Combine(tempFolderPath, "plugin"); - - if (Directory.Exists(tempFolderPath)) - Directory.Delete(tempFolderPath, true); - - Directory.CreateDirectory(tempFolderPath); - - var zipFilePath = Path.Combine(tempFolderPath, Path.GetFileName(downloadedFilePath)); - - File.Copy(downloadedFilePath, zipFilePath); - - File.Delete(downloadedFilePath); - + // Unzip plugin files to temp folder + var tempFolderPluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempFolderPluginPath); + File.Delete(zipFilePath); var pluginFolderPath = GetContainingFolderPathAfterUnzip(tempFolderPluginPath); @@ -454,7 +453,7 @@ namespace Flow.Launcher.Core.Plugin FilesFolders.CopyAll(pluginFolderPath, newPluginPath); - Directory.Delete(pluginFolderPath, true); + Directory.Delete(tempFolderPluginPath, true); if (checkModified) { diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs index b04026804..1206a4cf9 100644 --- a/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs +++ b/Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs @@ -139,7 +139,7 @@ namespace Flow.Launcher.Plugin.PluginsManager ? $"{plugin.Name}-{Guid.NewGuid()}.zip" : $"{plugin.Name}-{plugin.Version}.zip"; - var filePath = Path.Combine(DataLocation.PluginsDirectory, downloadFilename); + var filePath = Path.Combine(Path.GetTempPath(), downloadFilename); try { @@ -240,7 +240,7 @@ namespace Flow.Launcher.Plugin.PluginsManager Context.API.GetTranslation("plugin_pluginsmanager_update_title"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) { - var downloadToFilePath = Path.Combine(DataLocation.PluginsDirectory, + var downloadToFilePath = Path.Combine(Path.GetTempPath(), $"{x.Name}-{x.NewVersion}.zip"); _ = Task.Run(async delegate @@ -414,6 +414,7 @@ namespace Flow.Launcher.Plugin.PluginsManager try { PluginManager.InstallPlugin(plugin, downloadedFilePath); + File.Delete(downloadedFilePath); } catch (FileNotFoundException e) {