5 Commits

Author SHA1 Message Date
DismissedLight
80584305db Update Snap.Hutao.Deployment.Runtime.nuspec 2024-01-16 21:23:02 +08:00
DismissedLight
5a830c21cf code style 2024-01-16 21:09:59 +08:00
qhy040404
ab96c9be33 更新 Snap.Hutao.Deployment.csproj 2024-01-15 23:56:48 +08:00
qhy040404
d6f15608d9 更新 WindowsAppSDKDependency.cs 2024-01-15 23:55:23 +08:00
qhy040404
6867e5e914 更新 Snap.Hutao.Deployment.csproj 2024-01-15 23:42:58 +08:00
4 changed files with 36 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>Snap.Hutao.Deployment.Runtime</id>
<version>1.11.0</version>
<version>1.12.0</version>
<authors>DGP Studio</authors>
<developmentDependency>true</developmentDependency>
<requireLicenseAcceptance>false</requireLicenseAcceptance>

View File

@@ -134,7 +134,10 @@ internal static partial class Invocation
if (!isUpdateMode)
{
Console.WriteLine("Press enter to exit...");
while (Console.ReadKey(true).Key != ConsoleKey.Enter) ;
while (Console.ReadKey(true).Key != ConsoleKey.Enter)
{
//Pending enter key
}
FreeConsole();
}
else

View File

@@ -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>

View File

@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.Management.Deployment;
@@ -25,7 +29,7 @@ internal static partial class WindowsAppSDKDependency
return;
}
if (CheckRuntimeInstalled(packageName, msixVersion))
if (await CheckRuntimeInstalledAndVerifyAsync(packageName, msixVersion).ConfigureAwait(false))
{
return;
}
@@ -63,19 +67,21 @@ internal static partial class WindowsAppSDKDependency
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);
List<bool> results = [];
foreach (Windows.ApplicationModel.Package installed in new PackageManager().FindPackages())
{
if (installed.Id.Name == packageName && installed.Id.Version.ToVersion() >= msixMinVersion)
{
return true;
results.Add(await installed.VerifyContentIntegrityAsync());
}
}
return false;
return results.Aggregate((result, element) => result || element);
}
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...");
Process installerProcess = new()
{
@@ -116,12 +139,13 @@ internal static partial class WindowsAppSDKDependency
installerProcess.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data);
installerProcess.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data);
installerProcess.Start();
Console.WriteLine("-----> WindowsAppRuntimeInstall Output begin -----");
Console.WriteLine("-----> WindowsAppRuntimeInstall Output begin");
installerProcess.BeginOutputReadLine();
installerProcess.BeginErrorReadLine();
await installerProcess.WaitForExitAsync().ConfigureAwait(false);
Console.WriteLine("<----- WindowsAppRuntimeInstall Output end -------");
Marshal.ThrowExceptionForHR(installerProcess.ExitCode);
Console.WriteLine("<----- WindowsAppRuntimeInstall Output end");
}
}
finally