diff --git a/.pipelines/ESRPSigning_core.json b/.pipelines/ESRPSigning_core.json index f1af7d7688..aa871e6f15 100644 --- a/.pipelines/ESRPSigning_core.json +++ b/.pipelines/ESRPSigning_core.json @@ -173,7 +173,6 @@ "HelixToolkit.Core.Wpf.dll", "Mages.Core.dll", "JetBrains.Annotations.dll", - "ICSharpCode.SharpZipLib.dll", "NLog.Extensions.Logging.dll", "concrt140_app.dll", "msvcp140_1_app.dll", diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index 1249d9e8dd..dae59f0083 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -1379,7 +1379,7 @@ - + diff --git a/src/modules/launcher/PowerLauncher/Plugin/PluginInstaller.cs b/src/modules/launcher/PowerLauncher/Plugin/PluginInstaller.cs deleted file mode 100644 index ee83e0aa62..0000000000 --- a/src/modules/launcher/PowerLauncher/Plugin/PluginInstaller.cs +++ /dev/null @@ -1,232 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.IO; -using System.IO.Abstractions; -using System.Reflection; -using System.Text.Json; -using System.Windows; -using ICSharpCode.SharpZipLib.Zip; -using Wox.Plugin; -using Wox.Plugin.Logger; - -namespace PowerLauncher.Plugin -{ - internal class PluginInstaller - { - private static readonly IFileSystem FileSystem = new FileSystem(); - private static readonly IPath Path = FileSystem.Path; - private static readonly IFile File = FileSystem.File; - private static readonly IDirectory Directory = FileSystem.Directory; - - internal static void Install(string path) - { - if (File.Exists(path)) - { - string tempFolder = Path.Combine(Path.GetTempPath(), "wox\\plugins"); - if (Directory.Exists(tempFolder)) - { - Directory.Delete(tempFolder, true); - } - - UnZip(path, tempFolder, true); - - string iniPath = Path.Combine(tempFolder, "plugin.json"); - if (!File.Exists(iniPath)) - { - MessageBox.Show("Install failed: plugin config is missing"); - return; - } - - PluginMetadata plugin = GetMetadataFromJson(tempFolder); - if (plugin?.Name == null) - { - MessageBox.Show("Install failed: plugin config is invalid"); - return; - } - - string pluginFolderPath = Constant.PluginsDirectory; - - // Using Ordinal since this is part of a path - string newPluginName = plugin.Name - .Replace("/", "_", StringComparison.Ordinal) - .Replace("\\", "_", StringComparison.Ordinal) - .Replace(":", "_", StringComparison.Ordinal) - .Replace("<", "_", StringComparison.Ordinal) - .Replace(">", "_", StringComparison.Ordinal) - .Replace("?", "_", StringComparison.Ordinal) - .Replace("*", "_", StringComparison.Ordinal) - .Replace("|", "_", StringComparison.Ordinal) - + "-" + Guid.NewGuid(); - string newPluginPath = Path.Combine(pluginFolderPath, newPluginName); - string content = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" + - $"Name: {plugin.Name}{Environment.NewLine}" + - $"Version: {plugin.Version}{Environment.NewLine}" + - $"Author: {plugin.Author}"; - PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID); - - if (existingPlugin != null) - { - content = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" + - $"Name: {plugin.Name}{Environment.NewLine}" + - $"Old Version: {existingPlugin.Metadata.Version}" + - $"{Environment.NewLine}New Version: {plugin.Version}" + - $"{Environment.NewLine}Author: {plugin.Author}"; - } - - var result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (result == MessageBoxResult.Yes) - { - if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory)) - { - // when plugin is in use, we can't delete them. That's why we need to make plugin folder a random name - File.Create(Path.Combine(existingPlugin.Metadata.PluginDirectory, "NeedDelete.txt")).Close(); - } - - UnZip(path, newPluginPath, true); - Directory.Delete(tempFolder, true); - - // existing plugins could be loaded by the application, - // if we try to delete those kind of plugins, we will get a error that indicate the - // file is been used now. - // current solution is to restart wox. Ugly. - // if (MainWindow.Initialized) - // { - // Plugins.Initialize(); - // } - if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine} Restart Wox to take effect?", "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) - { - PluginManager.API.RestartApp(); - } - } - } - } - - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")] - private static PluginMetadata GetMetadataFromJson(string pluginDirectory) - { - string configPath = Path.Combine(pluginDirectory, "plugin.json"); - PluginMetadata metadata; - - if (!File.Exists(configPath)) - { - return null; - } - - try - { - metadata = JsonSerializer.Deserialize(File.ReadAllText(configPath)); - metadata.PluginDirectory = pluginDirectory; - } - catch (Exception e) - { - string error = $"Parse plugin config {configPath} failed: json format is not valid"; - Log.Exception(error, e, MethodBase.GetCurrentMethod().DeclaringType); -#if DEBUG - { - throw new Exception(error); - } -#else - return null; -#endif - } - - if (!AllowedLanguage.IsAllowed(metadata.Language)) - { - string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}"; -#if DEBUG - { - throw new Exception(error); - } -#else - return null; -#endif - } - - if (!File.Exists(metadata.ExecuteFilePath)) - { - string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist"; -#if DEBUG - { - throw new Exception(error); - } -#else - return null; -#endif - } - - return metadata; - } - - /// - /// unzip - /// - /// The zipped file. - /// The STR directory. - /// overwrite - private static void UnZip(string zippedFile, string strDirectory, bool overWrite) - { - if (string.IsNullOrEmpty(strDirectory)) - { - strDirectory = Directory.GetCurrentDirectory(); - } - - // Using Ordinal since this is a path - if (!strDirectory.EndsWith("\\", StringComparison.Ordinal)) - { - strDirectory += "\\"; - } - - using (ZipInputStream s = new ZipInputStream(File.OpenRead(zippedFile))) - { - ZipEntry theEntry; - - while ((theEntry = s.GetNextEntry()) != null) - { - string directoryName = string.Empty; - string pathToZip = string.Empty; - pathToZip = theEntry.Name; - - if (!string.IsNullOrEmpty(pathToZip)) - { - directoryName = Path.GetDirectoryName(pathToZip) + "\\"; - } - - string fileName = Path.GetFileName(pathToZip); - - Directory.CreateDirectory(strDirectory + directoryName); - - if (!string.IsNullOrEmpty(fileName)) - { - if ((File.Exists(strDirectory + directoryName + fileName) && overWrite) || (!File.Exists(strDirectory + directoryName + fileName))) - { - using (Stream streamWriter = File.Create(strDirectory + directoryName + fileName)) - { - byte[] data = new byte[2048]; - while (true) - { - int size = s.Read(data, 0, data.Length); - - if (size > 0) - { - streamWriter.Write(data, 0, size); - } - else - { - break; - } - } - - streamWriter.Close(); - } - } - } - } - - s.Close(); - } - } - } -} diff --git a/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs b/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs index 29ae0bf5de..243adc9f4a 100644 --- a/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs +++ b/src/modules/launcher/PowerLauncher/Plugin/PluginManager.cs @@ -165,11 +165,6 @@ namespace PowerLauncher.Plugin } } - public static void InstallPlugin(string path) - { - PluginInstaller.Install(path); - } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")] public static List QueryForPlugin(PluginPair pair, Query query, bool delayedExecution = false) { diff --git a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj index ad6eb06765..06384a12b1 100644 --- a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj +++ b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj @@ -103,7 +103,6 @@ - diff --git a/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs b/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs index 5641713bd3..8c6940973c 100644 --- a/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs +++ b/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs @@ -103,11 +103,6 @@ namespace Wox }); } - public void InstallPlugin(string path) - { - Application.Current.Dispatcher.Invoke(() => PluginManager.InstallPlugin(path)); - } - public List GetAllPlugins() { return PluginManager.AllPlugins.ToList(); diff --git a/src/modules/launcher/Wox.Plugin/IPublicAPI.cs b/src/modules/launcher/Wox.Plugin/IPublicAPI.cs index 92c1b4805d..a26af295ed 100644 --- a/src/modules/launcher/Wox.Plugin/IPublicAPI.cs +++ b/src/modules/launcher/Wox.Plugin/IPublicAPI.cs @@ -64,12 +64,6 @@ namespace Wox.Plugin /// Message icon path (relative path to your plugin folder) void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true); - /// - /// Install Wox plugin - /// - /// Plugin path (ends with .wox) - void InstallPlugin(string path); - /// /// Get all loaded plugins ///