From 6dc447a8ce1d0242f5eecd7109f940c104880710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20Kentt=C3=A4?= Date: Tue, 19 Dec 2023 18:08:34 +0200 Subject: [PATCH] Try to avoid some .Net Framework 4.8 features --- src/Setup.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Setup.cs b/src/Setup.cs index 5a30a77..e1f2abf 100644 --- a/src/Setup.cs +++ b/src/Setup.cs @@ -519,7 +519,7 @@ public class Setup { */ protected void VerifyLoaderConfig() { var lines = File.ReadAllLines("config.txt"); - var loader = lines.Where(s => s.StartsWith("boot=")).Select(s => s.Substring(5)).Prepend("").Last(); + var loader = lines.Where(s => s.StartsWith("boot=")).Select(s => s.Substring(5)).LastOrDefault(); if (loader == null) { throw new SetupException("config.txt does not contain a boot=... line!"); } @@ -716,8 +716,13 @@ public class Setup { * @param arch The architecture. */ protected void SetArch(string arch) { - var detectedArch = DetectArchFromOS(); - if (arch == "") { + var detectedArch = Environment.Is64BitOperatingSystem ? "x64" : "ia32"; + try { + detectedArch = DetectArchFromOS(); + } catch { + WriteLine($"Failed to detect OS architecture, assuming {detectedArch}."); + } + if (arch == "" || arch == null) { EfiArch = detectedArch; WriteLine($"Your OS uses arch={EfiArch}. This will be checked again during installation."); } else { @@ -963,7 +968,7 @@ public class Setup { Batch = args.Contains("batch"); ForwardArguments = String.Join(" ", args.Where(s => s == "dry-run" || s == "batch" || s.StartsWith("arch="))); try { - SetArch(args.Prepend("arch=").Last(s => s.StartsWith("arch=")).Substring(5)); + SetArch(args.Where(s => s.StartsWith("arch=")).Select(s => s.Substring(5)).LastOrDefault()); if (args.Contains("is-elevated") && !HasPrivileges() && !DryRun) { WriteLine("This installer needs to be run as administrator!"); return 1;