This commit is contained in:
Lightczx
2023-12-28 14:01:46 +08:00
parent 9d71ac82b7
commit cd6a3bbfd9
5 changed files with 36 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Snap.Hutao.Deployment.Runtime</id>
<version>1.7.0</version>
<version>1.8.0</version>
<authors>DGP Studio</authors>
<developmentDependency>true</developmentDependency>
<requireLicenseAcceptance>false</requireLicenseAcceptance>

View File

@@ -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();
}

View File

@@ -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<int> Main(string[] args)
{

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
@@ -12,6 +12,7 @@
<SelfContained>true</SelfContained>
<DebugType>embedded</DebugType>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>