From ada0dc91af555da1228d28d68a1817d248f7fedc Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Thu, 25 May 2023 22:56:08 +0100 Subject: [PATCH] Better handling of malformed registry key (#264) --- Bloxstrap/App.xaml.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 2dc51ab..9e39d45 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -174,7 +174,12 @@ namespace Bloxstrap // check if installed using (RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey($@"Software\{ProjectName}")) { - if (registryKey is null) + string? installLocation = null; + + if (registryKey is not null) + installLocation = (string?)registryKey.GetValue("InstallLocation"); + + if (registryKey is null || installLocation is null) { Logger.WriteLine("[App::OnStartup] Running first-time install"); @@ -191,7 +196,7 @@ namespace Bloxstrap else { IsFirstRun = false; - BaseDirectory = (string)registryKey.GetValue("InstallLocation")!; + BaseDirectory = installLocation; } }