From 82aa208db6da6da4a969142b06537495836bd8bc Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Wed, 13 May 2015 17:53:57 +0100 Subject: [PATCH] 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. --- src/backend/game.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/backend/game.cpp b/src/backend/game.cpp index a71d75dd..ccbac21a 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -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; }