From 7c713cef049d6a972b2c78a8d009fefc8176251a Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:44:30 +0300 Subject: [PATCH] Use CSharpier --- .../Bootstrapper.cs | 26 ++++-- ...tnetRuntimeBootstrapper.AppHost.Cli.csproj | 1 + .../Utils/ConsoleEx.cs | 10 +- .../Utils/ConsoleProgress.cs | 2 +- .../BootstrapperBase.cs | 29 +++--- .../BootstrapperConfiguration.cs | 7 +- .../Dotnet/DotnetHost.cs | 44 ++++----- .../Dotnet/DotnetInstallation.cs | 27 +++--- .../Dotnet/DotnetRuntime.cs | 47 +++++----- ...netRuntimeBootstrapper.AppHost.Core.csproj | 1 + .../Native/IOCounters.cs | 2 +- .../Native/JobObjectBasicLimitInformation.cs | 2 +- .../JobObjectExtendedLimitInformation.cs | 2 +- .../Native/JobObjectInfoType.cs | 2 +- .../Native/NativeLibrary.cs | 21 ++--- .../Native/NativeMethods.cs | 8 +- .../Native/NativeResource.cs | 2 +- .../Native/ProcessJob.cs | 23 ++--- .../Native/SystemInfo.cs | 2 +- .../Native/SystemVersionInfo.cs | 2 +- .../Platform/OperatingSystemEx.cs | 31 ++++--- .../Platform/OperatingSystemVersion.cs | 2 +- .../Platform/ProcessorArchitecture.cs | 2 +- .../DotnetRuntimePrerequisite.cs | 93 ++++++++++--------- .../ExecutablePrerequisiteInstaller.cs | 14 ++- .../Prerequisites/IPrerequisite.cs | 2 +- .../Prerequisites/IPrerequisiteInstaller.cs | 2 +- .../PrerequisiteInstallerResult.cs | 2 +- .../Prerequisites/VisualCppPrerequisite.cs | 14 +-- .../WindowsUpdate2999226Prerequisite.cs | 60 ++++++------ .../WindowsUpdate3063858Prerequisite.cs | 36 ++++--- .../WindowsUpdatePrerequisiteInstaller.cs | 8 +- .../TargetAssembly.cs | 19 ++-- .../Utils/CommandLine.cs | 22 +++-- .../Utils/Disposable.cs | 5 +- .../Utils/EnvironmentEx.cs | 6 +- .../Utils/Extensions/AssemblyExtensions.cs | 8 +- .../Utils/Extensions/CollectionExtensions.cs | 2 +- .../Utils/Extensions/GenericExtensions.cs | 5 +- .../Utils/Extensions/RegistryExtensions.cs | 2 +- .../Utils/Extensions/StringExtensions.cs | 6 +- .../Utils/FileEx.cs | 2 +- .../Utils/Http.cs | 35 ++++--- .../Utils/IconEx.cs | 2 +- .../Utils/PathEx.cs | 2 +- .../Utils/RandomEx.cs | 2 +- .../Utils/Url.cs | 9 +- .../Utils/VersionEx.cs | 6 +- .../Bootstrapper.cs | 8 +- ...tnetRuntimeBootstrapper.AppHost.Gui.csproj | 1 + .../InstallForm.cs | 83 +++++++++-------- .../PromptForm.cs | 6 +- .../Utils/ApplicationEx.cs | 2 +- .../DotnetRuntimeBootstrapper.Demo.Cli.csproj | 4 + DotnetRuntimeBootstrapper.Demo.Cli/Program.cs | 2 +- .../DotnetRuntimeBootstrapper.Demo.Gui.csproj | 4 + .../MainForm.cs | 2 +- DotnetRuntimeBootstrapper.Demo.Gui/Program.cs | 2 +- DotnetRuntimeBootstrapper/BootstrapperTask.cs | 67 +++++++------ .../DotnetRuntimeBootstrapper.csproj | 1 + .../Utils/Extensions/AssemblyExtensions.cs | 14 ++- .../Utils/Extensions/CollectionExtensions.cs | 2 +- 62 files changed, 467 insertions(+), 390 deletions(-) diff --git a/DotnetRuntimeBootstrapper.AppHost.Cli/Bootstrapper.cs b/DotnetRuntimeBootstrapper.AppHost.Cli/Bootstrapper.cs index 65ac5ca..6c0c3d2 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Cli/Bootstrapper.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Cli/Bootstrapper.cs @@ -28,11 +28,14 @@ protected override void ReportError(string message) protected override bool Prompt( TargetAssembly targetAssembly, - IPrerequisite[] missingPrerequisites) + IPrerequisite[] missingPrerequisites + ) { using (ConsoleEx.WithForegroundColor(ConsoleColor.DarkRed)) { - Console.Error.WriteLine($"Your system is missing runtime components required by {targetAssembly.Name}:"); + Console.Error.WriteLine( + $"Your system is missing runtime components required by {targetAssembly.Name}:" + ); foreach (var prerequisite in missingPrerequisites) Console.Error.WriteLine($" - {prerequisite.DisplayName}"); @@ -54,7 +57,9 @@ protected override void ReportError(string message) // When not running in interactive mode, instruct the user to set the environment variable instead else { - Console.Error.Write("To install the missing components automatically, set the environment variable "); + Console.Error.Write( + "To install the missing components automatically, set the environment variable " + ); using (ConsoleEx.WithForegroundColor(ConsoleColor.DarkCyan)) Console.Error.Write(AcceptPromptEnvironmentVariable); @@ -85,7 +90,8 @@ protected override void ReportError(string message) protected override bool Install( TargetAssembly targetAssembly, - IPrerequisite[] missingPrerequisites) + IPrerequisite[] missingPrerequisites + ) { using (ConsoleEx.WithForegroundColor(ConsoleColor.White)) Console.Out.WriteLine($"{targetAssembly.Name}: installing prerequisites"); @@ -101,7 +107,11 @@ protected override void ReportError(string message) Console.Out.Write($"Downloading {prerequisite.DisplayName}... "); // Only write progress if running in interactive mode - using (var progress = new ConsoleProgress(ConsoleEx.IsInteractive ? Console.Out : TextWriter.Null)) + using ( + var progress = new ConsoleProgress( + ConsoleEx.IsInteractive ? Console.Out : TextWriter.Null + ) + ) { var installer = prerequisite.DownloadInstaller(progress.Report); installers.Add(installer); @@ -141,7 +151,9 @@ protected override void ReportError(string message) if (isRebootRequired) { using (ConsoleEx.WithForegroundColor(ConsoleColor.DarkYellow)) - Console.Out.WriteLine($"You need to restart Windows before you can run {targetAssembly.Name}."); + Console.Out.WriteLine( + $"You need to restart Windows before you can run {targetAssembly.Name}." + ); // Only prompt for reboot if running in interactive mode if (ConsoleEx.IsInteractive) @@ -163,4 +175,4 @@ protected override void ReportError(string message) } public static int Main(string[] args) => new Bootstrapper().Run(args); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Cli/DotnetRuntimeBootstrapper.AppHost.Cli.csproj b/DotnetRuntimeBootstrapper.AppHost.Cli/DotnetRuntimeBootstrapper.AppHost.Cli.csproj index 5354086..e2a83c3 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Cli/DotnetRuntimeBootstrapper.AppHost.Cli.csproj +++ b/DotnetRuntimeBootstrapper.AppHost.Cli/DotnetRuntimeBootstrapper.AppHost.Cli.csproj @@ -12,6 +12,7 @@ + diff --git a/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleEx.cs b/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleEx.cs index cacc9ba..ac3266b 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleEx.cs @@ -7,10 +7,10 @@ namespace DotnetRuntimeBootstrapper.AppHost.Cli.Utils; internal static class ConsoleEx { public static bool IsInteractive => - NativeMethods.GetConsoleWindow() != 0 && - NativeMethods.GetFileType(NativeMethods.GetStdHandle(-10)) == 2 && - NativeMethods.GetFileType(NativeMethods.GetStdHandle(-11)) == 2 && - NativeMethods.GetFileType(NativeMethods.GetStdHandle(-12)) == 2; + NativeMethods.GetConsoleWindow() != 0 + && NativeMethods.GetFileType(NativeMethods.GetStdHandle(-10)) == 2 + && NativeMethods.GetFileType(NativeMethods.GetStdHandle(-11)) == 2 + && NativeMethods.GetFileType(NativeMethods.GetStdHandle(-12)) == 2; public static IDisposable WithForegroundColor(ConsoleColor color) { @@ -18,4 +18,4 @@ public static IDisposable WithForegroundColor(ConsoleColor color) Console.ForegroundColor = color; return Disposable.Create(() => Console.ForegroundColor = lastColor); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleProgress.cs b/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleProgress.cs index cf0b071..e501f67 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleProgress.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Cli/Utils/ConsoleProgress.cs @@ -36,4 +36,4 @@ private void Write(string text) public void Report(double progress) => Write($"{progress:P1}"); public void Dispose() => EraseLast(); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperBase.cs b/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperBase.cs index 6648e36..6a3f501 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperBase.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperBase.cs @@ -13,7 +13,8 @@ public abstract class BootstrapperBase protected const string LegacyAcceptPromptEnvironmentVariable = "DOTNET_INSTALL_PREREQUISITES"; protected const string AcceptPromptEnvironmentVariable = "DOTNET_ENABLE_BOOTSTRAPPER"; - protected BootstrapperConfiguration Configuration { get; } = BootstrapperConfiguration.Resolve(); + protected BootstrapperConfiguration Configuration { get; } = + BootstrapperConfiguration.Resolve(); protected virtual void ReportError(string message) { @@ -25,8 +26,7 @@ protected virtual void ReportError(string message) var applicationName = Path.GetFileName(applicationFilePath); var bootstrapperVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); - var content = - $""" + var content = $""" Description: Bootstrapper for a .NET application has failed. Application: {applicationName} Path: {applicationFilePath} @@ -54,31 +54,26 @@ IPrerequisite[] missingPrerequisites private bool PromptAndInstall( TargetAssembly targetAssembly, - IPrerequisite[] missingPrerequisites) + IPrerequisite[] missingPrerequisites + ) { // Install prompt can be disabled in bootstrap configuration or via environment variable var isPromptPreAccepted = !Configuration.IsPromptRequired - || - string.Equals( + || string.Equals( Environment.GetEnvironmentVariable(AcceptPromptEnvironmentVariable), "true", StringComparison.OrdinalIgnoreCase ) - || - string.Equals( + || string.Equals( Environment.GetEnvironmentVariable(LegacyAcceptPromptEnvironmentVariable), "true", StringComparison.OrdinalIgnoreCase ); - var isPromptAccepted = - isPromptPreAccepted || - Prompt(targetAssembly, missingPrerequisites); + var isPromptAccepted = isPromptPreAccepted || Prompt(targetAssembly, missingPrerequisites); - return - isPromptAccepted && - Install(targetAssembly, missingPrerequisites); + return isPromptAccepted && Install(targetAssembly, missingPrerequisites); } private int Run(TargetAssembly targetAssembly, string[] args) @@ -126,8 +121,8 @@ public int Run(string[] args) { var targetAssembly = TargetAssembly.Resolve( Path.Combine( - Path.GetDirectoryName(EnvironmentEx.ProcessPath) ?? - AppDomain.CurrentDomain.BaseDirectory, + Path.GetDirectoryName(EnvironmentEx.ProcessPath) + ?? AppDomain.CurrentDomain.BaseDirectory, Configuration.TargetFileName ) ); @@ -140,4 +135,4 @@ public int Run(string[] args) return 0xDEAD; } } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperConfiguration.cs b/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperConfiguration.cs index 71bbedd..fccc968 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperConfiguration.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/BootstrapperConfiguration.cs @@ -16,7 +16,9 @@ public partial class BootstrapperConfiguration { public static BootstrapperConfiguration Resolve() { - var data = Assembly.GetExecutingAssembly().GetManifestResourceString(nameof(BootstrapperConfiguration)); + var data = Assembly + .GetExecutingAssembly() + .GetManifestResourceString(nameof(BootstrapperConfiguration)); var parsed = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var line in data.Split('\n')) @@ -34,7 +36,6 @@ public static BootstrapperConfiguration Resolve() return new BootstrapperConfiguration { TargetFileName = parsed[nameof(TargetFileName)], - IsPromptRequired = string.Equals( parsed[nameof(IsPromptRequired)], "true", @@ -42,4 +43,4 @@ public static BootstrapperConfiguration Resolve() ) }; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetHost.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetHost.cs index 413e5ca..7a48411 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetHost.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetHost.cs @@ -42,19 +42,19 @@ internal partial class DotnetHost : IDisposable ); private InitializeForCommandLineFn GetInitializeForCommandLineFn() => - _hostResolverLibrary.GetFunction("hostfxr_initialize_for_dotnet_command_line"); + _hostResolverLibrary.GetFunction( + "hostfxr_initialize_for_dotnet_command_line" + ); [UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)] private delegate int RunAppFn(nint handle); - private RunAppFn GetRunAppFn() => - _hostResolverLibrary.GetFunction("hostfxr_run_app"); + private RunAppFn GetRunAppFn() => _hostResolverLibrary.GetFunction("hostfxr_run_app"); [UnmanagedFunctionPointer(CallingConvention.Cdecl, SetLastError = true)] private delegate int CloseFn(nint handle); - private CloseFn GetCloseFn() => - _hostResolverLibrary.GetFunction("hostfxr_close"); + private CloseFn GetCloseFn() => _hostResolverLibrary.GetFunction("hostfxr_close"); private nint Initialize(string targetFilePath, string[] args) { @@ -72,9 +72,8 @@ private nint Initialize(string targetFilePath, string[] args) if (status != 0) { - var error = errorBuffer.Length > 0 - ? errorBuffer.ToString() - : "No error messages reported."; + var error = + errorBuffer.Length > 0 ? errorBuffer.ToString() : "No error messages reported."; throw new ApplicationException( $""" @@ -102,10 +101,10 @@ private int Run(nint handle) // Unfortunately, there is no way to get the original exception or its message. // https://github.com/Tyrrrz/DotnetRuntimeBootstrapper/issues/23 throw new ApplicationException( - "Application crashed with an unhandled exception. " + - "Unfortunately, it was not possible to retrieve the exception message or its stacktrace. " + - "Please check the Windows Event Viewer to see if the runtime logged any additional information. " + - "If you are the developer of the application, consider adding a global exception handler to provide a more detailed error message to the user.", + "Application crashed with an unhandled exception. " + + "Unfortunately, it was not possible to retrieve the exception message or its stacktrace. " + + "Please check the Windows Event Viewer to see if the runtime logged any additional information. " + + "If you are the developer of the application, consider adding a global exception handler to provide a more detailed error message to the user.", ex ); } @@ -146,9 +145,15 @@ private static string GetHostResolverFilePath() // 1. Find the hostfxr directory containing versioned subdirectories // 2. Get the hostfxr.dll from the subdirectory with the highest version number - var hostResolverRootDirPath = PathEx.Combine(DotnetInstallation.GetDirectoryPath(), "host", "fxr"); + var hostResolverRootDirPath = PathEx.Combine( + DotnetInstallation.GetDirectoryPath(), + "host", + "fxr" + ); if (!Directory.Exists(hostResolverRootDirPath)) - throw new DirectoryNotFoundException("Could not find directory containing hostfxr.dll."); + throw new DirectoryNotFoundException( + "Could not find directory containing hostfxr.dll." + ); var hostResolverFilePath = ( from dirPath in Directory.GetDirectories(hostResolverRootDirPath) @@ -160,12 +165,9 @@ where File.Exists(filePath) select filePath ).FirstOrDefault(); - return - hostResolverFilePath ?? - throw new FileNotFoundException("Could not find hostfxr.dll."); + return hostResolverFilePath + ?? throw new FileNotFoundException("Could not find hostfxr.dll."); } - public static DotnetHost Load() => new( - NativeLibrary.Load(GetHostResolverFilePath()) - ); -} \ No newline at end of file + public static DotnetHost Load() => new(NativeLibrary.Load(GetHostResolverFilePath())); +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetInstallation.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetInstallation.cs index 851c6dd..0faeec5 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetInstallation.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetInstallation.cs @@ -10,11 +10,13 @@ internal static class DotnetInstallation private static string? TryGetDirectoryPathFromRegistry() { var dotnetRegistryKey = Registry.LocalMachine.OpenSubKey( - (OperatingSystemEx.ProcessorArchitecture.Is64Bit() - ? "SOFTWARE\\Wow6432Node\\" - : "SOFTWARE\\") + - "dotnet\\Setup\\InstalledVersions\\" + - OperatingSystemEx.ProcessorArchitecture.GetMoniker(), + ( + OperatingSystemEx.ProcessorArchitecture.Is64Bit() + ? "SOFTWARE\\Wow6432Node\\" + : "SOFTWARE\\" + ) + + "dotnet\\Setup\\InstalledVersions\\" + + OperatingSystemEx.ProcessorArchitecture.GetMoniker(), false ); @@ -31,9 +33,9 @@ internal static class DotnetInstallation // if the apphost is running in x86 mode on an x64 system, so we rely // on an environment variable instead. var programFilesDirPath = - Environment.GetEnvironmentVariable("PROGRAMFILES") ?? - Environment.GetEnvironmentVariable("ProgramW6432") ?? - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); + Environment.GetEnvironmentVariable("PROGRAMFILES") + ?? Environment.GetEnvironmentVariable("ProgramW6432") + ?? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); var dotnetDirPath = Path.Combine(programFilesDirPath, "dotnet"); @@ -46,8 +48,9 @@ internal static class DotnetInstallation // https://github.com/dotnet/designs/blob/main/accepted/2020/install-locations.md public static string GetDirectoryPath() => // Try to resolve location from registry (covers both custom and default locations) - TryGetDirectoryPathFromRegistry() ?? + TryGetDirectoryPathFromRegistry() + ?? // Try to resolve location from program files (default location) - TryGetDirectoryPathFromEnvironment() ?? - throw new DirectoryNotFoundException("Could not find .NET installation directory."); -} \ No newline at end of file + TryGetDirectoryPathFromEnvironment() + ?? throw new DirectoryNotFoundException("Could not find .NET installation directory."); +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetRuntime.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetRuntime.cs index 6255140..21e9b83 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetRuntime.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Dotnet/DotnetRuntime.cs @@ -29,9 +29,9 @@ public DotnetRuntime(string name, Version version) } public bool IsSupersededBy(DotnetRuntime other) => - string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) && - Version.Major == other.Version.Major && - Version <= other.Version; + string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) + && Version.Major == other.Version.Major + && Version <= other.Version; } internal partial class DotnetRuntime @@ -40,7 +40,9 @@ public static DotnetRuntime[] GetAllInstalled() { var sharedDirPath = Path.Combine(DotnetInstallation.GetDirectoryPath(), "shared"); if (!Directory.Exists(sharedDirPath)) - throw new DirectoryNotFoundException("Could not find directory containing .NET runtime binaries."); + throw new DirectoryNotFoundException( + "Could not find directory containing .NET runtime binaries." + ); return ( from runtimeDirPath in Directory.GetDirectories(sharedDirPath) @@ -61,30 +63,33 @@ static DotnetRuntime ParseRuntime(JsonNode json) return !string.IsNullOrEmpty(name) && version is not null ? new DotnetRuntime(name, version) - : throw new ApplicationException("Could not parse runtime info from runtime config."); + : throw new ApplicationException( + "Could not parse runtime info from runtime config." + ); } var json = - Json.TryParse(File.ReadAllText(runtimeConfigFilePath)) ?? - throw new ApplicationException($"Failed to parse runtime config '{runtimeConfigFilePath}'."); + Json.TryParse(File.ReadAllText(runtimeConfigFilePath)) + ?? throw new ApplicationException( + $"Failed to parse runtime config '{runtimeConfigFilePath}'." + ); return // Multiple targets - json - .TryGetChild("runtimeOptions")? - .TryGetChild("frameworks")? - .EnumerateChildren() + json.TryGetChild("runtimeOptions") + ?.TryGetChild("frameworks") + ?.EnumerateChildren() .Select(ParseRuntime) - .ToArray() ?? - + .ToArray() + ?? // Single target - json - .TryGetChild("runtimeOptions")? - .TryGetChild("framework")? - .ToSingletonEnumerable() + json.TryGetChild("runtimeOptions") + ?.TryGetChild("framework") + ?.ToSingletonEnumerable() .Select(ParseRuntime) - .ToArray() ?? - - throw new ApplicationException("Could not resolve target runtime from runtime config."); + .ToArray() + ?? throw new ApplicationException( + "Could not resolve target runtime from runtime config." + ); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/DotnetRuntimeBootstrapper.AppHost.Core.csproj b/DotnetRuntimeBootstrapper.AppHost.Core/DotnetRuntimeBootstrapper.AppHost.Core.csproj index 18f6174..b9425c8 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/DotnetRuntimeBootstrapper.AppHost.Core.csproj +++ b/DotnetRuntimeBootstrapper.AppHost.Core/DotnetRuntimeBootstrapper.AppHost.Core.csproj @@ -5,6 +5,7 @@ + diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/IOCounters.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/IOCounters.cs index 587b100..65f0bff 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/IOCounters.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/IOCounters.cs @@ -12,4 +12,4 @@ internal struct IOCounters public ulong ReadTransferCount; public ulong WriteTransferCount; public ulong OtherTransferCount; -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectBasicLimitInformation.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectBasicLimitInformation.cs index a699b42..d74563f 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectBasicLimitInformation.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectBasicLimitInformation.cs @@ -14,4 +14,4 @@ internal struct JobObjectBasicLimitInformation public nint Affinity; public uint PriorityClass; public uint SchedulingClass; -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectExtendedLimitInformation.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectExtendedLimitInformation.cs index b60b9ef..c3af5c7 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectExtendedLimitInformation.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectExtendedLimitInformation.cs @@ -11,4 +11,4 @@ internal struct JobObjectExtendedLimitInformation public nint JobMemoryLimit; public nint PeakProcessMemoryUsed; public nint PeakJobMemoryUsed; -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectInfoType.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectInfoType.cs index 4a8787f..066d316 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectInfoType.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/JobObjectInfoType.cs @@ -10,4 +10,4 @@ internal enum JobObjectInfoType ExtendedLimitInformation = 9, SecurityLimitInformation = 5, GroupInformation = 11 -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeLibrary.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeLibrary.cs index c17adec..e8d6187 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeLibrary.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeLibrary.cs @@ -10,13 +10,15 @@ internal partial class NativeLibrary : NativeResource private readonly Dictionary _functionsByName = new(StringComparer.Ordinal); public NativeLibrary(nint handle) - : base(handle) - { - } + : base(handle) { } - public TDelegate GetFunction(string functionName) where TDelegate : Delegate + public TDelegate GetFunction(string functionName) + where TDelegate : Delegate { - if (_functionsByName.TryGetValue(functionName, out var cached) && cached is TDelegate cachedCasted) + if ( + _functionsByName.TryGetValue(functionName, out var cached) + && cached is TDelegate cachedCasted + ) return cachedCasted; var address = NativeMethods.GetProcAddress(Handle, functionName); @@ -29,8 +31,7 @@ public NativeLibrary(nint handle) return function; } - protected override void Dispose(bool disposing) => - NativeMethods.FreeLibrary(Handle); + protected override void Dispose(bool disposing) => NativeMethods.FreeLibrary(Handle); } internal partial class NativeLibrary @@ -38,8 +39,6 @@ internal partial class NativeLibrary public static NativeLibrary Load(string filePath) { var handle = NativeMethods.LoadLibrary(filePath); - return handle != 0 - ? new NativeLibrary(handle) - : throw new Win32Exception(); + return handle != 0 ? new NativeLibrary(handle) : throw new Win32Exception(); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeMethods.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeMethods.cs index ef4743b..8ab4068 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeMethods.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeMethods.cs @@ -52,5 +52,9 @@ uint cbJobObjectInfoLength public static extern int GetFileType(nint hFile); [DllImport(Shell32, CharSet = CharSet.Auto, SetLastError = true)] - public static extern nint ExtractAssociatedIcon(nint hInst, string lpIconPath, out ushort lpiIcon); -} \ No newline at end of file + public static extern nint ExtractAssociatedIcon( + nint hInst, + string lpIconPath, + out ushort lpiIcon + ); +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeResource.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeResource.cs index 574d617..4451605 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeResource.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/NativeResource.cs @@ -17,4 +17,4 @@ public void Dispose() Dispose(true); GC.SuppressFinalize(this); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/ProcessJob.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/ProcessJob.cs index 8b6b7b0..73d7959 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/ProcessJob.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/ProcessJob.cs @@ -7,9 +7,7 @@ namespace DotnetRuntimeBootstrapper.AppHost.Core.Native; internal partial class ProcessJob : NativeResource { public ProcessJob(nint handle) - : base(handle) - { - } + : base(handle) { } public void Configure(JobObjectExtendedLimitInformation limitInfo) { @@ -20,11 +18,14 @@ public void Configure(JobObjectExtendedLimitInformation limitInfo) { Marshal.StructureToPtr(limitInfo, limitInfoHandle, false); - if (!NativeMethods.SetInformationJobObject( + if ( + !NativeMethods.SetInformationJobObject( Handle, JobObjectInfoType.ExtendedLimitInformation, limitInfoHandle, - (uint) limitInfoSize)) + (uint)limitInfoSize + ) + ) { throw new Win32Exception(); } @@ -38,11 +39,9 @@ public void Configure(JobObjectExtendedLimitInformation limitInfo) public void AddProcess(nint processHandle) => NativeMethods.AssignProcessToJobObject(Handle, processHandle); - public void AddProcess(Process process) => - AddProcess(process.Handle); + public void AddProcess(Process process) => AddProcess(process.Handle); - protected override void Dispose(bool disposing) => - NativeMethods.CloseHandle(Handle); + protected override void Dispose(bool disposing) => NativeMethods.CloseHandle(Handle); } internal partial class ProcessJob @@ -50,8 +49,6 @@ internal partial class ProcessJob public static ProcessJob Create() { var handle = NativeMethods.CreateJobObject(0, null); - return handle != 0 - ? new ProcessJob(handle) - : throw new Win32Exception(); + return handle != 0 ? new ProcessJob(handle) : throw new Win32Exception(); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemInfo.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemInfo.cs index 0792f20..ae46806 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemInfo.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemInfo.cs @@ -29,4 +29,4 @@ private static SystemInfo Resolve() return systemInfo; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemVersionInfo.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemVersionInfo.cs index 5c74065..5f72a06 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemVersionInfo.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Native/SystemVersionInfo.cs @@ -32,4 +32,4 @@ private static SystemVersionInfo Resolve() return systemVersionInfo; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemEx.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemEx.cs index ba8873a..bf5486d 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemEx.cs @@ -9,23 +9,24 @@ namespace DotnetRuntimeBootstrapper.AppHost.Core.Platform; // The 'Ex' suffix here is just to disambiguate from the existing 'OperatingSystem' type in the BCL internal static class OperatingSystemEx { - public static Version Version { get; } = new( - SystemVersionInfo.Instance.MajorVersion, - SystemVersionInfo.Instance.MinorVersion - ); + public static Version Version { get; } = + new(SystemVersionInfo.Instance.MajorVersion, SystemVersionInfo.Instance.MinorVersion); - public static ProcessorArchitecture ProcessorArchitecture => SystemInfo.Instance.ProcessorArchitecture switch - { - 0 => ProcessorArchitecture.X86, - 9 => ProcessorArchitecture.X64, - 5 => ProcessorArchitecture.Arm, - 12 => ProcessorArchitecture.Arm64, - _ => throw new InvalidOperationException("Unknown processor architecture.") - }; + public static ProcessorArchitecture ProcessorArchitecture => + SystemInfo.Instance.ProcessorArchitecture switch + { + 0 => ProcessorArchitecture.X86, + 9 => ProcessorArchitecture.X64, + 5 => ProcessorArchitecture.Arm, + 12 => ProcessorArchitecture.Arm64, + _ => throw new InvalidOperationException("Unknown processor architecture.") + }; public static IEnumerable GetInstalledUpdates() { - using var search = new ManagementObjectSearcher("SELECT HotFixID FROM Win32_QuickFixEngineering"); + using var search = new ManagementObjectSearcher( + "SELECT HotFixID FROM Win32_QuickFixEngineering" + ); using var results = search.Get(); foreach (var result in results) @@ -36,5 +37,5 @@ public static IEnumerable GetInstalledUpdates() } } - public static void Reboot() => CommandLine.Run("shutdown", new[] {"/r", "/t", "0"}); -} \ No newline at end of file + public static void Reboot() => CommandLine.Run("shutdown", new[] { "/r", "/t", "0" }); +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemVersion.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemVersion.cs index 3e12576..272bcf6 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemVersion.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Platform/OperatingSystemVersion.cs @@ -12,4 +12,4 @@ internal static class OperatingSystemVersion public static Version Windows8_1 { get; } = new(6, 3); public static Version Windows10 { get; } = new(10, 0); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Platform/ProcessorArchitecture.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Platform/ProcessorArchitecture.cs index 5e1964b..3beeea1 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Platform/ProcessorArchitecture.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Platform/ProcessorArchitecture.cs @@ -15,4 +15,4 @@ internal static class ProcessorArchitectureExtensions public static string GetMoniker(this ProcessorArchitecture arch) => arch.ToString().ToLowerInvariant(); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/DotnetRuntimePrerequisite.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/DotnetRuntimePrerequisite.cs index e13d760..b21d9aa 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/DotnetRuntimePrerequisite.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/DotnetRuntimePrerequisite.cs @@ -13,13 +13,14 @@ internal class DotnetRuntimePrerequisite : IPrerequisite { private readonly DotnetRuntime _runtime; - private string ShortName => _runtime switch - { - { IsWindowsDesktop: true } => "Desktop", - { IsAspNet: true } => "ASP.NET", - { IsBase: true } => "Base", - _ => _runtime.Name - }; + private string ShortName => + _runtime switch + { + { IsWindowsDesktop: true } => "Desktop", + { IsAspNet: true } => "ASP.NET", + { IsBase: true } => "Base", + _ => _runtime.Name + }; public string DisplayName => $".NET Runtime ({ShortName}) v{_runtime.Version}"; @@ -43,59 +44,63 @@ public bool IsInstalled() private string GetInstallerDownloadUrl() { var manifest = Http.GetContentString( - "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/" + - $"{_runtime.Version.ToString(2)}/releases.json" + "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/" + + $"{_runtime.Version.ToString(2)}/releases.json" ); // Find the installer download URL applicable for the current system - return - Json - // Find the list of files for the latest release - .TryParse(manifest)? - .TryGetChild("releases")? - .TryGetChild(0)? - .TryGetChild(_runtime switch - { - { IsWindowsDesktop: true } => "windowsdesktop", - { IsAspNet: true } => "aspnetcore-runtime", - _ => "runtime" - })? - .TryGetChild("files")? - .EnumerateChildren() + return Json + // Find the list of files for the latest release + .TryParse(manifest) + ?.TryGetChild("releases") + ?.TryGetChild(0) + ?.TryGetChild( + _runtime switch + { + { IsWindowsDesktop: true } => "windowsdesktop", + { IsAspNet: true } => "aspnetcore-runtime", + _ => "runtime" + } + ) + ?.TryGetChild("files") + ?.EnumerateChildren() // Filter by processor architecture - .Where(f => - string.Equals( - f.TryGetChild("rid")?.TryGetString(), - "win-" + OperatingSystemEx.ProcessorArchitecture.GetMoniker(), - StringComparison.OrdinalIgnoreCase - ) + .Where( + f => + string.Equals( + f.TryGetChild("rid")?.TryGetString(), + "win-" + OperatingSystemEx.ProcessorArchitecture.GetMoniker(), + StringComparison.OrdinalIgnoreCase + ) ) // Filter by file type - .Where(f => - string.Equals( - f.TryGetChild("name")?.TryGetString()?.Pipe(Path.GetExtension), - ".exe", - StringComparison.OrdinalIgnoreCase - ) + .Where( + f => + string.Equals( + f.TryGetChild("name")?.TryGetString()?.Pipe(Path.GetExtension), + ".exe", + StringComparison.OrdinalIgnoreCase + ) ) .Select(f => f.TryGetChild("url")?.TryGetString()) - .FirstOrDefault() ?? - - throw new ApplicationException( - "Failed to resolve download URL for the required .NET runtime. " + - $"Please try to download ${DisplayName} manually " + - $"from https://dotnet.microsoft.com/download/dotnet/{_runtime.Version.ToString(2)} or " + - "from https://get.dot.net." + .FirstOrDefault() + ?? throw new ApplicationException( + "Failed to resolve download URL for the required .NET runtime. " + + $"Please try to download ${DisplayName} manually " + + $"from https://dotnet.microsoft.com/download/dotnet/{_runtime.Version.ToString(2)} or " + + "from https://get.dot.net." ); } public IPrerequisiteInstaller DownloadInstaller(Action? handleProgress) { var downloadUrl = GetInstallerDownloadUrl(); - var filePath = FileEx.GenerateTempFilePath(Url.TryExtractFileName(downloadUrl) ?? "installer.exe"); + var filePath = FileEx.GenerateTempFilePath( + Url.TryExtractFileName(downloadUrl) ?? "installer.exe" + ); Http.DownloadFile(downloadUrl, filePath, handleProgress); return new ExecutablePrerequisiteInstaller(this, filePath); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/ExecutablePrerequisiteInstaller.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/ExecutablePrerequisiteInstaller.cs index 767b5d9..1845256 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/ExecutablePrerequisiteInstaller.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/ExecutablePrerequisiteInstaller.cs @@ -17,7 +17,11 @@ public ExecutablePrerequisiteInstaller(IPrerequisite prerequisite, string filePa public PrerequisiteInstallerResult Run() { - var exitCode = CommandLine.Run(FilePath, new[] { "/install", "/quiet", "/norestart" }, true); + var exitCode = CommandLine.Run( + FilePath, + new[] { "/install", "/quiet", "/norestart" }, + true + ); // https://github.com/Tyrrrz/DotnetRuntimeBootstrapper/issues/24#issuecomment-1021447102 if (exitCode is 3010 or 3011 or 1641) @@ -26,12 +30,12 @@ public PrerequisiteInstallerResult Run() if (exitCode != 0) { throw new ApplicationException( - $"Failed to install {Prerequisite.DisplayName}. " + - $"Exit code: {exitCode}. " + - "Please try to install this component manually." + $"Failed to install {Prerequisite.DisplayName}. " + + $"Exit code: {exitCode}. " + + "Please try to install this component manually." ); } return PrerequisiteInstallerResult.Success; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisite.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisite.cs index bc3bcd3..104b5d5 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisite.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisite.cs @@ -9,4 +9,4 @@ public interface IPrerequisite bool IsInstalled(); IPrerequisiteInstaller DownloadInstaller(Action? handleProgress); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisiteInstaller.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisiteInstaller.cs index 4c427fd..e51cf99 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisiteInstaller.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/IPrerequisiteInstaller.cs @@ -7,4 +7,4 @@ public interface IPrerequisiteInstaller string FilePath { get; } PrerequisiteInstallerResult Run(); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/PrerequisiteInstallerResult.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/PrerequisiteInstallerResult.cs index d32b622..b8005ba 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/PrerequisiteInstallerResult.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/PrerequisiteInstallerResult.cs @@ -4,4 +4,4 @@ public enum PrerequisiteInstallerResult { Success, RebootRequired -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/VisualCppPrerequisite.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/VisualCppPrerequisite.cs index 06e71c4..690552b 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/VisualCppPrerequisite.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/VisualCppPrerequisite.cs @@ -12,11 +12,13 @@ internal class VisualCppPrerequisite : IPrerequisite public bool IsInstalled() => Registry.LocalMachine.ContainsSubKey( - (OperatingSystemEx.ProcessorArchitecture.Is64Bit() - ? "SOFTWARE\\Wow6432Node\\" - : "SOFTWARE\\") + - "Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\" + - OperatingSystemEx.ProcessorArchitecture.GetMoniker() + ( + OperatingSystemEx.ProcessorArchitecture.Is64Bit() + ? "SOFTWARE\\Wow6432Node\\" + : "SOFTWARE\\" + ) + + "Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\" + + OperatingSystemEx.ProcessorArchitecture.GetMoniker() ); public IPrerequisiteInstaller DownloadInstaller(Action? handleProgress) @@ -28,4 +30,4 @@ public IPrerequisiteInstaller DownloadInstaller(Action? handleProgress) return new ExecutablePrerequisiteInstaller(this, filePath); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate2999226Prerequisite.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate2999226Prerequisite.cs index f23bc0e..e4c3cc1 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate2999226Prerequisite.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate2999226Prerequisite.cs @@ -13,51 +13,57 @@ internal class WindowsUpdate2999226Prerequisite : IPrerequisite public string DisplayName => $"Windows Update {Id}"; public bool IsInstalled() => - OperatingSystemEx.Version >= OperatingSystemVersion.Windows10 || - OperatingSystemEx.GetInstalledUpdates().Contains(Id, StringComparer.OrdinalIgnoreCase); + OperatingSystemEx.Version >= OperatingSystemVersion.Windows10 + || OperatingSystemEx.GetInstalledUpdates().Contains(Id, StringComparer.OrdinalIgnoreCase); private string GetInstallerDownloadUrl() { - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows7 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows7 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64 + ) { - return - "https://download.microsoft.com/download/1/1/5/11565A9A-EA09-4F0A-A57E-520D5D138140/Windows6.1-KB2999226-x64.msu"; + return "https://download.microsoft.com/download/1/1/5/11565A9A-EA09-4F0A-A57E-520D5D138140/Windows6.1-KB2999226-x64.msu"; } - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows7 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows7 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86 + ) { - return - "https://download.microsoft.com/download/4/F/E/4FE73868-5EDD-4B47-8B33-CE1BB7B2B16A/Windows6.1-KB2999226-x86.msu"; + return "https://download.microsoft.com/download/4/F/E/4FE73868-5EDD-4B47-8B33-CE1BB7B2B16A/Windows6.1-KB2999226-x86.msu"; } - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows8 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows8 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64 + ) { - return - "https://download.microsoft.com/download/A/C/1/AC15393F-A6E6-469B-B222-C44B3BB6ECCC/Windows8-RT-KB2999226-x64.msu"; + return "https://download.microsoft.com/download/A/C/1/AC15393F-A6E6-469B-B222-C44B3BB6ECCC/Windows8-RT-KB2999226-x64.msu"; } - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows8 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows8 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86 + ) { - return - "https://download.microsoft.com/download/1/E/8/1E8AFE90-5217-464D-9292-7D0B95A56CE4/Windows8-RT-KB2999226-x86.msu"; + return "https://download.microsoft.com/download/1/E/8/1E8AFE90-5217-464D-9292-7D0B95A56CE4/Windows8-RT-KB2999226-x86.msu"; } - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows8_1 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows8_1 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64 + ) { - return - "https://download.microsoft.com/download/9/6/F/96FD0525-3DDF-423D-8845-5F92F4A6883E/Windows8.1-KB2999226-x64.msu"; + return "https://download.microsoft.com/download/9/6/F/96FD0525-3DDF-423D-8845-5F92F4A6883E/Windows8.1-KB2999226-x64.msu"; } - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows8_1 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows8_1 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86 + ) { - return - "https://download.microsoft.com/download/E/4/6/E4694323-8290-4A08-82DB-81F2EB9452C2/Windows8.1-KB2999226-x86.msu"; + return "https://download.microsoft.com/download/E/4/6/E4694323-8290-4A08-82DB-81F2EB9452C2/Windows8.1-KB2999226-x86.msu"; } throw new ApplicationException("Unsupported operating system version."); @@ -71,4 +77,4 @@ public IPrerequisiteInstaller DownloadInstaller(Action? handleProgress) return new WindowsUpdatePrerequisiteInstaller(this, filePath); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate3063858Prerequisite.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate3063858Prerequisite.cs index 8a7857c..2628b62 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate3063858Prerequisite.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdate3063858Prerequisite.cs @@ -13,27 +13,33 @@ internal class WindowsUpdate3063858Prerequisite : IPrerequisite public string DisplayName => $"Windows Update {Id}"; public bool IsInstalled() => - OperatingSystemEx.Version >= OperatingSystemVersion.Windows8 || - OperatingSystemEx.GetInstalledUpdates().Any(u => - string.Equals(u, Id, StringComparison.OrdinalIgnoreCase) || - // Supersession (https://github.com/Tyrrrz/LightBulb/issues/209) - string.Equals(u, "KB3068708", StringComparison.OrdinalIgnoreCase) - ); + OperatingSystemEx.Version >= OperatingSystemVersion.Windows8 + || OperatingSystemEx + .GetInstalledUpdates() + .Any( + u => + string.Equals(u, Id, StringComparison.OrdinalIgnoreCase) + || + // Supersession (https://github.com/Tyrrrz/LightBulb/issues/209) + string.Equals(u, "KB3068708", StringComparison.OrdinalIgnoreCase) + ); private string GetInstallerDownloadUrl() { - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows7 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows7 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X64 + ) { - return - "https://download.microsoft.com/download/0/8/E/08E0386B-F6AF-4651-8D1B-C0A95D2731F0/Windows6.1-KB3063858-x64.msu"; + return "https://download.microsoft.com/download/0/8/E/08E0386B-F6AF-4651-8D1B-C0A95D2731F0/Windows6.1-KB3063858-x64.msu"; } - if (OperatingSystemEx.Version == OperatingSystemVersion.Windows7 && - OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86) + if ( + OperatingSystemEx.Version == OperatingSystemVersion.Windows7 + && OperatingSystemEx.ProcessorArchitecture == ProcessorArchitecture.X86 + ) { - return - "https://download.microsoft.com/download/C/9/6/C96CD606-3E05-4E1C-B201-51211AE80B1E/Windows6.1-KB3063858-x86.msu"; + return "https://download.microsoft.com/download/C/9/6/C96CD606-3E05-4E1C-B201-51211AE80B1E/Windows6.1-KB3063858-x86.msu"; } throw new ApplicationException("Unsupported operating system version."); @@ -47,4 +53,4 @@ public IPrerequisiteInstaller DownloadInstaller(Action? handleProgress) return new WindowsUpdatePrerequisiteInstaller(this, filePath); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdatePrerequisiteInstaller.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdatePrerequisiteInstaller.cs index 0b9249b..c14e774 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdatePrerequisiteInstaller.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Prerequisites/WindowsUpdatePrerequisiteInstaller.cs @@ -26,12 +26,12 @@ public PrerequisiteInstallerResult Run() if (exitCode != 0) { throw new ApplicationException( - $"Failed to install {Prerequisite.DisplayName}. " + - $"Exit code: {exitCode}. " + - "Please try to install this component manually." + $"Failed to install {Prerequisite.DisplayName}. " + + $"Exit code: {exitCode}. " + + "Please try to install this component manually." ); } return PrerequisiteInstallerResult.Success; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/TargetAssembly.cs b/DotnetRuntimeBootstrapper.AppHost.Core/TargetAssembly.cs index 5eabab8..cc40fc2 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/TargetAssembly.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/TargetAssembly.cs @@ -35,10 +35,11 @@ private DotnetRuntime[] GetRuntimes() // If the app targets .NET 5 desktop and .NET 6 base, // we still need to keep the base. // Very unlikely that such a situation will happen though. - runtimes.RemoveAll(r => - r.IsBase && - r.Version.Major == desktopRuntime.Version.Major && - r.Version <= desktopRuntime.Version + runtimes.RemoveAll( + r => + r.IsBase + && r.Version.Major == desktopRuntime.Version.Major + && r.Version <= desktopRuntime.Version ); } } @@ -76,12 +77,14 @@ public partial class TargetAssembly public static TargetAssembly Resolve(string filePath) { if (!File.Exists(filePath)) - throw new FileNotFoundException($"Could not find target assembly '{Path.GetFileName(filePath)}'."); + throw new FileNotFoundException( + $"Could not find target assembly '{Path.GetFileName(filePath)}'." + ); var name = - FileVersionInfo.GetVersionInfo(filePath).ProductName?.NullIfEmptyOrWhiteSpace() ?? - Path.GetFileNameWithoutExtension(filePath); + FileVersionInfo.GetVersionInfo(filePath).ProductName?.NullIfEmptyOrWhiteSpace() + ?? Path.GetFileNameWithoutExtension(filePath); return new TargetAssembly(filePath, name); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/CommandLine.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/CommandLine.cs index 0991a39..64a9920 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/CommandLine.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/CommandLine.cs @@ -18,14 +18,16 @@ internal static class CommandLine { var processJob = ProcessJob.Create(); - processJob.Configure(new JobObjectExtendedLimitInformation - { - BasicLimitInformation = new JobObjectBasicLimitInformation + processJob.Configure( + new JobObjectExtendedLimitInformation { - // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE - LimitFlags = 0x2000 + BasicLimitInformation = new JobObjectBasicLimitInformation + { + // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE + LimitFlags = 0x2000 + } } - }); + ); return processJob; } @@ -39,7 +41,11 @@ internal static class CommandLine private static string EscapeArgument(string argument) => '"' + argument.Replace("\"", "\\\"") + '"'; - private static Process CreateProcess(string executableFilePath, string[] arguments, bool isElevated = false) + private static Process CreateProcess( + string executableFilePath, + string[] arguments, + bool isElevated = false + ) { var process = new Process { @@ -72,4 +78,4 @@ public static int Run(string executableFilePath, string[] arguments, bool isElev return process.ExitCode; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Disposable.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Disposable.cs index 1388fef..0d4db75 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Disposable.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Disposable.cs @@ -6,8 +6,7 @@ internal partial class Disposable : IDisposable { private readonly Action _dispose; - public Disposable(Action dispose) => - _dispose = dispose; + public Disposable(Action dispose) => _dispose = dispose; public void Dispose() => _dispose(); } @@ -15,4 +14,4 @@ internal partial class Disposable : IDisposable internal partial class Disposable { public static IDisposable Create(Action dispose) => new Disposable(dispose); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/EnvironmentEx.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/EnvironmentEx.cs index 1b44123..acd6df2 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/EnvironmentEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/EnvironmentEx.cs @@ -17,10 +17,10 @@ public static void RefreshEnvironmentVariables() foreach (var environmentVariable in machineEnvironmentVariables) { - var key = (string) environmentVariable.Key; - var value = (string?) environmentVariable.Value; + var key = (string)environmentVariable.Key; + var value = (string?)environmentVariable.Value; Environment.SetEnvironmentVariable(key, value); } } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/AssemblyExtensions.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/AssemblyExtensions.cs index b1b8c60..d651f59 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/AssemblyExtensions.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/AssemblyExtensions.cs @@ -10,11 +10,13 @@ internal static class AssemblyExtensions public static string GetManifestResourceString(this Assembly assembly, string resourceName) { using var stream = - assembly.GetManifestResourceStream(resourceName) ?? - throw new MissingManifestResourceException($"Could not resolve resource '{resourceName}'."); + assembly.GetManifestResourceStream(resourceName) + ?? throw new MissingManifestResourceException( + $"Could not resolve resource '{resourceName}'." + ); using var reader = new StreamReader(stream, Encoding.UTF8); return reader.ReadToEnd(); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/CollectionExtensions.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/CollectionExtensions.cs index 7a35703..252cd6f 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/CollectionExtensions.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/CollectionExtensions.cs @@ -8,4 +8,4 @@ public static IEnumerable ToSingletonEnumerable(this T value) { yield return value; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/GenericExtensions.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/GenericExtensions.cs index 81e139c..a9a1d77 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/GenericExtensions.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/GenericExtensions.cs @@ -4,5 +4,6 @@ namespace DotnetRuntimeBootstrapper.AppHost.Core.Utils.Extensions; internal static class GenericExtensions { - public static TOut Pipe(this TIn input, Func transform) => transform(input); -} \ No newline at end of file + public static TOut Pipe(this TIn input, Func transform) => + transform(input); +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/RegistryExtensions.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/RegistryExtensions.cs index 26c372e..f97c843 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/RegistryExtensions.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/RegistryExtensions.cs @@ -6,4 +6,4 @@ internal static class RegistryExtensions { public static bool ContainsSubKey(this RegistryKey key, string name) => key.OpenSubKey(name, false) is not null; -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/StringExtensions.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/StringExtensions.cs index 4ce3e8b..c510144 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/StringExtensions.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Extensions/StringExtensions.cs @@ -3,7 +3,5 @@ internal static class StringExtensions { public static string? NullIfEmptyOrWhiteSpace(this string str) => - !string.IsNullOrEmpty(str.Trim()) - ? str - : null; -} \ No newline at end of file + !string.IsNullOrEmpty(str.Trim()) ? str : null; +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/FileEx.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/FileEx.cs index 4993d1f..24e9ab7 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/FileEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/FileEx.cs @@ -39,4 +39,4 @@ public static void TryDelete(string filePath) // Ignore } } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Http.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Http.cs index 08f4655..05ef054 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Http.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Http.cs @@ -23,9 +23,9 @@ static Http() // it ourselves because it would require a reboot in the middle of installation). // On Windows 8 and higher this should succeed. ServicePointManager.SecurityProtocol = - (SecurityProtocolType) 0x00000C00 | - SecurityProtocolType.Tls | - SecurityProtocolType.Ssl3; + (SecurityProtocolType)0x00000C00 + | SecurityProtocolType.Tls + | SecurityProtocolType.Ssl3; IsHttpsSupported = true; } @@ -37,13 +37,12 @@ static Http() private static HttpWebRequest CreateRequest(string url, string method = "GET") { - var request = (HttpWebRequest) WebRequest.Create( - // Certain older systems don't support HTTPS protocols required by most web servers. - // If we're running on such a system, we have to downgrade to HTTP. - IsHttpsSupported - ? url - : Url.ReplaceProtocol(url, "http") - ); + var request = (HttpWebRequest) + WebRequest.Create( + // Certain older systems don't support HTTPS protocols required by most web servers. + // If we're running on such a system, we have to downgrade to HTTP. + IsHttpsSupported ? url : Url.ReplaceProtocol(url, "http") + ); request.Method = method; @@ -62,15 +61,11 @@ private static Stream GetContentStream(string url, out long length) } catch (WebException ex) { - throw new WebException( - $"Failed to send HTTP request to '{url}'.", - ex - ); + throw new WebException($"Failed to send HTTP request to '{url}'.", ex); } } - public static Stream GetContentStream(string url) => - GetContentStream(url, out _); + public static Stream GetContentStream(string url) => GetContentStream(url, out _); public static string GetContentString(string url) { @@ -80,7 +75,11 @@ public static string GetContentString(string url) return reader.ReadToEnd(); } - public static void DownloadFile(string url, string outputFilePath, Action? handleProgress = null) + public static void DownloadFile( + string url, + string outputFilePath, + Action? handleProgress = null + ) { using var source = GetContentStream(url, out var contentLength); using var destination = File.Create(outputFilePath); @@ -101,4 +100,4 @@ public static void DownloadFile(string url, string outputFilePath, Action paths.Aggregate(Path.Combine); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/RandomEx.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/RandomEx.cs index 5b270e3..a075cad 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/RandomEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/RandomEx.cs @@ -5,4 +5,4 @@ namespace DotnetRuntimeBootstrapper.AppHost.Core.Utils; internal static class RandomEx { public static Random Instance { get; } = new(); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Url.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Url.cs index 6b528f1..c5c11e4 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Url.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/Url.cs @@ -18,9 +18,6 @@ public static string ReplaceProtocol(string url, string protocol) return protocol + url[index..]; } - public static string? TryExtractFileName(string url) => Regex - .Match(url, @".+/([^?]*)") - .Groups[1] - .Value - .NullIfEmptyOrWhiteSpace(); -} \ No newline at end of file + public static string? TryExtractFileName(string url) => + Regex.Match(url, @".+/([^?]*)").Groups[1].Value.NullIfEmptyOrWhiteSpace(); +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/VersionEx.cs b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/VersionEx.cs index 8915dbb..b89b5ce 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Core/Utils/VersionEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Core/Utils/VersionEx.cs @@ -6,9 +6,7 @@ namespace DotnetRuntimeBootstrapper.AppHost.Core.Utils; internal static class VersionEx { public static Version? TryParse(string value) => - Regex.IsMatch(value, @"^\d+\.\d+(?:\.\d+)?(?:\.\d+)?$") - ? Parse(value) - : null; + Regex.IsMatch(value, @"^\d+\.\d+(?:\.\d+)?(?:\.\d+)?$") ? Parse(value) : null; public static Version Parse(string value) => new(value); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Gui/Bootstrapper.cs b/DotnetRuntimeBootstrapper.AppHost.Gui/Bootstrapper.cs index 5689406..ef0c963 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Gui/Bootstrapper.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Gui/Bootstrapper.cs @@ -24,7 +24,8 @@ protected override void ReportError(string message) protected override bool Prompt( TargetAssembly targetAssembly, - IPrerequisite[] missingPrerequisites) + IPrerequisite[] missingPrerequisites + ) { ApplicationEx.EnsureInitialized(); @@ -36,7 +37,8 @@ protected override void ReportError(string message) protected override bool Install( TargetAssembly targetAssembly, - IPrerequisite[] missingPrerequisites) + IPrerequisite[] missingPrerequisites + ) { ApplicationEx.EnsureInitialized(); @@ -48,4 +50,4 @@ protected override void ReportError(string message) [STAThread] public static int Main(string[] args) => new Bootstrapper().Run(args); -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Gui/DotnetRuntimeBootstrapper.AppHost.Gui.csproj b/DotnetRuntimeBootstrapper.AppHost.Gui/DotnetRuntimeBootstrapper.AppHost.Gui.csproj index 3678a6c..a056d4a 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Gui/DotnetRuntimeBootstrapper.AppHost.Gui.csproj +++ b/DotnetRuntimeBootstrapper.AppHost.Gui/DotnetRuntimeBootstrapper.AppHost.Gui.csproj @@ -13,6 +13,7 @@ + diff --git a/DotnetRuntimeBootstrapper.AppHost.Gui/InstallForm.cs b/DotnetRuntimeBootstrapper.AppHost.Gui/InstallForm.cs index e213648..f23ddbd 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Gui/InstallForm.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Gui/InstallForm.cs @@ -37,36 +37,36 @@ public InstallForm(TargetAssembly targetAssembly, IPrerequisite[] missingPrerequ private void InvokeOnUI(Action action) => Invoke(action); - private void UpdateStatus(string status) => InvokeOnUI(() => - StatusLabel.Text = status - ); + private void UpdateStatus(string status) => InvokeOnUI(() => StatusLabel.Text = status); - private void UpdateCurrentProgress(double progress) => InvokeOnUI(() => - { - if (progress >= 0) - { - CurrentProgressBar.Style = ProgressBarStyle.Continuous; - CurrentProgressBar.Value = (int) (progress * 100); - } - else + private void UpdateCurrentProgress(double progress) => + InvokeOnUI(() => { - CurrentProgressBar.Style = ProgressBarStyle.Marquee; - } - }); + if (progress >= 0) + { + CurrentProgressBar.Style = ProgressBarStyle.Continuous; + CurrentProgressBar.Value = (int)(progress * 100); + } + else + { + CurrentProgressBar.Style = ProgressBarStyle.Marquee; + } + }); - private void UpdateTotalProgress(double totalProgress) => InvokeOnUI(() => - { - if (totalProgress >= 0) + private void UpdateTotalProgress(double totalProgress) => + InvokeOnUI(() => { - TotalProgressBar.Style = ProgressBarStyle.Continuous; - TotalProgressBar.Value = (int) (totalProgress * 100); - TotalProgressLabel.Text = @$"Total progress: {totalProgress:P0}"; - } - else - { - TotalProgressBar.Style = ProgressBarStyle.Marquee; - } - }); + if (totalProgress >= 0) + { + TotalProgressBar.Style = ProgressBarStyle.Continuous; + TotalProgressBar.Value = (int)(totalProgress * 100); + TotalProgressLabel.Text = @$"Total progress: {totalProgress:P0}"; + } + else + { + TotalProgressBar.Style = ProgressBarStyle.Marquee; + } + }); private void Execute() { @@ -77,7 +77,9 @@ private void Execute() var installers = new List(); foreach (var prerequisite in _missingPrerequisites) { - UpdateStatus(@$"[{currentStep}/{totalSteps}] Downloading {prerequisite.DisplayName}..."); + UpdateStatus( + @$"[{currentStep}/{totalSteps}] Downloading {prerequisite.DisplayName}..." + ); UpdateCurrentProgress(0); var installer = prerequisite.DownloadInstaller(p => @@ -96,7 +98,9 @@ private void Execute() var installersFinishedCount = 0; foreach (var installer in installers) { - UpdateStatus(@$"[{currentStep}/{totalSteps}] Installing {installer.Prerequisite.DisplayName}..."); + UpdateStatus( + @$"[{currentStep}/{totalSteps}] Installing {installer.Prerequisite.DisplayName}..." + ); UpdateCurrentProgress(-1); var installationResult = installer.Run(); @@ -113,13 +117,14 @@ private void Execute() // Finalize if (isRebootRequired) { - var isRebootAccepted = MessageBox.Show( - @$"You need to restart Windows before you can run {_targetAssembly.Name}. " + - @"Would you like to do it now?", - @"Restart required", - MessageBoxButtons.YesNo, - MessageBoxIcon.Warning - ) == DialogResult.Yes; + var isRebootAccepted = + MessageBox.Show( + @$"You need to restart Windows before you can run {_targetAssembly.Name}. " + + @"Would you like to do it now?", + @"Restart required", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning + ) == DialogResult.Yes; if (isRebootAccepted) OperatingSystemEx.Reboot(); @@ -141,10 +146,6 @@ private void InstallationForm_Load(object sender, EventArgs e) UpdateStatus(@"Preparing installation"); - new Thread(Execute) - { - Name = nameof(Execute), - IsBackground = true - }.Start(); + new Thread(Execute) { Name = nameof(Execute), IsBackground = true }.Start(); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Gui/PromptForm.cs b/DotnetRuntimeBootstrapper.AppHost.Gui/PromptForm.cs index cb34b2f..6ddb6e7 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Gui/PromptForm.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Gui/PromptForm.cs @@ -27,7 +27,9 @@ private void InstallationPromptForm_Load(object sender, EventArgs e) { Text = @$"{_targetAssembly.Name}: prerequisites missing"; Icon = IconEx.TryExtractAssociatedIcon(Application.ExecutablePath); - MissingPrerequisitesTextBox.Lines = _missingPrerequisites.Select(c => $"• {c.DisplayName}").ToArray(); + MissingPrerequisitesTextBox.Lines = _missingPrerequisites + .Select(c => $"• {c.DisplayName}") + .ToArray(); } private void InstallButton_Click(object sender, EventArgs e) @@ -41,4 +43,4 @@ private void ExitButton_Click(object sender, EventArgs e) IsSuccess = false; Close(); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.AppHost.Gui/Utils/ApplicationEx.cs b/DotnetRuntimeBootstrapper.AppHost.Gui/Utils/ApplicationEx.cs index ac80f38..b4e83d4 100644 --- a/DotnetRuntimeBootstrapper.AppHost.Gui/Utils/ApplicationEx.cs +++ b/DotnetRuntimeBootstrapper.AppHost.Gui/Utils/ApplicationEx.cs @@ -16,4 +16,4 @@ public static void EnsureInitialized() Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.Demo.Cli/DotnetRuntimeBootstrapper.Demo.Cli.csproj b/DotnetRuntimeBootstrapper.Demo.Cli/DotnetRuntimeBootstrapper.Demo.Cli.csproj index 35bb73a..fdf1018 100644 --- a/DotnetRuntimeBootstrapper.Demo.Cli/DotnetRuntimeBootstrapper.Demo.Cli.csproj +++ b/DotnetRuntimeBootstrapper.Demo.Cli/DotnetRuntimeBootstrapper.Demo.Cli.csproj @@ -13,6 +13,10 @@ true + + + + diff --git a/DotnetRuntimeBootstrapper.Demo.Cli/Program.cs b/DotnetRuntimeBootstrapper.Demo.Cli/Program.cs index 4721eee..37a3f0b 100644 --- a/DotnetRuntimeBootstrapper.Demo.Cli/Program.cs +++ b/DotnetRuntimeBootstrapper.Demo.Cli/Program.cs @@ -17,4 +17,4 @@ public static void Main(string[] args) Console.WriteLine("Hello world!"); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.Demo.Gui/DotnetRuntimeBootstrapper.Demo.Gui.csproj b/DotnetRuntimeBootstrapper.Demo.Gui/DotnetRuntimeBootstrapper.Demo.Gui.csproj index a37dbc1..5b921cd 100644 --- a/DotnetRuntimeBootstrapper.Demo.Gui/DotnetRuntimeBootstrapper.Demo.Gui.csproj +++ b/DotnetRuntimeBootstrapper.Demo.Gui/DotnetRuntimeBootstrapper.Demo.Gui.csproj @@ -15,6 +15,10 @@ true + + + + diff --git a/DotnetRuntimeBootstrapper.Demo.Gui/MainForm.cs b/DotnetRuntimeBootstrapper.Demo.Gui/MainForm.cs index 9500b35..0f6af9d 100644 --- a/DotnetRuntimeBootstrapper.Demo.Gui/MainForm.cs +++ b/DotnetRuntimeBootstrapper.Demo.Gui/MainForm.cs @@ -8,4 +8,4 @@ public MainForm() { InitializeComponent(); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper.Demo.Gui/Program.cs b/DotnetRuntimeBootstrapper.Demo.Gui/Program.cs index 9b3c009..3e990ac 100644 --- a/DotnetRuntimeBootstrapper.Demo.Gui/Program.cs +++ b/DotnetRuntimeBootstrapper.Demo.Gui/Program.cs @@ -21,4 +21,4 @@ public static void Main(string[] args) Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper/BootstrapperTask.cs b/DotnetRuntimeBootstrapper/BootstrapperTask.cs index 463bc8a..e1b4d83 100644 --- a/DotnetRuntimeBootstrapper/BootstrapperTask.cs +++ b/DotnetRuntimeBootstrapper/BootstrapperTask.cs @@ -35,26 +35,25 @@ private void ExtractAppHost() Log.LogMessage("Extracting apphost..."); var assembly = Assembly.GetExecutingAssembly(); - var resourceName = GetType().Namespace + Variant.ToUpperInvariant() switch - { - "CLI" => ".AppHost.Cli.exe", - "GUI" => ".AppHost.Gui.exe", - _ => throw new InvalidOperationException($"Unknown bootstrapper variant '{Variant}'.") - }; + var resourceName = + GetType().Namespace + + Variant.ToUpperInvariant() switch + { + "CLI" => ".AppHost.Cli.exe", + "GUI" => ".AppHost.Gui.exe", + _ + => throw new InvalidOperationException( + $"Unknown bootstrapper variant '{Variant}'." + ) + }; // Executable file - assembly.ExtractManifestResource( - resourceName, - AppHostFilePath - ); + assembly.ExtractManifestResource(resourceName, AppHostFilePath); Log.LogMessage("Extracted apphost to '{0}'.", AppHostFilePath); // Config file - assembly.ExtractManifestResource( - resourceName + ".config", - AppHostFilePath + ".config" - ); + assembly.ExtractManifestResource(resourceName + ".config", AppHostFilePath + ".config"); Log.LogMessage("Extracted apphost config to '{0}'.", AppHostFilePath + ".config"); } @@ -63,8 +62,7 @@ private void InjectConfiguration() { Log.LogMessage("Injecting configuration..."); - var configuration = - $""" + var configuration = $""" TargetFileName={TargetFileName} IsPromptRequired={IsPromptRequired} """; @@ -74,15 +72,22 @@ private void InjectConfiguration() new ReaderParameters { ReadWrite = true } ); - assembly.MainModule.Resources.RemoveAll(r => - string.Equals(r.Name, "BootstrapperConfiguration", StringComparison.OrdinalIgnoreCase) + assembly.MainModule.Resources.RemoveAll( + r => + string.Equals( + r.Name, + "BootstrapperConfiguration", + StringComparison.OrdinalIgnoreCase + ) ); - assembly.MainModule.Resources.Add(new EmbeddedResource( - "BootstrapperConfiguration", - ManifestResourceAttributes.Public, - Encoding.UTF8.GetBytes(configuration) - )); + assembly.MainModule.Resources.Add( + new EmbeddedResource( + "BootstrapperConfiguration", + ManifestResourceAttributes.Public, + Encoding.UTF8.GetBytes(configuration) + ) + ); assembly.Write(); @@ -108,11 +113,15 @@ private void InjectResources() } // Modify the version info resource - targetPortableExecutable.SetVersionInfo(v => v - .SetFileType(FileType.Application) - .SetAttribute(VersionAttributeName.InternalName, AppHostFileName) - .SetAttribute(VersionAttributeName.OriginalFilename, AppHostFileName) - .SetAttribute("AppHost", $".NET Runtime Bootstrapper v{Version.ToString(3)} ({Variant})") + targetPortableExecutable.SetVersionInfo( + v => + v.SetFileType(FileType.Application) + .SetAttribute(VersionAttributeName.InternalName, AppHostFileName) + .SetAttribute(VersionAttributeName.OriginalFilename, AppHostFileName) + .SetAttribute( + "AppHost", + $".NET Runtime Bootstrapper v{Version.ToString(3)} ({Variant})" + ) ); Log.LogMessage("Injected resources into '{0}'.", AppHostFileName); @@ -132,4 +141,4 @@ public override bool Execute() Log.LogMessage("Bootstrapper successfully created."); return true; } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper/DotnetRuntimeBootstrapper.csproj b/DotnetRuntimeBootstrapper/DotnetRuntimeBootstrapper.csproj index a6751a8..a4a8573 100644 --- a/DotnetRuntimeBootstrapper/DotnetRuntimeBootstrapper.csproj +++ b/DotnetRuntimeBootstrapper/DotnetRuntimeBootstrapper.csproj @@ -31,6 +31,7 @@ + diff --git a/DotnetRuntimeBootstrapper/Utils/Extensions/AssemblyExtensions.cs b/DotnetRuntimeBootstrapper/Utils/Extensions/AssemblyExtensions.cs index ce16fc5..73512c2 100644 --- a/DotnetRuntimeBootstrapper/Utils/Extensions/AssemblyExtensions.cs +++ b/DotnetRuntimeBootstrapper/Utils/Extensions/AssemblyExtensions.cs @@ -6,13 +6,19 @@ namespace DotnetRuntimeBootstrapper.Utils.Extensions; internal static class AssemblyExtensions { - public static void ExtractManifestResource(this Assembly assembly, string resourceName, string filePath) + public static void ExtractManifestResource( + this Assembly assembly, + string resourceName, + string filePath + ) { var resourceStream = - assembly.GetManifestResourceStream(resourceName) ?? - throw new MissingManifestResourceException($"Could not find resource '{resourceName}'."); + assembly.GetManifestResourceStream(resourceName) + ?? throw new MissingManifestResourceException( + $"Could not find resource '{resourceName}'." + ); using var fileStream = File.Create(filePath); resourceStream.CopyTo(fileStream); } -} \ No newline at end of file +} diff --git a/DotnetRuntimeBootstrapper/Utils/Extensions/CollectionExtensions.cs b/DotnetRuntimeBootstrapper/Utils/Extensions/CollectionExtensions.cs index 89bc94c..8ff0c3e 100644 --- a/DotnetRuntimeBootstrapper/Utils/Extensions/CollectionExtensions.cs +++ b/DotnetRuntimeBootstrapper/Utils/Extensions/CollectionExtensions.cs @@ -14,4 +14,4 @@ public static void RemoveAll(this ICollection source, Func predic source.Remove(i); } } -} \ No newline at end of file +}