mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Deployment.git
synced 2025-11-19 21:08:45 +08:00
Compare commits
14 Commits
feat/webvi
...
1.16.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e31f23ec7c | ||
|
|
f39463f0d3 | ||
|
|
de074e40e0 | ||
|
|
4cf4c6caca | ||
|
|
02dae0e199 | ||
|
|
291c754deb | ||
|
|
a4fd59df08 | ||
|
|
39ccb73e2f | ||
|
|
ae96cdf793 | ||
|
|
0571c386e9 | ||
|
|
95d7a85494 | ||
|
|
d8b3f8ae34 | ||
|
|
da33fc0ba3 | ||
|
|
d6f5b7374d |
5
.github/workflows/Publish.yml
vendored
5
.github/workflows/Publish.yml
vendored
@@ -7,7 +7,7 @@ on:
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: windows-latest
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
@@ -18,9 +18,6 @@ jobs:
|
||||
with:
|
||||
dotnet-version: '8.x'
|
||||
|
||||
- name: Build Tool
|
||||
run: dotnet publish src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj
|
||||
|
||||
- name: Pack
|
||||
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">
|
||||
<metadata>
|
||||
<id>Snap.Hutao.Deployment.Runtime</id>
|
||||
<version>1.9.0</version>
|
||||
<version>1.16.0</version>
|
||||
<authors>DGP Studio</authors>
|
||||
<developmentDependency>true</developmentDependency>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
|
||||
Binary file not shown.
@@ -18,23 +18,30 @@ internal static class Certificate
|
||||
store.Open(OpenFlags.ReadWrite);
|
||||
if (store.Certificates.Any(cert => cert.FriendlyName == CertificateName))
|
||||
{
|
||||
Console.WriteLine("Certificate [GlobalSign Code Signing Root R45] found");
|
||||
Console.WriteLine("""
|
||||
已找到证书 [GlobalSign Code Signing Root R45]
|
||||
Certificate [GlobalSign Code Signing Root R45] found
|
||||
""");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Required Certificate [GlobalSign Code Signing Root R45] not found, download from GlobalSign");
|
||||
Console.WriteLine("""
|
||||
无法找到所需证书 [GlobalSign Code Signing Root R45],正在从 GlobalSign 下载
|
||||
Required Certificate [GlobalSign Code Signing Root R45] not found, downloading from GlobalSign
|
||||
""");
|
||||
|
||||
using (HttpClient httpClient = new())
|
||||
{
|
||||
byte[] rawData = await httpClient.GetByteArrayAsync(CertificateUrl).ConfigureAwait(false);
|
||||
|
||||
Console.WriteLine("""
|
||||
正在向本地计算机/受信任的根证书颁发机构添加证书
|
||||
正在向 本地计算机/受信任的根证书颁发机构 添加证书
|
||||
如果你无法理解弹窗中的文本,请点击 [是]
|
||||
|
||||
Adding certificate to LocalMachine/ThirdParty Root CA store,
|
||||
please click [yes] on the [Security Waring] dialog
|
||||
|
||||
关于更多安全信息,请查看下方的网址
|
||||
For more security information, please visit the url down below
|
||||
https://support.globalsign.com/ca-certificates/root-certificates/globalsign-root-certificates
|
||||
""");
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Deployment;
|
||||
|
||||
internal static partial class EdgeWebView2Dependency
|
||||
{
|
||||
private const string EdgeWebView2DownloadUrl = "https://go.microsoft.com/fwlink/p/?LinkId=2124703";
|
||||
|
||||
private const string EdgeWebView2PerUserPath = @"HKEY_CURRENT_USER\Software\Microsoft\EdgeUpdate\Clients";
|
||||
private const string EdgeWebView2PerMachinePath = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients";
|
||||
private const string EdgeWebView2GuidKey = "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}";
|
||||
|
||||
public static async Task EnsureAsync(bool installWebView2, bool isUpdateMode)
|
||||
{
|
||||
if (!installWebView2 || isUpdateMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Registry.GetValue(EdgeWebView2PerUserPath, EdgeWebView2GuidKey, null) is not null || Registry.GetValue(EdgeWebView2PerMachinePath, EdgeWebView2GuidKey, null) is not null)
|
||||
{
|
||||
Console.WriteLine("WebView2 already installed.");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("WebView2 not found, start downloading and installing WebView2...");
|
||||
await DownloadWebView2InstallerAndInstallAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task DownloadWebView2InstallerAndInstallAsync()
|
||||
{
|
||||
string webView2InstallerPath = Path.Combine(Path.GetTempPath(), "MicrosoftEdgeWebview2Setup.exe");
|
||||
try
|
||||
{
|
||||
using (HttpClient httpClient = new())
|
||||
{
|
||||
HttpShardCopyWorkerOptions<DownloadStatus> options = new()
|
||||
{
|
||||
HttpClient = httpClient,
|
||||
SourceUrl = EdgeWebView2DownloadUrl,
|
||||
DestinationFilePath = webView2InstallerPath,
|
||||
StatusFactory = (bytesRead, totalBytes) => new DownloadStatus(bytesRead, totalBytes),
|
||||
};
|
||||
|
||||
using (HttpShardCopyWorker<DownloadStatus> worker = await HttpShardCopyWorker<DownloadStatus>.CreateAsync(options).ConfigureAwait(false))
|
||||
{
|
||||
Progress<DownloadStatus> progress = new(ConsoleWriteProgress);
|
||||
await worker.CopyAsync(progress).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Start installing WebView2...");
|
||||
Process installerProcess = new()
|
||||
{
|
||||
StartInfo = new()
|
||||
{
|
||||
Arguments = "/silent /install",
|
||||
FileName = webView2InstallerPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
},
|
||||
};
|
||||
|
||||
using (installerProcess)
|
||||
{
|
||||
installerProcess.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
||||
installerProcess.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
||||
installerProcess.Start();
|
||||
Console.WriteLine("-----> WebView2 Output begin -----");
|
||||
installerProcess.BeginOutputReadLine();
|
||||
installerProcess.BeginErrorReadLine();
|
||||
|
||||
await installerProcess.WaitForExitAsync().ConfigureAwait(false);
|
||||
Console.WriteLine("<----- WebView2 Output end -------");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(webView2InstallerPath))
|
||||
{
|
||||
File.Delete(webView2InstallerPath);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConsoleWriteProgress(DownloadStatus status)
|
||||
{
|
||||
Console.Write($"\r{status.ProgressDescription}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,12 @@ internal sealed class HttpShardCopyWorker<TStatus> : IDisposable
|
||||
public Task CopyAsync(IProgress<TStatus> progress, CancellationToken token = default)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Management.Deployment;
|
||||
@@ -15,7 +16,6 @@ internal static partial class Invocation
|
||||
string? path = context.ParseResult.GetValueForOption(InvocationOptions.PackagePath);
|
||||
string? name = context.ParseResult.GetValueForOption(InvocationOptions.FamilyName);
|
||||
bool isUpdateMode = context.ParseResult.GetValueForOption(InvocationOptions.UpdateBehavior);
|
||||
bool installWebView2 = context.ParseResult.GetValueForOption(InvocationOptions.InstallWebView2);
|
||||
|
||||
if (!isUpdateMode)
|
||||
{
|
||||
@@ -25,99 +25,38 @@ internal static partial class Invocation
|
||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||
|
||||
Console.WriteLine($"""
|
||||
Snap Hutao Deployment Tool [1.16.0]
|
||||
PackagePath: {path}
|
||||
FamilyName: {name}
|
||||
------------------------------------------------------------
|
||||
""");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Console.WriteLine($"Package file not found.");
|
||||
|
||||
if (isUpdateMode)
|
||||
{
|
||||
await ExitAsync(true).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Start downloading package...");
|
||||
await PackageDownload.DownloadPackageAsync(path).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false);
|
||||
await WindowsAppSDKDependency.EnsureAsync(path).ConfigureAwait(false);
|
||||
await EdgeWebView2Dependency.EnsureAsync(installWebView2, isUpdateMode).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
|
||||
{
|
||||
Console.WriteLine("Initializing PackageManager...");
|
||||
PackageManager packageManager = new();
|
||||
AddPackageOptions addPackageOptions = new()
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
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}
|
||||
Console.WriteLine("""
|
||||
未找到包文件。
|
||||
Package file not found.
|
||||
""");
|
||||
|
||||
if (isUpdateMode)
|
||||
{
|
||||
await ExitAsync(true).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("""
|
||||
开始下载包文件...
|
||||
Start downloading package...
|
||||
""");
|
||||
await PackageDownload.DownloadPackageAsync(path).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
await Certificate.EnsureGlobalSignCodeSigningRootR45Async().ConfigureAwait(false);
|
||||
await RunDeploymentCoreAsync(path, name, isUpdateMode).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -126,14 +65,104 @@ internal static partial class Invocation
|
||||
{ex}
|
||||
""");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await ExitAsync(isUpdateMode).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task RunDeploymentCoreAsync(string path, string? name, bool isUpdateMode)
|
||||
{
|
||||
Console.WriteLine("""
|
||||
初始化 PackageManager...
|
||||
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,正在枚举包。
|
||||
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 any key to exit...");
|
||||
Console.ReadKey();
|
||||
Console.WriteLine("""
|
||||
按下回车键退出...
|
||||
Press enter to exit...
|
||||
""");
|
||||
while (Console.ReadKey(true).Key != ConsoleKey.Enter)
|
||||
{
|
||||
//Pending enter key
|
||||
}
|
||||
FreeConsole();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -19,9 +19,4 @@ internal static class InvocationOptions
|
||||
"--update-behavior",
|
||||
() => false,
|
||||
"Change behavior of the tool into update mode");
|
||||
|
||||
public static readonly Option<bool> InstallWebView2 = new(
|
||||
"--install-webview2",
|
||||
() => false,
|
||||
"Install WebView2 if not found.");
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.CommandLine;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Deployment;
|
||||
@@ -16,7 +15,6 @@ internal static partial class Program
|
||||
root.AddOption(InvocationOptions.PackagePath);
|
||||
root.AddOption(InvocationOptions.FamilyName);
|
||||
root.AddOption(InvocationOptions.UpdateBehavior);
|
||||
root.AddOption(InvocationOptions.InstallWebView2);
|
||||
|
||||
root.SetHandler(Invocation.RunDeploymentAsync);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,171 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Management.Deployment;
|
||||
|
||||
namespace Snap.Hutao.Deployment;
|
||||
|
||||
internal static partial class WindowsAppSDKDependency
|
||||
{
|
||||
private const string SDKInstallerDownloadFormat = "https://aka.ms/windowsappsdk/{0}/{1}/windowsappruntimeinstall-x64.exe";
|
||||
|
||||
public static async Task EnsureAsync(string packagePath)
|
||||
{
|
||||
using FileStream packageStream = File.OpenRead(packagePath);
|
||||
using ZipArchive package = new(packageStream, ZipArchiveMode.Read);
|
||||
|
||||
(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;
|
||||
}
|
||||
|
||||
if (CheckRuntimeInstalled(packageName, msixVersion))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string sdkVersion = await ExtractSDKVersionFromDepsJsonAsync(package).ConfigureAwait(false);
|
||||
|
||||
if (string.IsNullOrEmpty(sdkVersion))
|
||||
{
|
||||
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)
|
||||
{
|
||||
ZipArchiveEntry? depsJson = package.GetEntry("Snap.Hutao.deps.json");
|
||||
ArgumentNullException.ThrowIfNull(depsJson);
|
||||
|
||||
using (StreamReader reader = new(depsJson.Open()))
|
||||
{
|
||||
while (await reader.ReadLineAsync().ConfigureAwait(false) is { } line)
|
||||
{
|
||||
if (WindowsAppSDKVersion().Match(line) is { Success: true } match)
|
||||
{
|
||||
string sdkVersion = match.Groups[1].Value;
|
||||
Console.WriteLine($"Using Windows App SDK version: {sdkVersion}");
|
||||
return sdkVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private static bool CheckRuntimeInstalled(string packageName, string msixVersion)
|
||||
{
|
||||
Version msixMinVersion = new(msixVersion);
|
||||
|
||||
foreach (Windows.ApplicationModel.Package installed in new PackageManager().FindPackages())
|
||||
{
|
||||
if (installed.Id.Name == packageName && installed.Id.Version.ToVersion() >= msixMinVersion)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static async Task DownloadWindowsAppRuntimeInstallAndInstallAsync(string version)
|
||||
{
|
||||
string sdkInstallerPath = Path.Combine(Path.GetTempPath(), "windowsappruntimeinstall-x64.exe");
|
||||
try
|
||||
{
|
||||
using (HttpClient httpClient = new())
|
||||
{
|
||||
HttpShardCopyWorkerOptions<DownloadStatus> options = new()
|
||||
{
|
||||
HttpClient = httpClient,
|
||||
SourceUrl = string.Format(SDKInstallerDownloadFormat, MajorMinorVersion().Match(version).Value, version),
|
||||
DestinationFilePath = sdkInstallerPath,
|
||||
StatusFactory = (bytesRead, totalBytes) => new DownloadStatus(bytesRead, totalBytes),
|
||||
};
|
||||
|
||||
using (HttpShardCopyWorker<DownloadStatus> worker = await HttpShardCopyWorker<DownloadStatus>.CreateAsync(options).ConfigureAwait(false))
|
||||
{
|
||||
Progress<DownloadStatus> progress = new(ConsoleWriteProgress);
|
||||
await worker.CopyAsync(progress).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Start installing SDK...");
|
||||
Process installerProcess = new()
|
||||
{
|
||||
StartInfo = new()
|
||||
{
|
||||
FileName = sdkInstallerPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
},
|
||||
};
|
||||
|
||||
using (installerProcess)
|
||||
{
|
||||
installerProcess.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
||||
installerProcess.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
|
||||
installerProcess.Start();
|
||||
Console.WriteLine("-----> WindowsAppRuntimeInstall Output begin -----");
|
||||
installerProcess.BeginOutputReadLine();
|
||||
installerProcess.BeginErrorReadLine();
|
||||
|
||||
await installerProcess.WaitForExitAsync().ConfigureAwait(false);
|
||||
Console.WriteLine("<----- WindowsAppRuntimeInstall Output end -------");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (File.Exists(sdkInstallerPath))
|
||||
{
|
||||
File.Delete(sdkInstallerPath);
|
||||
}
|
||||
}
|
||||
|
||||
static void ConsoleWriteProgress(DownloadStatus status)
|
||||
{
|
||||
Console.Write($"\r{status.ProgressDescription}");
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<(string PackageName, string MsixVersion)> ExtractRuntimePackageNameAndMsixMinVersionFromAppManifestAsync(ZipArchive package)
|
||||
{
|
||||
ZipArchiveEntry? appxManifest = package.GetEntry("AppxManifest.xml");
|
||||
ArgumentNullException.ThrowIfNull(appxManifest);
|
||||
|
||||
using (StreamReader reader = new(appxManifest.Open()))
|
||||
{
|
||||
while (await reader.ReadLineAsync().ConfigureAwait(false) is { } line)
|
||||
{
|
||||
if (WindowsAppRuntimeMsixMinVersion().Match(line) is { Success: true } match)
|
||||
{
|
||||
string packageName = match.Groups[1].Value;
|
||||
string msixVersion = match.Groups[2].Value;
|
||||
Console.WriteLine($"Using {packageName} version: {msixVersion}");
|
||||
return (packageName, msixVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
[GeneratedRegex("<PackageDependency Name=\"(Microsoft\\.WindowsAppRuntime.+?)\" MinVersion=\"(.+?)\"")]
|
||||
private static partial Regex WindowsAppRuntimeMsixMinVersion();
|
||||
|
||||
[GeneratedRegex("\"Microsoft\\.WindowsAppSDK\": \"(.+?)\",")]
|
||||
private static partial Regex WindowsAppSDKVersion();
|
||||
|
||||
[GeneratedRegex(@"\d+\.\d+")]
|
||||
private static partial Regex MajorMinorVersion();
|
||||
}
|
||||
Reference in New Issue
Block a user