diff --git a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec index 9673f7c..875419b 100644 --- a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec +++ b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec @@ -2,7 +2,7 @@ Snap.Hutao.Deployment.Runtime - 1.9.0 + 1.10.0 DGP Studio true false diff --git a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe index 6691db4..e950639 100644 Binary files a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe and b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.exe differ diff --git a/src/Snap.Hutao.Deployment/Invocation.cs b/src/Snap.Hutao.Deployment/Invocation.cs index 48643c2..47e3b63 100644 --- a/src/Snap.Hutao.Deployment/Invocation.cs +++ b/src/Snap.Hutao.Deployment/Invocation.cs @@ -45,77 +45,11 @@ internal static partial class Invocation } } - await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false); - await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false); - await RunDeploymentCoreAsync(path, name, isUpdateMode).ConfigureAwait(false); - await ExitAsync(isUpdateMode).ConfigureAwait(false); - } - - private static async Task RunDeploymentCoreAsync(string path, string? name, bool isUpdateMode) - { try { - Console.WriteLine("Initializing PackageManager..."); - PackageManager packageManager = new(); - AddPackageOptions addPackageOptions = new() - { - ForceAppShutdown = true, - RetainFilesOnFailure = true, - }; - - Console.WriteLine("Start deploying..."); - IProgress progress = new Progress(p => - { - Console.WriteLine($"[Deploying]: State: {p.state} Progress: {p.percentage}%"); - }); - DeploymentResult result = await packageManager - .AddPackageByUriAsync(new Uri(path), addPackageOptions) - .AsTask(progress) - .ConfigureAwait(false); - - if (result.IsRegistered) - { - Console.WriteLine("Package deployed."); - if (string.IsNullOrEmpty(name)) - { - Console.WriteLine("FamilyName not provided, enumerating packages."); - - foreach (Windows.ApplicationModel.Package package in packageManager.FindPackages()) - { - try - { - if (package is { DisplayName: "Snap Hutao", PublisherDisplayName: "DGP Studio" }) - { - name = package.Id.FamilyName; - Console.WriteLine($"Package found: {name}"); - } - } - catch (COMException ex) - { - // ERROR_MRM_MAP_NOT_FOUND or ERROR_NOT_FOUND - if (ex.HResult is not unchecked((int)0x80073B1F) or unchecked((int)0x80070490)) - { - throw; - } - } - } - } - - Console.WriteLine("Starting app..."); - Process.Start(new ProcessStartInfo() - { - UseShellExecute = true, - FileName = $@"shell:AppsFolder\{name}!App", - }); - } - else - { - Console.WriteLine($""" - ActivityId: {result.ActivityId} - ExtendedErrorCode: {result.ExtendedErrorCode} - ErrorText: {result.ErrorText} - """); - } + await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false); + await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false); + await RunDeploymentCoreAsync(path, name, isUpdateMode).ConfigureAwait(false); } catch (Exception ex) { @@ -124,14 +58,83 @@ internal static partial class Invocation {ex} """); } + finally + { + await ExitAsync(isUpdateMode).ConfigureAwait(false); + } + } + + private static async Task RunDeploymentCoreAsync(string path, string? name, bool isUpdateMode) + { + Console.WriteLine("Initializing PackageManager..."); + PackageManager packageManager = new(); + AddPackageOptions addPackageOptions = new() + { + ForceAppShutdown = true, + RetainFilesOnFailure = true, + }; + + Console.WriteLine("Start deploying..."); + IProgress progress = new Progress(p => + { + Console.WriteLine($"[Deploying]: State: {p.state} Progress: {p.percentage}%"); + }); + DeploymentResult result = await packageManager + .AddPackageByUriAsync(new Uri(path), addPackageOptions) + .AsTask(progress) + .ConfigureAwait(false); + + if (result.IsRegistered) + { + Console.WriteLine("Package deployed."); + if (string.IsNullOrEmpty(name)) + { + Console.WriteLine("FamilyName not provided, enumerating packages."); + + foreach (Windows.ApplicationModel.Package package in packageManager.FindPackages()) + { + try + { + if (package is { DisplayName: "Snap Hutao", PublisherDisplayName: "DGP Studio" }) + { + name = package.Id.FamilyName; + Console.WriteLine($"Package found: {name}"); + } + } + catch (COMException ex) + { + // ERROR_MRM_MAP_NOT_FOUND or ERROR_NOT_FOUND + if (ex.HResult is not unchecked((int)0x80073B1F) or unchecked((int)0x80070490)) + { + throw; + } + } + } + } + + Console.WriteLine("Starting app..."); + Process.Start(new ProcessStartInfo() + { + UseShellExecute = true, + FileName = $@"shell:AppsFolder\{name}!App", + }); + } + else + { + Console.WriteLine($""" + ActivityId: {result.ActivityId} + ExtendedErrorCode: {result.ExtendedErrorCode} + ErrorText: {result.ErrorText} + """); + } } private static async ValueTask ExitAsync(bool isUpdateMode) { if (!isUpdateMode) { - Console.WriteLine("Press any key to exit..."); - Console.ReadKey(); + Console.WriteLine("Press enter to exit..."); + while (Console.ReadKey(true).Key != ConsoleKey.Enter) ; FreeConsole(); } else