mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
[PTRun]Remove Wox plugin install dead code/deps (#15869)
This commit is contained in:
@@ -173,7 +173,6 @@
|
|||||||
"HelixToolkit.Core.Wpf.dll",
|
"HelixToolkit.Core.Wpf.dll",
|
||||||
"Mages.Core.dll",
|
"Mages.Core.dll",
|
||||||
"JetBrains.Annotations.dll",
|
"JetBrains.Annotations.dll",
|
||||||
"ICSharpCode.SharpZipLib.dll",
|
|
||||||
"NLog.Extensions.Logging.dll",
|
"NLog.Extensions.Logging.dll",
|
||||||
"concrt140_app.dll",
|
"concrt140_app.dll",
|
||||||
"msvcp140_1_app.dll",
|
"msvcp140_1_app.dll",
|
||||||
|
|||||||
@@ -1379,7 +1379,7 @@
|
|||||||
|
|
||||||
<Component Id="launcherInstallComponent" Directory="LauncherInstallFolder" Guid="5E688DB4-C522-4268-BA54-ED1CDFFE9DB6">
|
<Component Id="launcherInstallComponent" Directory="LauncherInstallFolder" Guid="5E688DB4-C522-4268-BA54-ED1CDFFE9DB6">
|
||||||
<File Source="$(var.BinX64Dir)modules\Launcher\PowerToys.Launcher.dll" />
|
<File Source="$(var.BinX64Dir)modules\Launcher\PowerToys.Launcher.dll" />
|
||||||
<?foreach File in concrt140_app.dll;e_sqlite3.dll;ICSharpCode.SharpZipLib.dll;JetBrains.Annotations.dll;Mages.Core.dll;Microsoft.Search.Interop.dll;Mono.Cecil.dll;Mono.Cecil.Mdb.dll;Mono.Cecil.Pdb.dll;Mono.Cecil.Rocks.dll;msvcp140_1_app.dll;msvcp140_2_app.dll;msvcp140_app.dll;NLog.dll;NLog.Extensions.Logging.dll;PowerToys.PowerLauncher.deps.json;PowerToys.PowerLauncher.dll;PowerToys.PowerLauncher.exe;Microsoft.Xaml.Behaviors.dll;System.Text.Json.dll;PowerToys.PowerLauncher.runtimeconfig.json;System.Data.OleDb.dll;UnitsNet.dll;vcamp140_app.dll;vccorlib140_app.dll;vcomp140_app.dll;vcruntime140_1_app.dll;vcruntime140_app.dll;Wox.Infrastructure.dll;Wox.Plugin.dll;PowerToys.Interop.dll;PowerToys.ManagedTelemetry.dll;PowerToys.PowerLauncher.Telemetry.dll;Microsoft.Data.Sqlite.dll;SQLitePCLRaw.batteries_v2.dll;SQLitePCLRaw.core.dll;SQLitePCLRaw.provider.e_sqlite3.dll;Microsoft.Extensions.Configuration.Abstractions.dll;Microsoft.Extensions.Configuration.Binder.dll;Microsoft.Extensions.Configuration.dll;Microsoft.Extensions.DependencyInjection.Abstractions.dll;Microsoft.Extensions.DependencyInjection.dll;Microsoft.Extensions.Logging.Abstractions.dll;Microsoft.Extensions.Logging.dll;Microsoft.Extensions.Options.dll;Microsoft.Extensions.Primitives.dll;ControlzEx.dll;PowerToys.ManagedCommon.dll;System.IO.Abstractions.dll;PowerToys.Common.UI.dll;System.ServiceProcess.ServiceController.dll;Microsoft.Toolkit.Uwp.Notifications.dll;ModernWpf.Controls.dll;ModernWpf.dll;WinRT.Runtime.dll;Microsoft.Windows.SDK.NET.dll?>
|
<?foreach File in concrt140_app.dll;e_sqlite3.dll;JetBrains.Annotations.dll;Mages.Core.dll;Microsoft.Search.Interop.dll;Mono.Cecil.dll;Mono.Cecil.Mdb.dll;Mono.Cecil.Pdb.dll;Mono.Cecil.Rocks.dll;msvcp140_1_app.dll;msvcp140_2_app.dll;msvcp140_app.dll;NLog.dll;NLog.Extensions.Logging.dll;PowerToys.PowerLauncher.deps.json;PowerToys.PowerLauncher.dll;PowerToys.PowerLauncher.exe;Microsoft.Xaml.Behaviors.dll;System.Text.Json.dll;PowerToys.PowerLauncher.runtimeconfig.json;System.Data.OleDb.dll;UnitsNet.dll;vcamp140_app.dll;vccorlib140_app.dll;vcomp140_app.dll;vcruntime140_1_app.dll;vcruntime140_app.dll;Wox.Infrastructure.dll;Wox.Plugin.dll;PowerToys.Interop.dll;PowerToys.ManagedTelemetry.dll;PowerToys.PowerLauncher.Telemetry.dll;Microsoft.Data.Sqlite.dll;SQLitePCLRaw.batteries_v2.dll;SQLitePCLRaw.core.dll;SQLitePCLRaw.provider.e_sqlite3.dll;Microsoft.Extensions.Configuration.Abstractions.dll;Microsoft.Extensions.Configuration.Binder.dll;Microsoft.Extensions.Configuration.dll;Microsoft.Extensions.DependencyInjection.Abstractions.dll;Microsoft.Extensions.DependencyInjection.dll;Microsoft.Extensions.Logging.Abstractions.dll;Microsoft.Extensions.Logging.dll;Microsoft.Extensions.Options.dll;Microsoft.Extensions.Primitives.dll;ControlzEx.dll;PowerToys.ManagedCommon.dll;System.IO.Abstractions.dll;PowerToys.Common.UI.dll;System.ServiceProcess.ServiceController.dll;Microsoft.Toolkit.Uwp.Notifications.dll;ModernWpf.Controls.dll;ModernWpf.dll;WinRT.Runtime.dll;Microsoft.Windows.SDK.NET.dll?>
|
||||||
<File Id="File_$(var.File)" Source="$(var.BinX64Dir)modules\launcher\$(var.File)" />
|
<File Id="File_$(var.File)" Source="$(var.BinX64Dir)modules\launcher\$(var.File)" />
|
||||||
<?endforeach?>
|
<?endforeach?>
|
||||||
<File Source="$(var.BinX64Dir)Settings\PowerToys.Settings.UI.Lib.dll" />
|
<File Source="$(var.BinX64Dir)Settings\PowerToys.Settings.UI.Lib.dll" />
|
||||||
|
|||||||
@@ -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<PluginMetadata>(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// unzip
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="zippedFile">The zipped file.</param>
|
|
||||||
/// <param name="strDirectory">The STR directory.</param>
|
|
||||||
/// <param name="overWrite">overwrite</param>
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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")]
|
[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<Result> QueryForPlugin(PluginPair pair, Query query, bool delayedExecution = false)
|
public static List<Result> QueryForPlugin(PluginPair pair, Query query, bool delayedExecution = false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -103,7 +103,6 @@
|
|||||||
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
|
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
|
||||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
|
||||||
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
|
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
|
||||||
<PackageReference Include="SharpZipLib" Version="1.2.0" />
|
|
||||||
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
<PackageReference Include="System.Runtime" Version="4.3.1" />
|
||||||
<PackageReference Include="Microsoft.VCRTForwarders.140" Version="1.0.6" />
|
<PackageReference Include="Microsoft.VCRTForwarders.140" Version="1.0.6" />
|
||||||
<PackageReference Include="System.Data.OleDb" Version="4.7.1" />
|
<PackageReference Include="System.Data.OleDb" Version="4.7.1" />
|
||||||
|
|||||||
@@ -103,11 +103,6 @@ namespace Wox
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstallPlugin(string path)
|
|
||||||
{
|
|
||||||
Application.Current.Dispatcher.Invoke(() => PluginManager.InstallPlugin(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PluginPair> GetAllPlugins()
|
public List<PluginPair> GetAllPlugins()
|
||||||
{
|
{
|
||||||
return PluginManager.AllPlugins.ToList();
|
return PluginManager.AllPlugins.ToList();
|
||||||
|
|||||||
@@ -64,12 +64,6 @@ namespace Wox.Plugin
|
|||||||
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
|
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
|
||||||
void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true);
|
void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Install Wox plugin
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="path">Plugin path (ends with .wox)</param>
|
|
||||||
void InstallPlugin(string path);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all loaded plugins
|
/// Get all loaded plugins
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user