-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from ConchbrainClub/main
deploy to prod site
- Loading branch information
Showing
21 changed files
with
299 additions
and
604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> installer = new Argument<string>("installer", "installer path"); | ||
AddArgument((Argument)installer); | ||
|
||
IValueDescriptor<bool> silent = new Option<bool>("--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 | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SoftwareInfo> 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<SoftwareInfo> 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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
Oops, something went wrong.