From 1566871773e98bb0e7d2030cec3757f8817970a8 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Tue, 4 Sep 2018 20:52:44 -0700 Subject: [PATCH] Fix #1: Launch failure due to get_WarbandPath() Gracefully handle missing or inaccessible registry key for install_path. --- WarBender.UI/MainForm.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/WarBender.UI/MainForm.cs b/WarBender.UI/MainForm.cs index d10a9bd..44bc09d 100644 --- a/WarBender.UI/MainForm.cs +++ b/WarBender.UI/MainForm.cs @@ -67,9 +67,15 @@ public Game Game { private string WarbandPath { get { - var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); - var warbandKey = hklm.OpenSubKey(@"SOFTWARE\mount&blade warband"); - return warbandKey.GetValue("install_path", null)?.ToString(); + try { + var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); + var warbandKey = hklm?.OpenSubKey(@"SOFTWARE\mount&blade warband"); + return warbandKey?.GetValue("install_path", null)?.ToString(); + } catch (UnauthorizedAccessException) { + return null; + } catch (IOException) { + return null; + } } }