diff --git a/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/CurvaLauncher.Plugins.SHLoadIndirectStringList.fsproj b/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/CurvaLauncher.Plugins.SHLoadIndirectStringList.fsproj index d0be99b..6d5fffa 100644 --- a/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/CurvaLauncher.Plugins.SHLoadIndirectStringList.fsproj +++ b/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/CurvaLauncher.Plugins.SHLoadIndirectStringList.fsproj @@ -1,11 +1,14 @@  + + Library net8.0-windows true + false @@ -13,25 +16,15 @@ - + + PreserveNewest + - - - - - - - - - - - - - + diff --git a/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/Manifest.json b/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/Manifest.json new file mode 100644 index 0000000..47c9412 --- /dev/null +++ b/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/Manifest.json @@ -0,0 +1,4 @@ +{ + "ID": "SHLoadIndirectStringList", + "Assembly": "CurvaLauncher.Plugins.SHLoadIndirectStringList.dll" +} \ No newline at end of file diff --git a/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/SHLoadIndirectStringList.fs b/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/SHLoadIndirectStringList.fs index c543c9e..cce49ae 100644 --- a/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/SHLoadIndirectStringList.fs +++ b/src/AdditionalPlugins/CurvaLauncher.Plugins.SHLoadIndirectStringList/SHLoadIndirectStringList.fs @@ -31,20 +31,6 @@ type public StringQueryResult(title, desc, weight) = type public SHLoadIndirectStringPlugin(context: CurvaLauncherContext) = inherit SyncPlugin(context) - static do - AppDomain.CurrentDomain.add_AssemblyResolve(fun _ args -> - let asmName = new AssemblyName(args.Name) - let dllName = "FSharp.Core.dll" - if asmName.Name = "FSharp.Core" then - [| - (Path.Combine(AppContext.BaseDirectory, dllName)) - (Path.Combine(AppContext.BaseDirectory, "Libraries", dllName)); - (Path.Combine(Directory.GetCurrentDirectory(), dllName)) - |].Where(File.Exists).First() |> Assembly.LoadFrom - else - null - ) - [] static extern uint SHLoadIndirectString(string pszSource, char& pszOutBuf, int cchOutBuf, nativeint ppvReserved) diff --git a/src/CurvaLauncher.Plugins/PluginAssemblyLoadContext.cs b/src/CurvaLauncher.Plugins/PluginAssemblyLoadContext.cs new file mode 100644 index 0000000..a364164 --- /dev/null +++ b/src/CurvaLauncher.Plugins/PluginAssemblyLoadContext.cs @@ -0,0 +1,29 @@ +using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Runtime.Loader; + +namespace CurvaLauncher.Plugins; + +public sealed class PluginAssemblyLoadContext : AssemblyLoadContext +{ + private readonly AssemblyDependencyResolver resolver; + + public PluginAssemblyLoadContext(string pluginID, string dllPath) + : base($"ZipPlugin ALC - {pluginID}") + { + resolver = new(dllPath); + } + + protected override Assembly? Load(AssemblyName assemblyName) + { + string? resolvedPath = resolver.ResolveAssemblyToPath(assemblyName); + return resolvedPath is not null ? LoadFromAssemblyPath(resolvedPath) : null; + } + + protected override nint LoadUnmanagedDll(string unmanagedDllName) + { + string? resolvedPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName); + return resolvedPath is not null ? LoadUnmanagedDllFromPath(resolvedPath) : IntPtr.Zero; + } +} diff --git a/src/CurvaLauncher.Plugins/PluginManifest.cs b/src/CurvaLauncher.Plugins/PluginManifest.cs new file mode 100644 index 0000000..04dcf06 --- /dev/null +++ b/src/CurvaLauncher.Plugins/PluginManifest.cs @@ -0,0 +1,3 @@ +namespace CurvaLauncher.Plugins; + +public sealed record PluginManifest(string ID, string Assembly); diff --git a/src/CurvaLauncher.Plugins/PluginTypeAttribute.cs b/src/CurvaLauncher.Plugins/PluginTypeAttribute.cs new file mode 100644 index 0000000..67b037e --- /dev/null +++ b/src/CurvaLauncher.Plugins/PluginTypeAttribute.cs @@ -0,0 +1,12 @@ +namespace CurvaLauncher.Plugins; + +[AttributeUsage(AttributeTargets.Assembly)] +public sealed class PluginTypeAttribute : Attribute +{ + public Type PluginType { get; private set; } + + public PluginTypeAttribute(Type pluginType) + { + PluginType = pluginType; + } +} diff --git a/src/CurvaLauncher.sln b/src/CurvaLauncher.sln index fcc589e..9831eb3 100644 --- a/src/CurvaLauncher.sln +++ b/src/CurvaLauncher.sln @@ -39,13 +39,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurvaLauncher.Plugins.Every EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F36EDE5B-9C67-44F4-87A9-792390FECF85}" ProjectSection(SolutionItems) = preProject + Plugins\CopyAfterBuild.targets = Plugins\CopyAfterBuild.targets CurvaLauncher.props = CurvaLauncher.props + Plugins\PackAfterBuild.targets = Plugins\PackAfterBuild.targets + Plugins\Plugin.props = Plugins\Plugin.props EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{45D0660D-436E-4419-AEB9-B6ED5BC3E0ED}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CurvaLauncher.PluginTemplate", "Templates\CurvaLauncher.PluginTemplate\CurvaLauncher.PluginTemplate.csproj", "{702E5FF3-99D0-4FD3-86E2-04C0A2E82560}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -174,14 +173,6 @@ Global {C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Release|Any CPU.Build.0 = Release|Any CPU {C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Release|x64.ActiveCfg = Release|x64 {C7AC6C75-89C6-42E5-8D2A-D06994949F05}.Release|x64.Build.0 = Release|x64 - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Debug|Any CPU.Build.0 = Debug|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Debug|x64.ActiveCfg = Debug|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Debug|x64.Build.0 = Debug|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Release|Any CPU.ActiveCfg = Release|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Release|Any CPU.Build.0 = Release|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Release|x64.ActiveCfg = Release|Any CPU - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -198,7 +189,6 @@ Global {F3F6F783-4636-457F-80E1-CC489F524B43} = {BAACD50D-2F94-4A65-8B13-49031D617CAC} {8CFC1C29-51AA-45ED-A91F-01F513182002} = {4A86F98E-B276-4F75-9847-8D0E4280D887} {C7AC6C75-89C6-42E5-8D2A-D06994949F05} = {BAACD50D-2F94-4A65-8B13-49031D617CAC} - {702E5FF3-99D0-4FD3-86E2-04C0A2E82560} = {45D0660D-436E-4419-AEB9-B6ED5BC3E0ED} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3FC4E11A-3D67-43DE-84D8-DCA1841F0D71} diff --git a/src/CurvaLauncher/App.xaml.cs b/src/CurvaLauncher/App.xaml.cs index c816fa3..d1f4d59 100644 --- a/src/CurvaLauncher/App.xaml.cs +++ b/src/CurvaLauncher/App.xaml.cs @@ -52,7 +52,6 @@ private static IServiceProvider BuildServiceProvider() services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); @@ -81,8 +80,6 @@ protected override void OnStartup(StartupEventArgs e) .GetRequiredService(); var themeService = ServiceProvider .GetRequiredService(); - var libraryService = ServiceProvider - .GetRequiredService(); var globalizationService = ServiceProvider .GetRequiredService(); @@ -91,9 +88,6 @@ protected override void OnStartup(StartupEventArgs e) //new WindowInteropHelper(mainWindow) // .EnsureHandle(); - // 加载库 - libraryService.Setup(); - // 加载插件 pluginService.LoadAllPlugins(); @@ -215,7 +209,7 @@ public static void ShowLauncherWithQuery(string queryText) public static void CloseLauncher() { - var mainWindow = + var mainWindow = ServiceProvider.GetRequiredService(); mainWindow.ViewModel.QueryText = string.Empty; diff --git a/src/CurvaLauncher/Services/LibraryService.cs b/src/CurvaLauncher/Services/LibraryService.cs deleted file mode 100644 index 4f91bd9..0000000 --- a/src/CurvaLauncher/Services/LibraryService.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace CurvaLauncher.Services -{ - public class LibraryService - { - private readonly PathService _pathService; - - public string Path { get; set; } = "Libraries"; - - public ObservableCollection Libraries { get; } = new(); - - public LibraryService( - PathService pathService) - { - _pathService = pathService; - } - - private DirectoryInfo EnsureLibrariesDirectory() - { - DirectoryInfo dir = new DirectoryInfo(_pathService.GetPath(Path)); - - if (!dir.Exists) - dir.Create(); - - return dir; - } - - public void Setup() - { - var dir = EnsureLibrariesDirectory(); - var dllFiles = dir.EnumerateFiles("*.dll"); - - //NativeLibrary.SetDllImportResolver() - - foreach (var dllFile in dllFiles) - { - try - { - var assembly = Assembly.LoadFile(dllFile.FullName); - Libraries.Add(assembly); - } - catch - { - - } - } - } - } -} diff --git a/src/CurvaLauncher/Services/PluginService.cs b/src/CurvaLauncher/Services/PluginService.cs index 616ff50..cc8eab8 100644 --- a/src/CurvaLauncher/Services/PluginService.cs +++ b/src/CurvaLauncher/Services/PluginService.cs @@ -6,16 +6,14 @@ using System.Linq; using System.Reflection; using System.Text.Json; -using System.Text.Json.Nodes; -using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; using CommunityToolkit.Mvvm.Input; using CurvaLauncher.Models; using CurvaLauncher.Plugins; -using CurvaLauncher.PluginInteraction; using System.Diagnostics; using System.IO.Compression; using System.Runtime.Loader; +using IOPath = System.IO.Path; namespace CurvaLauncher.Services; @@ -141,34 +139,20 @@ private bool CoreLoadZipPlugin(AppConfig config, string zipFilePath, [NotNullWhe try { using var zipFile = File.OpenRead(zipFilePath); - using var zipArchive = new ZipArchive(zipFile, ZipArchiveMode.Read); - var assemblyLoadContext = new AssemblyLoadContext(null, false); - - foreach (var entry in zipArchive.Entries) - { - if (!entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) - { - continue; - } - - using var entryStream = entry.Open(); - - try - { - var assembly = assemblyLoadContext.LoadFromStream(entryStream); - - if (pluginInstance is null) - { - CoreLoadPluginFromAssembly(config, assembly, out pluginInstance); - } - } - catch (Exception ex) - { - Debug.WriteLine($"DLL load failed, {ex}"); - } - } - - return pluginInstance is not null; + string extractDir = IOPath.Combine(".cache", IOPath.GetFileNameWithoutExtension(zipFilePath)); + if (Directory.Exists(extractDir)) + Directory.Delete(extractDir, true); + ZipFile.ExtractToDirectory(zipFile, extractDir); + + var manifestJson = File.ReadAllText(IOPath.Combine(extractDir, "Manifest.json")); + var manifest = JsonSerializer.Deserialize(manifestJson); + if (manifest is null) + return false; + + var assemblyPath = IOPath.GetFullPath(IOPath.Combine(extractDir, manifest.Assembly)); + var alc = new PluginAssemblyLoadContext(manifest.ID, assemblyPath); + Assembly assembly = alc.LoadFromAssemblyPath(assemblyPath); + return CoreLoadPluginFromAssembly(config, assembly, out pluginInstance); } catch (Exception ex) { diff --git a/src/Plugins/CopyAfterBuild.targets b/src/Plugins/CopyAfterBuild.targets new file mode 100644 index 0000000..5cc59e1 --- /dev/null +++ b/src/Plugins/CopyAfterBuild.targets @@ -0,0 +1,13 @@ + + + + + <_CompileOutput Include="$(OutputPath)\**"/> + + + + + + \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.Calculator/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.Calculator/AssemblyInfo.cs new file mode 100644 index 0000000..c514305 --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.Calculator/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.Calculator; + +[assembly: PluginType(typeof(CalculatorPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.Calculator/CurvaLauncher.Plugins.Calculator.csproj b/src/Plugins/CurvaLauncher.Plugins.Calculator/CurvaLauncher.Plugins.Calculator.csproj index 5828d2d..83ed092 100644 --- a/src/Plugins/CurvaLauncher.Plugins.Calculator/CurvaLauncher.Plugins.Calculator.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.Calculator/CurvaLauncher.Plugins.Calculator.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -8,10 +10,6 @@ true - - - - True @@ -27,12 +25,6 @@ - - - + - - - - diff --git a/src/Plugins/CurvaLauncher.Plugins.Everything/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.Everything/AssemblyInfo.cs new file mode 100644 index 0000000..f3dd9bf --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.Everything/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.Everything; + +[assembly: PluginType(typeof(EverythingPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.Everything/CurvaLauncher.Plugins.Everything.csproj b/src/Plugins/CurvaLauncher.Plugins.Everything/CurvaLauncher.Plugins.Everything.csproj index 3311a7b..007caf4 100644 --- a/src/Plugins/CurvaLauncher.Plugins.Everything/CurvaLauncher.Plugins.Everything.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.Everything/CurvaLauncher.Plugins.Everything.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -14,10 +16,6 @@ - - - - True @@ -33,12 +31,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.Hashing/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.Hashing/AssemblyInfo.cs new file mode 100644 index 0000000..9122a7d --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.Hashing/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.Hashing; + +[assembly: PluginType(typeof(HashingPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.Hashing/CurvaLauncher.Plugins.Hashing.csproj b/src/Plugins/CurvaLauncher.Plugins.Hashing/CurvaLauncher.Plugins.Hashing.csproj index dcc7421..83ed092 100644 --- a/src/Plugins/CurvaLauncher.Plugins.Hashing/CurvaLauncher.Plugins.Hashing.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.Hashing/CurvaLauncher.Plugins.Hashing.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -8,10 +10,6 @@ true - - - - True @@ -27,12 +25,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.OpenUrl/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.OpenUrl/AssemblyInfo.cs new file mode 100644 index 0000000..28b029f --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.OpenUrl/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.OpenUrl; + +[assembly: PluginType(typeof(OpenUrlPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.OpenUrl/CurvaLauncher.Plugins.OpenUrl.csproj b/src/Plugins/CurvaLauncher.Plugins.OpenUrl/CurvaLauncher.Plugins.OpenUrl.csproj index dcc7421..83ed092 100644 --- a/src/Plugins/CurvaLauncher.Plugins.OpenUrl/CurvaLauncher.Plugins.OpenUrl.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.OpenUrl/CurvaLauncher.Plugins.OpenUrl.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -8,10 +10,6 @@ true - - - - True @@ -27,12 +25,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/AssemblyInfo.cs new file mode 100644 index 0000000..a2f29f8 --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.QuickWebSearch; + +[assembly: PluginType(typeof(QuickWebSearchPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/CurvaLauncher.Plugins.QuickWebSearch.csproj b/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/CurvaLauncher.Plugins.QuickWebSearch.csproj index dcc7421..83ed092 100644 --- a/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/CurvaLauncher.Plugins.QuickWebSearch.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.QuickWebSearch/CurvaLauncher.Plugins.QuickWebSearch.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -8,10 +10,6 @@ true - - - - True @@ -27,12 +25,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.RunApplication/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.RunApplication/AssemblyInfo.cs new file mode 100644 index 0000000..ad27a3f --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.RunApplication/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.RunApplication; + +[assembly: PluginType(typeof(RunApplicationPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.RunApplication/CurvaLauncher.Plugins.RunApplication.csproj b/src/Plugins/CurvaLauncher.Plugins.RunApplication/CurvaLauncher.Plugins.RunApplication.csproj index dfec9c5..d325bd5 100644 --- a/src/Plugins/CurvaLauncher.Plugins.RunApplication/CurvaLauncher.Plugins.RunApplication.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.RunApplication/CurvaLauncher.Plugins.RunApplication.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -13,10 +15,6 @@ - - - - True @@ -32,12 +30,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.RunProgram/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.RunProgram/AssemblyInfo.cs new file mode 100644 index 0000000..6cee964 --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.RunProgram/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.RunProgram; + +[assembly: PluginType(typeof(RunProgramPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.RunProgram/CurvaLauncher.Plugins.RunProgram.csproj b/src/Plugins/CurvaLauncher.Plugins.RunProgram/CurvaLauncher.Plugins.RunProgram.csproj index 1533d9d..07d1121 100644 --- a/src/Plugins/CurvaLauncher.Plugins.RunProgram/CurvaLauncher.Plugins.RunProgram.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.RunProgram/CurvaLauncher.Plugins.RunProgram.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -9,10 +11,6 @@ true - - - - True @@ -28,12 +26,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.Test/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.Test/AssemblyInfo.cs new file mode 100644 index 0000000..2464644 --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.Test/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.Test; + +[assembly: PluginType(typeof(TestPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.Test/CurvaLauncher.Plugins.Test.csproj b/src/Plugins/CurvaLauncher.Plugins.Test/CurvaLauncher.Plugins.Test.csproj index 971e266..7e7c655 100644 --- a/src/Plugins/CurvaLauncher.Plugins.Test/CurvaLauncher.Plugins.Test.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.Test/CurvaLauncher.Plugins.Test.csproj @@ -1,5 +1,7 @@ + + net8.0-windows enable @@ -8,16 +10,6 @@ true - - - - - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.Translator/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.Translator/AssemblyInfo.cs new file mode 100644 index 0000000..760f0a6 --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.Translator/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.Translator; + +[assembly: PluginType(typeof(TranslatorPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.Translator/CurvaLauncher.Plugins.Translator.csproj b/src/Plugins/CurvaLauncher.Plugins.Translator/CurvaLauncher.Plugins.Translator.csproj index dcc7421..fd9315a 100644 --- a/src/Plugins/CurvaLauncher.Plugins.Translator/CurvaLauncher.Plugins.Translator.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.Translator/CurvaLauncher.Plugins.Translator.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -7,11 +9,7 @@ true true - - - - - + True @@ -27,12 +25,6 @@ - - - - - - - + diff --git a/src/Plugins/CurvaLauncher.Plugins.ZXing/AssemblyInfo.cs b/src/Plugins/CurvaLauncher.Plugins.ZXing/AssemblyInfo.cs new file mode 100644 index 0000000..53e6020 --- /dev/null +++ b/src/Plugins/CurvaLauncher.Plugins.ZXing/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using CurvaLauncher.Plugins; +using CurvaLauncher.Plugins.ZXing; + +[assembly: PluginType(typeof(ZXingPlugin))] \ No newline at end of file diff --git a/src/Plugins/CurvaLauncher.Plugins.ZXing/CurvaLauncher.Plugins.ZXing.csproj b/src/Plugins/CurvaLauncher.Plugins.ZXing/CurvaLauncher.Plugins.ZXing.csproj index 93717b7..0c83f08 100644 --- a/src/Plugins/CurvaLauncher.Plugins.ZXing/CurvaLauncher.Plugins.ZXing.csproj +++ b/src/Plugins/CurvaLauncher.Plugins.ZXing/CurvaLauncher.Plugins.ZXing.csproj @@ -1,5 +1,7 @@  + + net8.0-windows enable @@ -14,10 +16,6 @@ $(DefineConstants);NETSTANDARD;NETSTANDARD2_0 - - - - True @@ -33,12 +31,6 @@ - - - - - - - + diff --git a/src/Plugins/PackAfterBuild.targets b/src/Plugins/PackAfterBuild.targets new file mode 100644 index 0000000..8358761 --- /dev/null +++ b/src/Plugins/PackAfterBuild.targets @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Plugins/Plugin.props b/src/Plugins/Plugin.props new file mode 100644 index 0000000..5a515e6 --- /dev/null +++ b/src/Plugins/Plugin.props @@ -0,0 +1,19 @@ + + + + + + false + true + + + + + false + + + false + + + + \ No newline at end of file diff --git a/src/Template/CurvaLauncher.PluginTemplate.csproj b/src/Template/CurvaLauncher.PluginTemplate.csproj new file mode 100644 index 0000000..c0aa20b --- /dev/null +++ b/src/Template/CurvaLauncher.PluginTemplate.csproj @@ -0,0 +1,33 @@ + + + + net8.0 + + CurvaLauncher.PluginTemplate + 0.7.1-beta + EleCho + https://github.com/OrgEleCho/CurvaLauncher + MIT + + Template + false + content + Icon128.png + true + $(NoWarn);NU5110;NU5111;NU5128 + true + false + + + + + + + + + + + + + + diff --git a/src/Template/content/.template.config/dotnetcli.host.json b/src/Template/content/.template.config/dotnetcli.host.json new file mode 100644 index 0000000..5c8f6ef --- /dev/null +++ b/src/Template/content/.template.config/dotnetcli.host.json @@ -0,0 +1,8 @@ +{ + "$schema": "http://json.schemastore.org/dotnetcli.host", + "symbolInfo": { + "CurvaLauncherPath": { + "shortName": "clpath" + } + } +} \ No newline at end of file diff --git a/src/Template/content/.template.config/template.json b/src/Template/content/.template.config/template.json new file mode 100644 index 0000000..792de91 --- /dev/null +++ b/src/Template/content/.template.config/template.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "EleCho", + "classifications": [ + "Plugin" + ], + "identity": "CurvaLauncher.Plugin", + "name": "CurvaLauncher Plugin", + "shortName": "curvaplugin", + "sourceName": "MyCurvaLauncherPlugin", + "preferNameDirectory": true, + "tags": { + "language": "C#", + "type": "project" + }, + "symbols": { + "CurvaLauncherPath": { + "type": "parameter", + "datatype": "text", + "replaces": "$(TemplateCurvaLauncherPath)", + "defaultValue": "../../../CurvaLauncher/bin/Debug/net8.0-windows", + "displayName": "Path to CurvaLauncher executable folder" + } + }, + "sources": [ + { + "exclude": [ + ".template.config/**" + ], + "copyOnly": [ + "CurvaLauncher.props", + "CurvaLauncher.targets" + ] + } + ] +} \ No newline at end of file diff --git a/src/Template/content/CurvaLauncher.props b/src/Template/content/CurvaLauncher.props new file mode 100644 index 0000000..42504d8 --- /dev/null +++ b/src/Template/content/CurvaLauncher.props @@ -0,0 +1,25 @@ + + + + true + win + true + false + + ../CurvaLauncher/build + + + + + false + runtime + + + + + + PreserveNewest + + + + \ No newline at end of file diff --git a/src/Template/content/CurvaLauncher.targets b/src/Template/content/CurvaLauncher.targets new file mode 100644 index 0000000..b345797 --- /dev/null +++ b/src/Template/content/CurvaLauncher.targets @@ -0,0 +1,16 @@ + + + + + $(CurvaLauncherPath)/Plugins + + + + + + \ No newline at end of file diff --git a/src/Template/content/Manifest.json b/src/Template/content/Manifest.json new file mode 100644 index 0000000..f866bb0 --- /dev/null +++ b/src/Template/content/Manifest.json @@ -0,0 +1,4 @@ +{ + "ID": "MyCurvaLauncherPlugin", + "Assembly": "MyCurvaLauncherPlugin.dll" +} \ No newline at end of file diff --git a/src/Template/content/MyCurvaLauncherPlugin.csproj b/src/Template/content/MyCurvaLauncherPlugin.csproj new file mode 100644 index 0000000..f28eef9 --- /dev/null +++ b/src/Template/content/MyCurvaLauncherPlugin.csproj @@ -0,0 +1,32 @@ + + + + + + Library + net8.0-windows + enable + enable + true + CurvaLauncher.Plugins.MyCurvaLauncherPlugin + + + + $(TemplateCurvaLauncherPath) + + + + + false + + + false + + + false + + + + + + \ No newline at end of file diff --git a/src/Template/content/TestPlugin.cs b/src/Template/content/TestPlugin.cs new file mode 100644 index 0000000..205419b --- /dev/null +++ b/src/Template/content/TestPlugin.cs @@ -0,0 +1,46 @@ +using System.Diagnostics; +using System.Windows; +using System.Windows.Media; + +namespace CurvaLauncher.Plugins.MyCurvaLauncherPlugin; + +public class TestPlugin : SyncPlugin +{ + [PluginOption] + public int ResultCount { get; set; } = 5; + + [PluginOption] + public string Title { get; set; } = "Test"; + + public override ImageSource Icon { get; } + + public override string Name => "MyCurvaLauncherPlugin"; + + public override string Description { get; } = "A plugin generated from template."; + + public TestPlugin(CurvaLauncherContext context) : base(context) + { + Icon = null!; + } + + public override IEnumerable Query(string query) + { + if (string.IsNullOrWhiteSpace(query)) + yield break; + + for (int i = 0; i < ResultCount; i++) + { + yield return new TestQueryResult($"{Title} {i}", $"#{i} of the query result.", (float)i / ResultCount); + } + } + + public override void Initialize() + { + Debug.WriteLine("MyCurvaLauncherPlugin loaded"); + } + + public override void Finish() + { + Debug.WriteLine("MyCurvaLauncherPlugin Unloaded"); + } +} \ No newline at end of file diff --git a/src/Template/content/TestQueryResult.cs b/src/Template/content/TestQueryResult.cs new file mode 100644 index 0000000..2e48f7c --- /dev/null +++ b/src/Template/content/TestQueryResult.cs @@ -0,0 +1,29 @@ +using System.Windows; +using System.Windows.Media; + +namespace CurvaLauncher.Plugins.MyCurvaLauncherPlugin; + +public class TestQueryResult : IAsyncActionQueryResult +{ + public float Weight { get; } + + public string Title { get; } + + public string Description { get; } + + public ImageSource? Icon => null; + + public TestQueryResult(string title, string description, float weight) + { + Title = title; + Description = description; + Weight = weight; + } + + public async Task InvokeAsync(CancellationToken cancellationToken) + { + await Task.Delay(2000, cancellationToken); + + MessageBox.Show(Description, Title); + } +} \ No newline at end of file diff --git a/src/Template/content/publishToZip.ps1 b/src/Template/content/publishToZip.ps1 new file mode 100644 index 0000000..b870d2b --- /dev/null +++ b/src/Template/content/publishToZip.ps1 @@ -0,0 +1,2 @@ +$path = $PWD.Path +dotnet build .\MyCurvaLauncherPlugin.csproj -c Release -p:ZipFileDestinationFolder=$path \ No newline at end of file diff --git a/src/Templates/CurvaLauncher.PluginTemplate/.template.config/template.json b/src/Templates/CurvaLauncher.PluginTemplate/.template.config/template.json deleted file mode 100644 index 21072b2..0000000 --- a/src/Templates/CurvaLauncher.PluginTemplate/.template.config/template.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/template", - "author": "EleCho", - "identity": "CurvaLauncher.PluginTemplate", - "classifications": [ - "CurvaLauncher", - "Library" - ], - "name": "CurvaLauncher Plugin", - "description": "Creates a CurvaLauncher plugin", - "tags": { - "language": "C#", - "type": "project" - }, - "shortName": "clp", - "sourceName": "CurvaLauncher.PluginTemplate", - "symbols": { - "EnableI18n": { - "type": "parameter", - "datatype": "bool", - "defaultValue": "true" - } - }, - "sources": [ - { - "modifiers": [ - { - "condition": "(!EnableI18n)", - "exclude": [ - "I18n/EnUs.xaml", - "I18n/ZhHans.xaml" - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/Templates/CurvaLauncher.PluginTemplate/CurvaLauncher.PluginTemplate.csproj b/src/Templates/CurvaLauncher.PluginTemplate/CurvaLauncher.PluginTemplate.csproj deleted file mode 100644 index b9e08d9..0000000 --- a/src/Templates/CurvaLauncher.PluginTemplate/CurvaLauncher.PluginTemplate.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - net8.0-windows - enable - - Template - 0.7.1-beta - CurvaLauncher.PluginTemplate - Icon128.png - https://github.com/OrgEleCho/CurvaLauncher - - true - false - content - MIT - - - - - True - \ - - - - - - - - - - - - - diff --git a/src/Templates/CurvaLauncher.PluginTemplate/I18n/EnUs.xaml b/src/Templates/CurvaLauncher.PluginTemplate/I18n/EnUs.xaml deleted file mode 100644 index a069afb..0000000 --- a/src/Templates/CurvaLauncher.PluginTemplate/I18n/EnUs.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - Sample Plugin - This is a plugin with i18n support - - Test Plugin - Your plugin is running well - \ No newline at end of file diff --git a/src/Templates/CurvaLauncher.PluginTemplate/I18n/ZhHans.xaml b/src/Templates/CurvaLauncher.PluginTemplate/I18n/ZhHans.xaml deleted file mode 100644 index 4bc7010..0000000 --- a/src/Templates/CurvaLauncher.PluginTemplate/I18n/ZhHans.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - 示例插件 - 这是一个支持本地化的插件 - - 测试插件 - 你的插件运行良好 - \ No newline at end of file diff --git a/src/Templates/CurvaLauncher.PluginTemplate/SomePlugin.cs b/src/Templates/CurvaLauncher.PluginTemplate/SomePlugin.cs deleted file mode 100644 index bfee57a..0000000 --- a/src/Templates/CurvaLauncher.PluginTemplate/SomePlugin.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using CurvaLauncher; -using CurvaLauncher.Plugins; - -namespace CurvaLauncher.PluginTemplate -{ -#if (!EnableI18n) - public class SomePlugin : Plugin, ISyncPlugin - { - public override string Name => "Sample Plugin"; // Plugin Name - public override string Description => "Plugin Description"; // Plugin Description - - public override ImageSource Icon { get; } - = new WriteableBitmap(10, 10, 96, 96, PixelFormats.Bgra32, null); // Empty Icon - - public SomePlugin(CurvaLauncherContext context) : base(context) - { - // With CurvaLauncherContext, you can use some APIs - // provided by CurvaLauncher - - } - - public IEnumerable Query(string query) - { - if (string.IsNullOrWhiteSpace(query)) - { - yield break; - } - - yield return new EmptyQueryResult("Test Plugin OK", $"Your plugin {Name} is running well", 1, null); - } - } -#else - public class SomePlugin : SyncI18nPlugin - { - private readonly CurvaLauncherContext _context; - private readonly Assembly _currentAssembly; - - public override object NameKey => "StrPluginName"; // Plugin name resource key - public override object DescriptionKey => "StrPluginDescription"; // Plugin description resource key - - public override ImageSource Icon { get; } - = new WriteableBitmap(10, 10, 96, 96, PixelFormats.Bgra32, null); // Empty Icon - - public SomePlugin(CurvaLauncherContext context) : base(context) - { - _context = context; - _currentAssembly = Assembly.GetExecutingAssembly(); - - // With CurvaLauncherContext, you can use some APIs - // provided by CurvaLauncher - - } - - public override IEnumerable GetI18nResourceDictionaries() - { - yield return I18nResourceDictionary.Create(new CultureInfo("en-US"), "I18n/EnUs.xaml"); - yield return I18nResourceDictionary.Create(new CultureInfo("zh-Hans"), "I18n/ZhHans.xaml"); - } - - public override IEnumerable Query(string query) - { - if (string.IsNullOrWhiteSpace(query)) - { - yield break; - } - - yield return new EmptyQueryResult( - _context.GetI18nResourceString(_currentAssembly, "StrTestResultTitle")!, - _context.GetI18nResourceString(_currentAssembly, "StrTestResultDescription")!, - 1, - null); - } - } -#endif -} diff --git a/src/Templates/Templates.sln b/src/Templates/Templates.sln deleted file mode 100644 index 47b5534..0000000 --- a/src/Templates/Templates.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.5.002.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurvaLauncher.I18nPluginTemplate", "CurvaLauncher.I18nPluginTemplate\CurvaLauncher.I18nPluginTemplate.csproj", "{6DE03DDB-7AD5-49B0-B212-07C15D8E1F8C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CurvaLauncher.PluginTemplate", "CurvaLauncher.PluginTemplate\CurvaLauncher.PluginTemplate.csproj", "{709E311C-73D1-438E-B77A-5919CEFDCD72}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6DE03DDB-7AD5-49B0-B212-07C15D8E1F8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6DE03DDB-7AD5-49B0-B212-07C15D8E1F8C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6DE03DDB-7AD5-49B0-B212-07C15D8E1F8C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6DE03DDB-7AD5-49B0-B212-07C15D8E1F8C}.Release|Any CPU.Build.0 = Release|Any CPU - {709E311C-73D1-438E-B77A-5919CEFDCD72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {709E311C-73D1-438E-B77A-5919CEFDCD72}.Debug|Any CPU.Build.0 = Debug|Any CPU - {709E311C-73D1-438E-B77A-5919CEFDCD72}.Release|Any CPU.ActiveCfg = Release|Any CPU - {709E311C-73D1-438E-B77A-5919CEFDCD72}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2C1A7E26-DDBB-4487-ACEB-F681452D34C7} - EndGlobalSection -EndGlobal