Skip to content

Commit

Permalink
Fix #1: Launch failure due to get_WarbandPath()
Browse files Browse the repository at this point in the history
Gracefully handle missing or inaccessible registry key for install_path.
  • Loading branch information
int19h committed Sep 5, 2018
1 parent 99a8b1f commit 1566871
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions WarBender.UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 1566871

Please sign in to comment.