Skip to content

Commit

Permalink
Merge pull request #111 from C7-Game/winregfix
Browse files Browse the repository at this point in the history
Fixes #79 error when winreg key not present
  • Loading branch information
QuintillusCFC committed Feb 23, 2022
2 parents 4fc2bfb + cbc0e30 commit 6a4d60e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions C7/Util.cs
Expand Up @@ -31,17 +31,18 @@ static public string GetCiv3Path()
if (path != null) return path;

// Look up in Windows registry if present
path = Civ3PathFromRegistry("");
if (path != "") return path;
path = Civ3PathFromRegistry();
if (path != null) return path;

// TODO: Maybe check an array of hard-coded paths during dev time?
return "/civ3/path/not/found";
}

static public string Civ3PathFromRegistry(string defaultPath = "D:/Civilization III")
static public string Civ3PathFromRegistry()
{
// Assuming 64-bit platform, get vanilla Civ3 install folder from registry
return (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Infogrames Interactive\Civilization III", "install_path", defaultPath);
// Return null if value not present or if key not found
return (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Infogrames Interactive\Civilization III", "install_path", null);
}

// Checks if a file exists ignoring case on the latter parts of its path. If the file is found, returns its full path re-capitalized as
Expand Down

0 comments on commit 6a4d60e

Please sign in to comment.