mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de074e40e0 | ||
|
|
4cf4c6caca | ||
|
|
02dae0e199 | ||
|
|
291c754deb | ||
|
|
a4fd59df08 | ||
|
|
39ccb73e2f | ||
|
|
ae96cdf793 | ||
|
|
0571c386e9 | ||
|
|
95d7a85494 |
5
.github/workflows/Publish.yml
vendored
5
.github/workflows/Publish.yml
vendored
@@ -7,7 +7,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish:
|
publish:
|
||||||
runs-on: windows-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
@@ -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.11.0</version>
|
<version>1.15.2</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.
@@ -55,7 +55,12 @@ internal sealed class HttpShardCopyWorker<TStatus> : IDisposable
|
|||||||
public Task CopyAsync(IProgress<TStatus> progress, CancellationToken token = default)
|
public Task CopyAsync(IProgress<TStatus> progress, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
ShardProgress shardProgress = new(progress, statusFactory, contentLength);
|
ShardProgress shardProgress = new(progress, statusFactory, contentLength);
|
||||||
return Parallel.ForEachAsync(shards, token, (shard, token) => CopyShardAsync(shard, shardProgress, token));
|
ParallelOptions options = new()
|
||||||
|
{
|
||||||
|
MaxDegreeOfParallelism = Math.Clamp(Environment.ProcessorCount, 2, 6),
|
||||||
|
CancellationToken = token,
|
||||||
|
};
|
||||||
|
return Parallel.ForEachAsync(shards, options, (shard, token) => CopyShardAsync(shard, shardProgress, token));
|
||||||
|
|
||||||
async ValueTask CopyShardAsync(Shard shard, IProgress<ShardStatus> progress, CancellationToken token)
|
async ValueTask CopyShardAsync(Shard shard, IProgress<ShardStatus> progress, CancellationToken token)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ internal static partial class Invocation
|
|||||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||||
|
|
||||||
Console.WriteLine($"""
|
Console.WriteLine($"""
|
||||||
|
Snap Hutao Deployment Tool [1.15.2]
|
||||||
PackagePath: {path}
|
PackagePath: {path}
|
||||||
FamilyName: {name}
|
FamilyName: {name}
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
@@ -134,7 +135,10 @@ internal static partial class Invocation
|
|||||||
if (!isUpdateMode)
|
if (!isUpdateMode)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Press enter to exit...");
|
Console.WriteLine("Press enter to exit...");
|
||||||
while (Console.ReadKey(true).Key != ConsoleKey.Enter) ;
|
while (Console.ReadKey(true).Key != ConsoleKey.Enter)
|
||||||
|
{
|
||||||
|
//Pending enter key
|
||||||
|
}
|
||||||
FreeConsole();
|
FreeConsole();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.CommandLine;
|
using System.CommandLine;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Snap.Hutao.Deployment;
|
namespace Snap.Hutao.Deployment;
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -16,30 +20,50 @@ internal static partial class WindowsAppSDKDependency
|
|||||||
public static async Task EnsureAsync(string packagePath)
|
public static async Task EnsureAsync(string packagePath)
|
||||||
{
|
{
|
||||||
using FileStream packageStream = File.OpenRead(packagePath);
|
using FileStream packageStream = File.OpenRead(packagePath);
|
||||||
using ZipArchive package = new(packageStream, ZipArchiveMode.Read);
|
ZipArchive package = default!;
|
||||||
|
try
|
||||||
(string packageName, string msixVersion) = await ExtractRuntimePackageNameAndMsixMinVersionFromAppManifestAsync(package).ConfigureAwait(false);
|
|
||||||
if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(msixVersion))
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("No Windows App Runtime version found in Msix/AppxManifest.xml");
|
package = new(packageStream, ZipArchiveMode.Read);
|
||||||
return;
|
}
|
||||||
|
catch (InvalidDataException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Msix Package corrupted, please re-launch Deployment and try again");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(packagePath);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckRuntimeInstalled(packageName, msixVersion))
|
using (package)
|
||||||
{
|
{
|
||||||
return;
|
(string packageName, string msixVersion) = await ExtractRuntimePackageNameAndMsixMinVersionFromAppManifestAsync(package).ConfigureAwait(false);
|
||||||
}
|
if (string.IsNullOrEmpty(packageName) || string.IsNullOrEmpty(msixVersion))
|
||||||
|
{
|
||||||
|
Console.WriteLine("No Windows App Runtime version found in Msix/AppxManifest.xml");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string sdkVersion = await ExtractSDKVersionFromDepsJsonAsync(package).ConfigureAwait(false);
|
if (await CheckRuntimeInstalledAndVerifyAsync(packageName, msixVersion).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(sdkVersion))
|
string sdkVersion = await ExtractSDKVersionFromDepsJsonAsync(package).ConfigureAwait(false);
|
||||||
{
|
|
||||||
Console.WriteLine("No Windows App SDK version found in Msix/Snap.Hutao.deps.json");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("Start downloading SDK installer...");
|
if (string.IsNullOrEmpty(sdkVersion))
|
||||||
await DownloadWindowsAppRuntimeInstallAndInstallAsync(sdkVersion).ConfigureAwait(false);
|
{
|
||||||
|
Console.WriteLine("No Windows App SDK version found in Msix/Snap.Hutao.deps.json");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Start downloading SDK installer...");
|
||||||
|
await DownloadWindowsAppRuntimeInstallAndInstallAsync(sdkVersion).ConfigureAwait(false);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<string> ExtractSDKVersionFromDepsJsonAsync(ZipArchive package)
|
private static async Task<string> ExtractSDKVersionFromDepsJsonAsync(ZipArchive package)
|
||||||
@@ -63,19 +87,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 +126,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 +159,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