diff --git a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec index caaee43..ae5718b 100644 --- a/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec +++ b/src/Snap.Hutao.Deployment.Runtime/Snap.Hutao.Deployment.Runtime.nuspec @@ -2,7 +2,7 @@ Snap.Hutao.Deployment.Runtime - 1.11.0 + 1.12.0 DGP Studio true false diff --git a/src/Snap.Hutao.Deployment/Invocation.cs b/src/Snap.Hutao.Deployment/Invocation.cs index b6c4f13..aa45c3b 100644 --- a/src/Snap.Hutao.Deployment/Invocation.cs +++ b/src/Snap.Hutao.Deployment/Invocation.cs @@ -134,7 +134,10 @@ private static async ValueTask ExitAsync(bool isUpdateMode) 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 diff --git a/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj b/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj index 21d1826..6d46698 100644 --- a/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj +++ b/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs b/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs index a3cb88c..8cc0474 100644 --- a/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs +++ b/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs @@ -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 @@ public static async Task EnsureAsync(string packagePath) return; } - if (CheckRuntimeInstalled(packageName, msixVersion)) + if (await CheckRuntimeInstalledAndVerifyAsync(packageName, msixVersion).ConfigureAwait(false)) { return; } @@ -63,19 +67,21 @@ private static async Task ExtractSDKVersionFromDepsJsonAsync(ZipArchive return string.Empty; } - private static bool CheckRuntimeInstalled(string packageName, string msixVersion) + private static async Task CheckRuntimeInstalledAndVerifyAsync(string packageName, string msixVersion) { Version msixMinVersion = new(msixVersion); + List 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 @@ private static async Task DownloadWindowsAppRuntimeInstallAndInstallAsync(string } } + 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 @@ private static async Task DownloadWindowsAppRuntimeInstallAndInstallAsync(string 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