Fix startup crash due to filesystem permissions.

An exception can be thrown when checking if a path exists, if the user
doesn't have permission to read that path. This exception wasn't getting
caught, so game detection was causing crashes on improperly-configured
systems. Now exceptions thrown during game detection are treated as the
game not being installed. Fixes #416.
This commit is contained in:
Oliver Hamlet
2015-05-13 17:53:57 +01:00
parent 7a48820d2b
commit 82aa208db6
+16 -11
View File
@@ -385,21 +385,26 @@ namespace loot {
}
bool Game::IsInstalled() const {
BOOST_LOG_TRIVIAL(trace) << "Checking if game \"" << _name << "\" is installed.";
if (!gamePath.empty() && fs::exists(gamePath / "Data" / _masterFile))
return true;
try {
BOOST_LOG_TRIVIAL(trace) << "Checking if game \"" << _name << "\" is installed.";
if (!gamePath.empty() && fs::exists(gamePath / "Data" / _masterFile))
return true;
if (fs::exists(fs::path("..") / "Data" / _masterFile))
return true;
if (fs::exists(fs::path("..") / "Data" / _masterFile))
return true;
#ifdef _WIN32
string path;
string key_parent = fs::path(registryKey).parent_path().string();
string key_name = fs::path(registryKey).filename().string();
path = RegKeyStringValue("HKEY_LOCAL_MACHINE", key_parent, key_name);
if (!path.empty() && fs::exists(fs::path(path) / "Data" / _masterFile))
return true;
string path;
string key_parent = fs::path(registryKey).parent_path().string();
string key_name = fs::path(registryKey).filename().string();
path = RegKeyStringValue("HKEY_LOCAL_MACHINE", key_parent, key_name);
if (!path.empty() && fs::exists(fs::path(path) / "Data" / _masterFile))
return true;
#endif
}
catch (exception &e) {
BOOST_LOG_TRIVIAL(error) << "Error while checking if game \"" << _name << "\" is installed: " << e.what();
}
return false;
}