mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Merge pull request #4 from DGP-Studio/fix/crash
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>Snap.Hutao.Deployment.Runtime</id>
|
<id>Snap.Hutao.Deployment.Runtime</id>
|
||||||
<version>1.9.0</version>
|
<version>1.10.0</version>
|
||||||
<authors>DGP Studio</authors>
|
<authors>DGP Studio</authors>
|
||||||
<developmentDependency>true</developmentDependency>
|
<developmentDependency>true</developmentDependency>
|
||||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
|
|||||||
Binary file not shown.
@@ -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
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine("Initializing PackageManager...");
|
await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false);
|
||||||
PackageManager packageManager = new();
|
await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false);
|
||||||
AddPackageOptions addPackageOptions = new()
|
await RunDeploymentCoreAsync(path, name, isUpdateMode).ConfigureAwait(false);
|
||||||
{
|
|
||||||
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}
|
|
||||||
""");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -124,14 +58,83 @@ internal static partial class Invocation
|
|||||||
{ex}
|
{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<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)
|
private static async ValueTask ExitAsync(bool isUpdateMode)
|
||||||
{
|
{
|
||||||
if (!isUpdateMode)
|
if (!isUpdateMode)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Press any key to exit...");
|
Console.WriteLine("Press enter to exit...");
|
||||||
Console.ReadKey();
|
while (Console.ReadKey(true).Key != ConsoleKey.Enter) ;
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user