diff --git a/MixApp.Client/Commands/InitCommand.cs b/MixApp.Client/Commands/InitCommand.cs new file mode 100644 index 0000000..81a19f0 --- /dev/null +++ b/MixApp.Client/Commands/InitCommand.cs @@ -0,0 +1,16 @@ +using System.CommandLine; + +namespace MixApp.Client.Commands; + +internal class InitCommand : Command +{ + public InitCommand() : base("init", "Initialize") + { + this.SetHandler(Execute); + } + + private void Execute() + { + + } +} \ No newline at end of file diff --git a/MixApp.Client/Commands/InstallCommand.cs b/MixApp.Client/Commands/InstallCommand.cs new file mode 100644 index 0000000..3798b29 --- /dev/null +++ b/MixApp.Client/Commands/InstallCommand.cs @@ -0,0 +1,67 @@ +using System.CommandLine; +using System.CommandLine.Binding; +using System.Diagnostics; + +namespace MixApp.Client.Commands; + +internal class InstallCommand : Command +{ + const string INSTALL_DIR = "C:/Program Files/"; + + public InstallCommand() : base("install", "Install a package") + { + IValueDescriptor installer = new Argument("installer", "installer path"); + AddArgument((Argument)installer); + + IValueDescriptor silent = new Option("--silent", "silent install"); + AddOption((Option)silent); + + this.SetHandler(Execute, installer, silent); + } + + private void Execute(string installer, bool silent) + { + Process process = new() + { + StartInfo = new FileInfo(installer).Extension switch + { + "msi" => InstallMSI(installer, silent), + "exe" => InstallNSIS(installer, silent), + _ => throw new ArgumentException("Invalid package type"), + } + }; + + process.Start(); + process.WaitForExit(); + } + + private static ProcessStartInfo InstallMSI(string installer, bool silent) + { + string arguments = $"/i \"{installer}\" INSTALLDIR=\"{INSTALL_DIR}\" /l*v \"{INSTALL_DIR}\\install.log\" "; + if (silent) arguments = "/quiet "; + + return new() + { + FileName = "msiexec.exe", + UseShellExecute = false, + CreateNoWindow = true, + Verb = "runas", + Arguments = arguments + }; + } + + private static ProcessStartInfo InstallNSIS(string installer, bool silent) + { + string arguments = $"/D={INSTALL_DIR} "; + if (silent) arguments = $"/S"; + + return new() + { + FileName = installer, + UseShellExecute = false, + CreateNoWindow = true, + Verb = "runas", + Arguments = arguments + }; + } +} \ No newline at end of file diff --git a/MixApp.Client/Commands/ListCommand.cs b/MixApp.Client/Commands/ListCommand.cs new file mode 100644 index 0000000..def60fb --- /dev/null +++ b/MixApp.Client/Commands/ListCommand.cs @@ -0,0 +1,102 @@ +using System.CommandLine; +using System.Runtime.Versioning; +using System.Text.Json; +using Microsoft.Win32; +using MixApp.Client.Model; + +namespace MixApp.Client.Commands; + +[SupportedOSPlatform("windows")] +public class ListCommand : Command +{ + const string UNINSTALL_KEY = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; + + public ListCommand() : base("list", "list installed softwares") + { + this.SetHandler(Execute); + } + + private void Execute() + { + List softwareInfos = []; + + RegistryKey? regUninstall = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(UNINSTALL_KEY, false); + if (regUninstall != null) FindSoft(regUninstall, ref softwareInfos, RegistryView.Registry32); + + regUninstall = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(UNINSTALL_KEY, false); + if (regUninstall != null) FindSoft(regUninstall, ref softwareInfos, RegistryView.Registry64); + + regUninstall = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32).OpenSubKey(UNINSTALL_KEY, false); + if (regUninstall != null) FindSoft(regUninstall, ref softwareInfos, RegistryView.Registry32); + + regUninstall = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64).OpenSubKey(UNINSTALL_KEY, false); + if (regUninstall != null) FindSoft(regUninstall, ref softwareInfos, RegistryView.Registry64); + + string result = JsonSerializer.Serialize(softwareInfos, ListSoftwareInfoJsonCtx.Default.ListSoftwareInfo) ?? string.Empty; + + Console.WriteLine(result); + } + + private static void FindSoft(RegistryKey regUninstall, ref List lst, RegistryView registryView) + { + foreach (var item in regUninstall.GetSubKeyNames()) + { + RegistryKey? regSub = regUninstall.OpenSubKey(item, false); + if (regSub == null) continue; + + string displayName = regSub.GetValue("DisplayName") as string ?? string.Empty; + string installLocation = regSub.GetValue("InstallLocation") as string ?? string.Empty; + string uninstallString = regSub.GetValue("UninstallString") as string ?? string.Empty; + string displayVersion = regSub.GetValue("DisplayVersion") as string ?? string.Empty; + string installDate = regSub.GetValue("InstallDate") as string ?? string.Empty; + string publisher = regSub.GetValue("Publisher") as string ?? string.Empty; + string displayIcon = regSub.GetValue("DisplayIcon") as string ?? string.Empty; + int estimatedSize = (int)regSub.GetValue("EstimatedSize", 0); + int systemComponent = (int)regSub.GetValue("SystemComponent", 0); + + if (string.IsNullOrWhiteSpace(displayName)) continue; + if (string.IsNullOrWhiteSpace(uninstallString)) continue; + if (string.IsNullOrWhiteSpace(displayVersion) && string.IsNullOrWhiteSpace(displayIcon)) continue; + if (systemComponent == 1) continue; + + if (string.IsNullOrWhiteSpace(installDate) && !string.IsNullOrWhiteSpace(displayIcon)) + { + try + { + string[] array = displayIcon.Split(','); + if (array.Length >= 2) + { + uninstallString = array[0]; + } + FileInfo fileInfo = new(uninstallString); + installDate = fileInfo.CreationTime.ToShortDateString(); + } + catch (Exception) + { + } + } + + SoftwareInfo? softModel = lst.FirstOrDefault(item1 => item1.Name == displayName); + + if (softModel == null) + { + lst.Add(new( + displayName, + displayVersion, + installDate, + uninstallString, + publisher, + estimatedSize == 0 ? "未知" : (estimatedSize / 1024.0).ToString("0.00M"), + installLocation, + registryView)); + } + else + { + if (string.IsNullOrWhiteSpace(softModel.DateTime) && !string.IsNullOrWhiteSpace(installDate)) + { + softModel.DateTime = installDate; + } + } + } + } +} diff --git a/MixApp.Client/Commands/OpenFolderCommand.cs b/MixApp.Client/Commands/OpenFolderCommand.cs new file mode 100644 index 0000000..e7b4cf4 --- /dev/null +++ b/MixApp.Client/Commands/OpenFolderCommand.cs @@ -0,0 +1,21 @@ +using System.CommandLine; +using System.Diagnostics; + +namespace MixApp.Client.Commands; + +public class OpenFolderCommand : Command +{ + public OpenFolderCommand() : base("folder", "open a folder") + { + this.SetHandler(Execute); + } + + private void Execute() + { + string downloadsPath = Path.Combine + ( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads" + ); + Process.Start("explorer.exe", downloadsPath); + } +} diff --git a/MixApp.Client/Commands/UnInstallCommand.cs b/MixApp.Client/Commands/UnInstallCommand.cs new file mode 100644 index 0000000..cc427ca --- /dev/null +++ b/MixApp.Client/Commands/UnInstallCommand.cs @@ -0,0 +1,19 @@ +using System.CommandLine; +using System.Diagnostics; + +namespace MixApp.Client.Commands; + +public class UnInstallCommand : Command +{ + public UnInstallCommand() : base("uninstall", "uninstall a package") + { + this.SetHandler(Execute); + } + + private void Execute() + { + var fileName = Path.Combine(Environment.SystemDirectory, "control.exe"); + var arguments = "/name Microsoft.ProgramsAndFeatures"; + Process.Start(fileName, arguments); + } +} diff --git a/MixApp.Client/Extensions/RootCommandExtension.cs b/MixApp.Client/Extensions/RootCommandExtension.cs new file mode 100644 index 0000000..511e41c --- /dev/null +++ b/MixApp.Client/Extensions/RootCommandExtension.cs @@ -0,0 +1,23 @@ +using System.CommandLine; +using MixApp.Client.Commands; + +namespace MixApp.Client.Extensions +{ + public static class RootCommandExtension + { + public static RootCommand Initialize(this RootCommand rootCommand) + { + rootCommand.Add(new InitCommand()); + + if(OperatingSystem.IsWindows()) + { + rootCommand.Add(new InstallCommand()); + rootCommand.Add(new UnInstallCommand()); + rootCommand.Add(new OpenFolderCommand()); + rootCommand.Add(new ListCommand()); + } + + return rootCommand; + } + } +} diff --git a/MixApp.Client/Helper/AppHelper.cs b/MixApp.Client/Helper/AppHelper.cs deleted file mode 100644 index ec056e5..0000000 --- a/MixApp.Client/Helper/AppHelper.cs +++ /dev/null @@ -1,230 +0,0 @@ -using Microsoft.Win32; -using MixApp.Client.Model; -using MixApp.Client.Model.Params; -using PhotinoNET; -using System; -using System.Diagnostics; -using System.Runtime.Versioning; -using System.Security.Cryptography; -using System.Text.Json; -using System.Text.Json.Serialization.Metadata; -using static MixApp.Client.AppHelper; - -namespace MixApp.Client; - -public static class AppHelper -{ - private const string UninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; - private const string Explorer = "explorer.exe"; - private const string Control = "control.exe"; - private const string Dowdloads = "Downloads"; - - public delegate bool AppMethod(T param, out string msg) where T : ParamsBase; - - private static void ExecuteMethod(int id, PhotinoWindow? window, string paraStr, JsonTypeInfo type, AppMethod appMethod) where T : ParamsBase - { - if (JsonSerializer.Deserialize(paraStr, type) is not T param) - { - window?.SendWebMessage(JsonSerializer.Serialize(new ReceveMsg(id, false, $"参数解析失败"), ReceveMsgJsonCtx.Default.ReceveMsg)); - return; - } - - if (appMethod(param, out string msg)) - window?.SendWebMessage(JsonSerializer.Serialize(new ReceveMsg(id, true, msg), ReceveMsgJsonCtx.Default.ReceveMsg)); - else - window?.SendWebMessage(JsonSerializer.Serialize(new ReceveMsg(id, false, msg), ReceveMsgJsonCtx.Default.ReceveMsg)); - } - - public static void Install(int id, PhotinoWindow? window, string paraStr) - { - ExecuteMethod(id, window, paraStr, InstallParameterJsonCtx.Default.InstallParameter, Install); - } - - public static void UnInstall(int id, PhotinoWindow? window, string paraStr) - { - ExecuteMethod(id, window, paraStr, UnInstallParameterJsonCtx.Default.UnInstallParameter, UnInstall); - } - - [SupportedOSPlatform("windows")] - public static void GetSoftewares(int id, PhotinoWindow? window, string paraStr) - { - ExecuteMethod(id, window, paraStr, GetSoftewaresParameterJsonCtx.Default.GetSoftewaresParameter, GetSoftewares); - } - - public static void OpenDownloadFolder(int id, PhotinoWindow? window, string paraStr) - { - ExecuteMethod(id, window, paraStr, OpenDownloadFolderParameterJsonCtx.Default.OpenDownloadFolderParameter, OpenDownloadFolder); - } - - /// - /// Install Application - /// - /// installation package's Type, have msi or exe - /// installation package Path - /// default installation path - /// Verify installation - /// Whether to install silently - private static bool Install(InstallParameter param, out string msg) - { - if (!param.IsValid(out msg)) - { - return false; - } - - Process process = new(); - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - process.StartInfo.Verb = "runas"; - switch (param.PkgType) - { - case PkgType.msi: - CreateMsiProcess(process, param.PkgPath, param.DefaultPath, param.Silent); - break; - case PkgType.exe: - CreateExeProcess(process, param.PkgPath, param.DefaultPath, param.Silent); - break; - default: - throw new ArgumentException("Invalid package type"); - } - process.Start(); - process.WaitForExit(); - - if (process.ExitCode == 0) - { - return true; - } - else - { - msg = "Installation failed "; - return false; - } - } - - private static bool UnInstall(UnInstallParameter _, out string msg) - { - msg = string.Empty; - var fileName = Path.Combine(Environment.SystemDirectory, Control); - var arguments = "/name Microsoft.ProgramsAndFeatures"; - Process.Start(fileName, arguments); - return true; - } - - private static bool OpenDownloadFolder(OpenDownloadFolderParameter _, out string msg) - { - msg = string.Empty; - string downloadsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Dowdloads); - Process.Start(Explorer, downloadsPath); - return true; - } - - /// - /// Obtain a list of all installed software on this computer - /// - [SupportedOSPlatform("windows")] - private static bool GetSoftewares(GetSoftewaresParameter _, out string msg) - { - List lst = new(); - - RegistryKey? regUninstall = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(UninstallKey, false); - if (regUninstall != null) FindSoft(regUninstall, ref lst, RegistryView.Registry32); - - regUninstall = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(UninstallKey, false); - if (regUninstall != null) FindSoft(regUninstall, ref lst, RegistryView.Registry64); - - regUninstall = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32).OpenSubKey(UninstallKey, false); - if (regUninstall != null) FindSoft(regUninstall, ref lst, RegistryView.Registry32); - - regUninstall = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64).OpenSubKey(UninstallKey, false); - if (regUninstall != null) FindSoft(regUninstall, ref lst, RegistryView.Registry64); - - msg = JsonSerializer.Serialize(lst, ListSoftInfoJsonCtx.Default.ListSoftInfo) ?? string.Empty; - - return string.IsNullOrEmpty(msg); - } - - private static void CreateMsiProcess(Process process, string pkgPath, string defaultPath, bool silent) - { - process.StartInfo.FileName = "msiexec.exe"; - if (silent) process.StartInfo.Arguments = "/quiet "; - process.StartInfo.Arguments += $"/i \"{pkgPath}\" INSTALLDIR=\"{defaultPath}\" /l*v \"{defaultPath}\\install.log\""; - } - - private static void CreateExeProcess(Process process, string pkgPath, string defaultPath, bool silent) - { - process.StartInfo.FileName = pkgPath; - if (silent) process.StartInfo.Arguments = $"/S "; - process.StartInfo.Arguments += $"/D={defaultPath}"; - } - - [SupportedOSPlatform("windows")] - private static void FindSoft(RegistryKey regUninstall, ref List lst, RegistryView registryView) - { - foreach (var item in regUninstall.GetSubKeyNames()) - { - RegistryKey? regSub = regUninstall.OpenSubKey(item, false); - if (regSub == null) continue; - - string displayName = regSub.GetValue("DisplayName") as string ?? string.Empty; - string installLocation = regSub.GetValue("InstallLocation") as string ?? string.Empty; - string uninstallString = regSub.GetValue("UninstallString") as string ?? string.Empty; - string displayVersion = regSub.GetValue("DisplayVersion") as string ?? string.Empty; - string installDate = regSub.GetValue("InstallDate") as string ?? string.Empty; - string publisher = regSub.GetValue("Publisher") as string ?? string.Empty; - string displayIcon = regSub.GetValue("DisplayIcon") as string ?? string.Empty; - int estimatedSize = (int)regSub.GetValue("EstimatedSize", 0); - int systemComponent = (int)regSub.GetValue("SystemComponent", 0); - - if (string.IsNullOrWhiteSpace(displayName)) continue; - if (string.IsNullOrWhiteSpace(uninstallString)) continue; - if (string.IsNullOrWhiteSpace(displayVersion) && string.IsNullOrWhiteSpace(displayIcon)) continue; - if (systemComponent == 1) continue; - - if (string.IsNullOrWhiteSpace(installDate) && !string.IsNullOrWhiteSpace(displayIcon)) - { - try - { - string[] array = displayIcon.Split(','); - if (array.Length >= 2) - { - uninstallString = array[0]; - } - FileInfo fileInfo = new(uninstallString); - installDate = fileInfo.CreationTime.ToShortDateString(); - } - catch (Exception) - { - } - } - - SoftInfo? softModel = lst.FirstOrDefault(item1 => item1.Name == displayName); - - if (softModel == null) - { - lst.Add(new( - displayName, - displayVersion, - installDate, - uninstallString, - publisher, - estimatedSize == 0 ? "未知" : (estimatedSize / 1024.0).ToString("0.00M"), - installLocation, - registryView)); - } - else - { - if (string.IsNullOrWhiteSpace(softModel.DateTime) && !string.IsNullOrWhiteSpace(installDate)) - { - softModel.DateTime = installDate; - } - } - } - } - -} - -public static class PkgType -{ - public const string msi = "msi"; - public const string exe = "exe"; -} - diff --git a/MixApp.Client/Helper/Route.cs b/MixApp.Client/Helper/Route.cs deleted file mode 100644 index 1bb0afa..0000000 --- a/MixApp.Client/Helper/Route.cs +++ /dev/null @@ -1,52 +0,0 @@ -using MixApp.Client.Model; -using MixApp.Client.Model.Params; -using PhotinoNET; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - -namespace MixApp.Client.Helper -{ - public static class Route - { - public static List Routers = new(); - - - public static void Init() - { - Routers.Add(new Router(nameof(AppHelper.Install), AppHelper.Install, InstallParameterJsonCtx.Default.InstallParameter)); - Routers.Add(new Router(nameof(AppHelper.UnInstall), AppHelper.UnInstall, UnInstallParameterJsonCtx.Default.UnInstallParameter)); - Routers.Add(new Router(nameof(AppHelper.GetSoftewares), AppHelper.GetSoftewares, GetSoftewaresParameterJsonCtx.Default.GetSoftewaresParameter)); - Routers.Add(new Router(nameof(AppHelper.OpenDownloadFolder), AppHelper.OpenDownloadFolder, OpenDownloadFolderParameterJsonCtx.Default.OpenDownloadFolderParameter)); - } - - public static void Map(PhotinoWindow? window, string message) - { - var sendMsg = JsonSerializer.Deserialize(message, SendMsgJsonCtx.Default.SendMsg); - if (sendMsg == null) - { - window?.SendWebMessage(JsonSerializer.Serialize(new ReceveMsg(-1, false, $"参数解析失败"), ReceveMsgJsonCtx.Default.ReceveMsg)); - return; - } - - try - { - Routers.FirstOrDefault(x => x.MethodName == sendMsg.MethodName)?.Method?.Invoke(sendMsg.ID, window, sendMsg.Parameters); - } - catch (Exception e) - { - window?.SendWebMessage(JsonSerializer.Serialize(new ReceveMsg(sendMsg.ID, false, $"执行失败:{e}"), ReceveMsgJsonCtx.Default.ReceveMsg)); - } - finally - { - window?.SendWebMessage(JsonSerializer.Serialize(new ReceveMsg(sendMsg.ID), ReceveMsgJsonCtx.Default.ReceveMsg)); - } - - - - } - } -} diff --git a/MixApp.Client/MixApp.Client.csproj b/MixApp.Client/MixApp.Client.csproj index c8fd813..9b1a0ac 100644 --- a/MixApp.Client/MixApp.Client.csproj +++ b/MixApp.Client/MixApp.Client.csproj @@ -20,5 +20,6 @@ + diff --git a/MixApp.Client/Model/Params/GetSoftewaresParameter.cs b/MixApp.Client/Model/Params/GetSoftewaresParameter.cs deleted file mode 100644 index 45c1e8c..0000000 --- a/MixApp.Client/Model/Params/GetSoftewaresParameter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using MixApp.Client.Model.Params; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class GetSoftewaresParameter : ParamsBase - { - } - - - [JsonSerializable(typeof(GetSoftewaresParameter))] - internal partial class GetSoftewaresParameterJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Model/Params/InstallParameter.cs b/MixApp.Client/Model/Params/InstallParameter.cs deleted file mode 100644 index 5eaafe6..0000000 --- a/MixApp.Client/Model/Params/InstallParameter.cs +++ /dev/null @@ -1,72 +0,0 @@ -using MixApp.Client.Model.Params; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class InstallParameter : ParamsBase - { - public string PkgType { get; set; } = string.Empty; - public string PkgPath { get; set; } = string.Empty; - public string DefaultPath { get; set; } = string.Empty; - public string Hash { get; set; } = string.Empty; - public bool Silent { get; set; } = false; - - public bool IsValid(out string errMsg) - { - errMsg = string.Empty; - if (string.IsNullOrEmpty(PkgType)) - errMsg += "安装包类型不能为空\n"; - - if (string.IsNullOrEmpty(PkgPath)) - errMsg += "安装包路径不能为空\n"; - - if (!CheckPkgPath(PkgPath)) - errMsg += "安装路径解析失败\n"; - - if (Silent && !CheckInstallPath(DefaultPath)) - errMsg += "默认安装路径解析失败\n"; - - if (!CheckHash(PkgPath, Hash)) - errMsg += "安装包损坏"; - - return string.IsNullOrEmpty(errMsg); - } - - public static bool CheckInstallPath(string? path) => Directory.Exists(path); - - public static bool CheckPkgPath(string? path) => File.Exists(path); - - /// - /// 根据path获取文件hash和checkHash比较,检查文件是否损坏 - /// - /// - /// - /// - /// - public static bool CheckHash(string? path, string? checkHash) - { - // 判断文件是否存在 - if (!File.Exists(path)) - { - throw new FileNotFoundException("文件不存在"); - } - using (var hashAlgorithm = SHA256.Create()) - { - using (var fileStream = File.OpenRead(path)) - { - var fileHash = hashAlgorithm.ComputeHash(fileStream); - var fileHashString = BitConverter.ToString(fileHash).Replace("-", ""); - return fileHashString.Equals(checkHash, StringComparison.OrdinalIgnoreCase); - } - } - } - } - [JsonSerializable(typeof(InstallParameter))] - internal partial class InstallParameterJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Model/Params/OpenDownloadFolderParameter.cs b/MixApp.Client/Model/Params/OpenDownloadFolderParameter.cs deleted file mode 100644 index 0ef6976..0000000 --- a/MixApp.Client/Model/Params/OpenDownloadFolderParameter.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model.Params -{ - public class OpenDownloadFolderParameter : ParamsBase - { - } - - [JsonSerializable(typeof(OpenDownloadFolderParameter))] - internal partial class OpenDownloadFolderParameterJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Model/Params/ParamsBase.cs b/MixApp.Client/Model/Params/ParamsBase.cs deleted file mode 100644 index f9d4baa..0000000 --- a/MixApp.Client/Model/Params/ParamsBase.cs +++ /dev/null @@ -1,13 +0,0 @@ -using PhotinoNET; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MixApp.Client.Model.Params -{ - public class ParamsBase - { - } -} diff --git a/MixApp.Client/Model/Params/UnInstallParameter.cs b/MixApp.Client/Model/Params/UnInstallParameter.cs deleted file mode 100644 index 1edbf85..0000000 --- a/MixApp.Client/Model/Params/UnInstallParameter.cs +++ /dev/null @@ -1,17 +0,0 @@ -using MixApp.Client.Model.Params; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class UnInstallParameter : ParamsBase - { - } - - [JsonSerializable(typeof(UnInstallParameter))] - internal partial class UnInstallParameterJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Model/ReceveMsg.cs b/MixApp.Client/Model/ReceveMsg.cs deleted file mode 100644 index 29a8992..0000000 --- a/MixApp.Client/Model/ReceveMsg.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class ReceveMsg - { - public ReceveMsg() - { - - } - public ReceveMsg(int iD) - { - ID = iD; - } - public ReceveMsg(int iD, bool result, string msg = "") - { - ID = iD; - Result = result; - Msg = msg; - } - public int ID { get; set; } - - public bool Result { get; set; } = true; - - public string Msg { get; set; } = string.Empty; - } - - [JsonSerializable(typeof(ReceveMsg))] - internal partial class ReceveMsgJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Model/Router.cs b/MixApp.Client/Model/Router.cs deleted file mode 100644 index e6ddc53..0000000 --- a/MixApp.Client/Model/Router.cs +++ /dev/null @@ -1,23 +0,0 @@ -using PhotinoNET; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization.Metadata; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class Router - { - public Router(string methodName, Action method, JsonTypeInfo parameterType) - { - MethodName = methodName; - Method = method; - ParameterType = parameterType; - } - public string MethodName { get; set; } = string.Empty; - public Action Method { get; set; } - public JsonTypeInfo ParameterType { get; set; } - } -} diff --git a/MixApp.Client/Model/SendMsg.cs b/MixApp.Client/Model/SendMsg.cs deleted file mode 100644 index f7ad41b..0000000 --- a/MixApp.Client/Model/SendMsg.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http.Json; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class SendMsg - { - public int ID { get; set; } - - public string MethodName { get; set; } = string.Empty; - - public string Parameters { get; set; } = string.Empty; - - } - - [JsonSerializable(typeof(SendMsg))] - internal partial class SendMsgJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Model/SoftInfo.cs b/MixApp.Client/Model/SoftInfo.cs deleted file mode 100644 index 1321c17..0000000 --- a/MixApp.Client/Model/SoftInfo.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Microsoft.Win32; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.Json.Serialization; -using System.Threading.Tasks; - -namespace MixApp.Client.Model -{ - public class SoftInfo - { - public SoftInfo(string name, string version, string dateTime, string uninstallString, string publisher, string estimatedSize, string installLocation, RegistryView registryView) - { - Name = name; - Version = version; - DateTime = dateTime; - UninstallString = uninstallString; - Publisher = publisher; - EstimatedSize = estimatedSize; - InstallLocation = installLocation; - RegistryView = registryView; - } - public string Name { get; set; } = string.Empty; - - public string Version { get; set; } = string.Empty; - public string DateTime { get; set; } = string.Empty; - public string UninstallString { get; set; } = string.Empty; - public string Publisher { get; set; } = string.Empty; - public string EstimatedSize { get; set; } = string.Empty; - public string InstallLocation { get; set; } = string.Empty; - public RegistryView RegistryView { get; set; } - } - - [JsonSerializable(typeof(SoftInfo))] - internal partial class SoftInfoJsonCtx : JsonSerializerContext { } - - - [JsonSerializable(typeof(List))] - internal partial class ListSoftInfoJsonCtx : JsonSerializerContext { } -} diff --git a/MixApp.Client/Models/SoftwareInfo.cs b/MixApp.Client/Models/SoftwareInfo.cs new file mode 100644 index 0000000..6955950 --- /dev/null +++ b/MixApp.Client/Models/SoftwareInfo.cs @@ -0,0 +1,23 @@ +using Microsoft.Win32; +using System.Text.Json.Serialization; + +namespace MixApp.Client.Model; + +public class SoftwareInfo(string name, string version, string dateTime, string uninstallString, string publisher, string estimatedSize, string installLocation, RegistryView registryView) +{ + public string Name { get; set; } = name; + + public string Version { get; set; } = version; + public string DateTime { get; set; } = dateTime; + public string UninstallString { get; set; } = uninstallString; + public string Publisher { get; set; } = publisher; + public string EstimatedSize { get; set; } = estimatedSize; + public string InstallLocation { get; set; } = installLocation; + public RegistryView RegistryView { get; set; } = registryView; +} + +[JsonSerializable(typeof(SoftwareInfo))] +internal partial class SoftwareInfoJsonCtx : JsonSerializerContext { } + +[JsonSerializable(typeof(List))] +internal partial class ListSoftwareInfoJsonCtx : JsonSerializerContext { } \ No newline at end of file diff --git a/MixApp.Client/Program.cs b/MixApp.Client/Program.cs index 09b4861..6840e95 100644 --- a/MixApp.Client/Program.cs +++ b/MixApp.Client/Program.cs @@ -1,78 +1,42 @@ -using MixApp.Client.Helper; -using MixApp.Client.Model; +using MixApp.Client.Extensions; using PhotinoNET; +using System.CommandLine; using System.Drawing; -using System.Security.Principal; -using System.Text.Json; namespace MixApp.Client; class Program { [STAThread] - static void Main(string[] _) + static void Main(string[] args) { - //string windowTitle = "MixStore"; + string windowTitle = "MixStore"; - //PhotinoWindow window = new PhotinoWindow() - // .SetTitle(windowTitle) - // .SetUseOsDefaultSize(false) - // .SetSize(new Size(1400, 930)) - // // .SetContextMenuEnabled(false) - // // .SetDevToolsEnabled(false) - // .SetGrantBrowserPermissions(true) - // .Center() - // .RegisterWebMessageReceivedHandler((object? sender, string sendMsgStr) => - // { - // PhotinoWindow? window = sender as PhotinoWindow; - // Route.Map(window, sendMsgStr); - // }) - // .Load(new Uri("https://mixstore.conchbrain.club/")); + RootCommand rootCommand = []; + rootCommand.Initialize(); - //window.WaitForClose(); - - //string type = PkgType.exe; - //string appPath = "D:\\MyProject\\TestApp\\Vim.exe"; - //string installPath = "D:\\MyProject\\TestApp"; - //string hash = "4BEFED920EB4C6D7C2720F9D0270FF1E9DD991A0581A41B123565C46F5BCB257"; - //AppHelper.Install(type, appPath, installPath, hash); - - //string type = PkgType.msi; - //string appPath = "D:\\MyProject\\TestApp\\7-Zip.msi"; - //string installPath = "D:\\MyProject\\TestApp"; - //string hash = "0BA639B6DACDF573D847C911BD147C6384381A54DAC082B1E8C77BC73D58958B"; - //AppHelper.Install(type, appPath, installPath, hash); - - //AppHelper.UnInstall(); - - //AppHelper.OpenDownloadFolder(string.Empty); - - Route.Init(); - - var param = new InstallParameter - { - PkgType = "msi", - PkgPath = "D:\\MyProject\\TestApp\\7-Zip.msi", - DefaultPath = "D:\\MyProject\\TestApp", - Hash = "0BA639B6DACDF573D847C911BD147C6384381A54DAC082B1E8C77BC73D58958B", - Silent = true - }; - - var paramStr = JsonSerializer.Serialize(param, InstallParameterJsonCtx.Default.InstallParameter); - - var sendMsg = new SendMsg + if (args.Length != 0) { - ID = 123, - MethodName = "GetSoftewares", - Parameters = paramStr - }; - var sendMsgStr = JsonSerializer.Serialize(sendMsg, SendMsgJsonCtx.Default.SendMsg); - - - Route.Map(new PhotinoWindow(), sendMsgStr); - - - + rootCommand.Invoke(args); + return; + } + + PhotinoWindow window = new PhotinoWindow() + .SetTitle(windowTitle) + .SetUseOsDefaultSize(false) + .SetSize(new Size(1400, 930)) + // .SetContextMenuEnabled(false) + // .SetDevToolsEnabled(false) + .SetGrantBrowserPermissions(true) + .Center() + .RegisterWebMessageReceivedHandler((object? sender, string command) => + { + PhotinoWindow? window = sender as PhotinoWindow; + rootCommand.Invoke(command); + }) + .Load(new Uri("https://mixstore.conchbrain.club/")); + + window.WaitForClose(); } } diff --git a/MixApp.Shared/Pages/Collections.razor.cs b/MixApp.Shared/Pages/Collections.razor.cs index 61972a6..4ee4f0f 100644 --- a/MixApp.Shared/Pages/Collections.razor.cs +++ b/MixApp.Shared/Pages/Collections.razor.cs @@ -26,7 +26,6 @@ protected override void OnAfterRender(bool firstRender) public async void LoadData() { Collections = await HttpClient.GetFromJsonAsync>("/v1/collection") ?? []; - Collections.ForEach(i => Console.WriteLine(i.Name)); StateHasChanged(); } }