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 1b44e97..125915b 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.7.0 + 1.8.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 2b35bad..421684b 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 4e312ca..f6db938 100644 --- a/src/Snap.Hutao.Deployment/Invocation.cs +++ b/src/Snap.Hutao.Deployment/Invocation.cs @@ -8,7 +8,7 @@ using Windows.Management.Deployment; namespace Snap.Hutao.Deployment; -internal static class Invocation +internal static partial class Invocation { public static async Task RunDeploymentAsync(InvocationContext context) { @@ -16,6 +16,11 @@ internal static class Invocation string? name = context.ParseResult.GetValueForOption(InvocationOptions.FamilyName); bool isUpdateMode = context.ParseResult.GetValueForOption(InvocationOptions.UpdateBehavior); + if (!isUpdateMode) + { + AllocConsole(); + } + ArgumentException.ThrowIfNullOrEmpty(path); Console.WriteLine($""" @@ -30,8 +35,7 @@ internal static class Invocation if (isUpdateMode) { - Console.WriteLine("Exit in 10 seconds..."); - await Task.Delay(10000).ConfigureAwait(false); + await ExitAsync(true).ConfigureAwait(false); return; } else @@ -43,10 +47,11 @@ internal static class Invocation await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false); await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false); - await RunDeploymentCoreAsync(path, name).ConfigureAwait(false); + await RunDeploymentCoreAsync(path, name, isUpdateMode).ConfigureAwait(false); + await ExitAsync(isUpdateMode).ConfigureAwait(false); } - private static async Task RunDeploymentCoreAsync(string path, string? name) + private static async Task RunDeploymentCoreAsync(string path, string? name, bool isUpdateMode) { try { @@ -109,11 +114,7 @@ internal static class Invocation ActivityId: {result.ActivityId} ExtendedErrorCode: {result.ExtendedErrorCode} ErrorText: {result.ErrorText} - - Exit in 10 seconds... """); - - await Task.Delay(10000).ConfigureAwait(false); } } catch (Exception ex) @@ -121,11 +122,30 @@ internal static class Invocation Console.WriteLine($""" Exception occured: {ex} - - Exit in 10 seconds... """); + } + } + private static async ValueTask ExitAsync(bool isUpdateMode) + { + if (!isUpdateMode) + { + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + FreeConsole(); + } + else + { + Console.WriteLine("Exit in 10 seconds..."); await Task.Delay(10000).ConfigureAwait(false); } } + + [LibraryImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial bool AllocConsole(); + + [LibraryImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial bool FreeConsole(); } \ No newline at end of file diff --git a/src/Snap.Hutao.Deployment/Program.cs b/src/Snap.Hutao.Deployment/Program.cs index d09fe65..19aeb40 100644 --- a/src/Snap.Hutao.Deployment/Program.cs +++ b/src/Snap.Hutao.Deployment/Program.cs @@ -1,9 +1,10 @@ using System.CommandLine; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace Snap.Hutao.Deployment; -internal static class Program +internal static partial class Program { internal static async Task Main(string[] args) { diff --git a/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj b/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj index 7cacdde..21d1826 100644 --- a/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj +++ b/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net8.0-windows10.0.22621.0 disable enable @@ -12,6 +12,7 @@ true embedded app.manifest + true