diff --git a/CMakeLists.txt b/CMakeLists.txt index ee55ff2d..f069ff16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,6 +222,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/app/loot_paths.h" "${CMAKE_SOURCE_DIR}/include/loot/error.h" "${CMAKE_SOURCE_DIR}/include/loot/error_categories.h" "${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h" + "${CMAKE_SOURCE_DIR}/include/loot/exception/game_detection_error.h" "${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h" "${CMAKE_SOURCE_DIR}/include/loot/game_type.h" "${CMAKE_SOURCE_DIR}/include/loot/language_code.h" @@ -283,6 +284,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h" "${CMAKE_SOURCE_DIR}/include/loot/error.h" "${CMAKE_SOURCE_DIR}/include/loot/error_categories.h" "${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h" + "${CMAKE_SOURCE_DIR}/include/loot/exception/game_detection_error.h" "${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h" "${CMAKE_SOURCE_DIR}/include/loot/game_type.h" "${CMAKE_SOURCE_DIR}/include/loot/language_code.h" diff --git a/docs/api/reference.rst b/docs/api/reference.rst index e7a7ecfd..c78c0342 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -49,6 +49,9 @@ Classes .. doxygenclass:: loot::GitStateError :members: +.. doxygenclass:: loot::GameDetectionError + :members: + .. doxygenclass:: loot::Error :members: diff --git a/include/loot/api.h b/include/loot/api.h index 23594fa7..b6d4c888 100644 --- a/include/loot/api.h +++ b/include/loot/api.h @@ -33,6 +33,7 @@ #include "loot/error.h" #include "loot/error_categories.h" #include "loot/exception/cyclic_interaction_error.h" +#include "loot/exception/game_detection_error.h" #include "loot/exception/git_state_error.h" #include "loot/game_type.h" #include "loot/loot_version.h" diff --git a/include/loot/error.h b/include/loot/error.h index 497dd270..0462ffb3 100644 --- a/include/loot/error.h +++ b/include/loot/error.h @@ -57,8 +57,6 @@ public: condition_eval_fail = 4, /** A path could not be found. */ path_not_found = 9, - /** None of LOOT's supported games could be detected. */ - no_game_detected = 10, }; /** diff --git a/include/loot/exception/game_detection_error.h b/include/loot/exception/game_detection_error.h new file mode 100644 index 00000000..01a98b48 --- /dev/null +++ b/include/loot/exception/game_detection_error.h @@ -0,0 +1,41 @@ +/* LOOT + + A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and + Fallout: New Vegas. + + Copyright (C) 2012-2016 WrinklyNinja + + This file is part of LOOT. + + LOOT is free software: you can redistribute + it and/or modify it under the terms of the GNU General Public License + as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + LOOT is distributed in the hope that it will + be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LOOT. If not, see + . + */ + +#ifndef LOOT_EXCEPTION_GAME_DETECTION_ERROR +#define LOOT_EXCEPTION_GAME_DETECTION_ERROR + +#include + +namespace loot { +/** + * @brief An exception class thrown if an error occurs when detecting installed + * games. + */ +class GameDetectionError : public std::runtime_error { +public: + using std::runtime_error::runtime_error; +}; +} + +#endif diff --git a/src/backend/app/loot_state.cpp b/src/backend/app/loot_state.cpp index 6db37f8b..7e562ea7 100644 --- a/src/backend/app/loot_state.cpp +++ b/src/backend/app/loot_state.cpp @@ -35,6 +35,7 @@ #include #include "loot/error.h" +#include "loot/exception/game_detection_error.h" #include "backend/app/loot_paths.h" #include "backend/helpers/helpers.h" #include "backend/helpers/language.h" @@ -186,13 +187,11 @@ void LootState::init(const std::string& cmdLineGame) { currentGame_->Init(true); // Update game path in settings object. storeGameSettings(toGameSettings(games_)); + } catch (GameDetectionError& e) { + initErrors_.push_back(e.what()); } catch (Error &e) { - if (e.code() == Error::Code::no_game_detected) { - initErrors_.push_back(e.what()); - } else { - BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what(); - initErrors_.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str()); - } + BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what(); + initErrors_.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str()); } BOOST_LOG_TRIVIAL(debug) << "Game selected is " << currentGame_->Name(); } @@ -271,7 +270,7 @@ void LootState::selectGame(std::string preferredGame) { // If no game can be selected, throw an exception. if (currentGame_ == end(games_)) { BOOST_LOG_TRIVIAL(error) << "None of the supported games were detected."; - throw Error(Error::Code::no_game_detected, translate("None of the supported games were detected.")); + throw GameDetectionError(translate("None of the supported games were detected.")); } } diff --git a/src/backend/game/game.cpp b/src/backend/game/game.cpp index e04b618c..1bfb6cc8 100644 --- a/src/backend/game/game.cpp +++ b/src/backend/game/game.cpp @@ -33,6 +33,7 @@ #include "backend/app/loot_paths.h" #include "loot/error.h" +#include "loot/exception/game_detection_error.h" #include "backend/helpers/helpers.h" using boost::locale::translate; @@ -64,7 +65,7 @@ void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppDa if (!this->IsInstalled()) { BOOST_LOG_TRIVIAL(error) << "Game path could not be detected."; - throw Error(Error::Code::path_not_found, translate("Game path could not be detected.").str()); + throw GameDetectionError(translate("Game path could not be detected.")); } if (createFolder) { diff --git a/src/tests/backend/game/game_test.h b/src/tests/backend/game/game_test.h index db86be54..1e02a628 100644 --- a/src/tests/backend/game/game_test.h +++ b/src/tests/backend/game/game_test.h @@ -28,7 +28,7 @@ along with LOOT. If not, see #include "backend/game/game.h" #include "backend/app/loot_paths.h" -#include "loot/error.h" +#include "loot/exception/game_detection_error.h" #include "tests/backend/game/load_order_handler_test.h" namespace loot { @@ -89,10 +89,10 @@ TEST_P(GameTest, constructingFromIdAndFolderShouldPassThemToGameSettingsConstruc // test autodetection fully unless on Linux. TEST_P(GameTest, initShouldThrowOnLinuxIfGamePathIsNotGiven) { Game game = Game(GetParam()); - EXPECT_THROW(game.Init(false), Error); - EXPECT_THROW(game.Init(true), Error); - EXPECT_THROW(game.Init(false, localPath), Error); - EXPECT_THROW(game.Init(true, localPath), Error); + EXPECT_THROW(game.Init(false), GameDetectionError); + EXPECT_THROW(game.Init(true), GameDetectionError); + EXPECT_THROW(game.Init(false, localPath), GameDetectionError); + EXPECT_THROW(game.Init(true, localPath), GameDetectionError); } TEST_P(GameTest, initShouldThrowOnLinuxIfLocalPathIsNotGiven) {