From 5a830c21cf3d34be3352a5bb3d66cc6ccb2b3d29 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Tue, 16 Jan 2024 21:09:59 +0800 Subject: [PATCH] code style --- src/Snap.Hutao.Deployment/Invocation.cs | 5 ++- .../Snap.Hutao.Deployment.csproj | 2 +- .../WindowsAppSDKDependency.cs | 38 +++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) 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 @@ 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 diff --git a/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj b/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj index 89e7993..6d46698 100644 --- a/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj +++ b/src/Snap.Hutao.Deployment/Snap.Hutao.Deployment.csproj @@ -1,4 +1,4 @@ - + WinExe diff --git a/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs b/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs index cd6713a..8cc0474 100644 --- a/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs +++ b/src/Snap.Hutao.Deployment/WindowsAppSDKDependency.cs @@ -1,7 +1,9 @@ -using System; +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; @@ -69,15 +71,17 @@ internal static partial class WindowsAppSDKDependency { 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 await installed.VerifyContentIntegrityAsync(); + results.Add(await installed.VerifyContentIntegrityAsync()); } } - return false; + return results.Aggregate((result, element) => result || element); } private static async Task DownloadWindowsAppRuntimeInstallAndInstallAsync(string version) @@ -102,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() { @@ -113,25 +134,18 @@ internal static partial class WindowsAppSDKDependency }, }; - ServiceController service = new("appxsvc"); - if (service.CanStop) - { - service.Stop(); - service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(5)); - } - 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 -----"); + Console.WriteLine("-----> WindowsAppRuntimeInstall Output begin"); installerProcess.BeginOutputReadLine(); installerProcess.BeginErrorReadLine(); await installerProcess.WaitForExitAsync().ConfigureAwait(false); Marshal.ThrowExceptionForHR(installerProcess.ExitCode); - Console.WriteLine("<----- WindowsAppRuntimeInstall Output end -------"); + Console.WriteLine("<----- WindowsAppRuntimeInstall Output end"); } } finally