mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39ccb73e2f | ||
|
|
ae96cdf793 | ||
|
|
0571c386e9 | ||
|
|
95d7a85494 | ||
|
|
d8b3f8ae34 | ||
|
|
da33fc0ba3 | ||
|
|
d6f5b7374d |
3
.github/workflows/Publish.yml
vendored
3
.github/workflows/Publish.yml
vendored
@@ -18,9 +18,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
dotnet-version: '8.x'
|
dotnet-version: '8.x'
|
||||||
|
|
||||||
- name: Build Tool
|
|
||||||
run: dotnet publish src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj
|
|
||||||
|
|
||||||
- name: Pack
|
- name: Pack
|
||||||
run: dotnet pack src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.csproj
|
run: dotnet pack src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.csproj
|
||||||
|
|
||||||
|
|||||||
@@ -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.14.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.
@@ -24,6 +24,7 @@ internal static partial class Invocation
|
|||||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||||
|
|
||||||
Console.WriteLine($"""
|
Console.WriteLine($"""
|
||||||
|
Snap Hutao Deployment Tool [1.14.0]
|
||||||
PackagePath: {path}
|
PackagePath: {path}
|
||||||
FamilyName: {name}
|
FamilyName: {name}
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
@@ -45,77 +46,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 +59,86 @@ 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)
|
||||||
|
{
|
||||||
|
//Pending enter key
|
||||||
|
}
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||||
|
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.ServiceProcess;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.Management.Deployment;
|
using Windows.Management.Deployment;
|
||||||
@@ -25,7 +29,7 @@ internal static partial class WindowsAppSDKDependency
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckRuntimeInstalled(packageName, msixVersion))
|
if (await CheckRuntimeInstalledAndVerifyAsync(packageName, msixVersion).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -63,19 +67,21 @@ internal static partial class WindowsAppSDKDependency
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CheckRuntimeInstalled(string packageName, string msixVersion)
|
private static async Task<bool> CheckRuntimeInstalledAndVerifyAsync(string packageName, string msixVersion)
|
||||||
{
|
{
|
||||||
Version msixMinVersion = new(msixVersion);
|
Version msixMinVersion = new(msixVersion);
|
||||||
|
|
||||||
|
List<bool> results = [];
|
||||||
|
|
||||||
foreach (Windows.ApplicationModel.Package installed in new PackageManager().FindPackages())
|
foreach (Windows.ApplicationModel.Package installed in new PackageManager().FindPackages())
|
||||||
{
|
{
|
||||||
if (installed.Id.Name == packageName && installed.Id.Version.ToVersion() >= msixMinVersion)
|
if (installed.Id.Name == packageName && installed.Id.Version.ToVersion() >= msixMinVersion)
|
||||||
{
|
{
|
||||||
return true;
|
results.Add(await installed.VerifyContentIntegrityAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return results.Count > 0 && results.Aggregate((result, element) => result || element);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task DownloadWindowsAppRuntimeInstallAndInstallAsync(string version)
|
private static async Task DownloadWindowsAppRuntimeInstallAndInstallAsync(string version)
|
||||||
@@ -100,6 +106,23 @@ internal static partial class WindowsAppSDKDependency
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceController serviceController = new("appxsvc");
|
||||||
|
if (serviceController.CanStop)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Stopping AppxSvc...");
|
||||||
|
serviceController.Stop();
|
||||||
|
serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(5));
|
||||||
|
|
||||||
|
if (serviceController.Status is not ServiceControllerStatus.Stopped)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Can not stop AppxSvc, timeout...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Can not stop AppxSvc, disallowed...");
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("Start installing SDK...");
|
Console.WriteLine("Start installing SDK...");
|
||||||
Process installerProcess = new()
|
Process installerProcess = new()
|
||||||
{
|
{
|
||||||
@@ -116,12 +139,13 @@ internal static partial class WindowsAppSDKDependency
|
|||||||
installerProcess.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
installerProcess.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
||||||
installerProcess.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
installerProcess.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
||||||
installerProcess.Start();
|
installerProcess.Start();
|
||||||
Console.WriteLine("-----> WindowsAppRuntimeInstall Output begin -----");
|
Console.WriteLine("-----> WindowsAppRuntimeInstall Output begin");
|
||||||
installerProcess.BeginOutputReadLine();
|
installerProcess.BeginOutputReadLine();
|
||||||
installerProcess.BeginErrorReadLine();
|
installerProcess.BeginErrorReadLine();
|
||||||
|
|
||||||
await installerProcess.WaitForExitAsync().ConfigureAwait(false);
|
await installerProcess.WaitForExitAsync().ConfigureAwait(false);
|
||||||
Console.WriteLine("<----- WindowsAppRuntimeInstall Output end -------");
|
Marshal.ThrowExceptionForHR(installerProcess.ExitCode);
|
||||||
|
Console.WriteLine("<----- WindowsAppRuntimeInstall Output end");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
Reference in New Issue
Block a user