mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8b3f8ae34 | ||
|
|
da33fc0ba3 | ||
|
|
d6f5b7374d | ||
|
|
a16fcbd2bb | ||
|
|
cd6a3bbfd9 |
@@ -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.11.0</version>
|
||||
<authors>DGP Studio</authors>
|
||||
<developmentDependency>true</developmentDependency>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
|
||||
Binary file not shown.
@@ -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
|
||||
@@ -41,91 +45,110 @@ internal static class Invocation
|
||||
}
|
||||
}
|
||||
|
||||
await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false);
|
||||
await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false);
|
||||
await RunDeploymentCoreAsync(path, name).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task RunDeploymentCoreAsync(string path, string? name)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Initializing PackageManager...");
|
||||
PackageManager packageManager = new();
|
||||
AddPackageOptions addPackageOptions = new()
|
||||
{
|
||||
ForceAppShutdown = true,
|
||||
RetainFilesOnFailure = true,
|
||||
};
|
||||
|
||||
Console.WriteLine("Start deploying...");
|
||||
IProgress<DeploymentProgress> progress = new Progress<DeploymentProgress>(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
|
||||
if (ex.HResult is not unchecked((int)0x80073B1F))
|
||||
{
|
||||
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}
|
||||
|
||||
Exit in 10 seconds...
|
||||
""");
|
||||
|
||||
await Task.Delay(10000).ConfigureAwait(false);
|
||||
}
|
||||
await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false);
|
||||
await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false);
|
||||
await RunDeploymentCoreAsync(path, name, isUpdateMode).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"""
|
||||
Exception occured:
|
||||
{ex}
|
||||
|
||||
Exit in 10 seconds...
|
||||
""");
|
||||
}
|
||||
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<DeploymentProgress> progress = new Progress<DeploymentProgress>(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 enter to exit...");
|
||||
while (Console.ReadKey(true).Key != ConsoleKey.Enter) ;
|
||||
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();
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user