diff --git a/src/backend/game.cpp b/src/backend/game.cpp index 61f8252b..67ff7653 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -62,26 +62,6 @@ namespace loot { return games; } - size_t SelectGame(const YAML::Node& settings, const std::vector& games, const std::string& cmdLineGame) { - string preferredGame(cmdLineGame); - if (preferredGame.empty()) { - // Get preferred game from settings. - if (settings["Game"] && settings["Game"].as() != "auto") - preferredGame = settings["Game"].as(); - else if (settings["Last Game"] && settings["Last Game"].as() != "auto") - preferredGame = settings["Last Game"].as(); - } - - // Get index of preferred game if there is one. - for (size_t i = 0; i < games.size(); ++i) { - if (preferredGame.empty() && games[i].IsInstalled()) - return i; - else if (!preferredGame.empty() && preferredGame == games[i].FolderName() && games[i].IsInstalled()) - return i; - } - throw error(error::no_game_detected, "None of the supported games were detected."); - } - // MetadataList member functions //------------------------------ @@ -612,20 +592,20 @@ namespace loot { void Game::LoadPlugins(bool headersOnly) { boost::thread_group group; - uintmax_t meanFileSize = 0; - unordered_map tempMap; + size_t meanFileSize = 0; + unordered_map tempMap; std::vector groupPlugins; //First calculate the mean plugin size. Store it temporarily in a map to reduce filesystem lookups and file size recalculation. for (fs::directory_iterator it(this->DataPath()); it != fs::directory_iterator(); ++it) { if (fs::is_regular_file(it->status()) && IsPlugin(it->path().string())) { - uintmax_t fileSize = fs::file_size(it->path()); + size_t fileSize = fs::file_size(it->path()); meanFileSize += fileSize; tempMap.emplace(it->path().filename().string(), fileSize); } } - meanFileSize /= tempMap.size(); //Rounding error, but not important. + meanFileSize /= tempMap.size(); //Now load plugins. for (const auto &pluginPair : tempMap) { diff --git a/src/backend/game.h b/src/backend/game.h index 5ecfe6f2..44098b7e 100644 --- a/src/backend/game.h +++ b/src/backend/game.h @@ -158,8 +158,6 @@ namespace loot { }; std::vector GetGames(const YAML::Node& settings); - - size_t SelectGame(const YAML::Node& settings, const std::vector& games, const std::string& cmdLineGame); } #endif diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 5021040d..b2df1a9b 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -34,12 +34,18 @@ #include "../backend/helpers.h" #include "../backend/generators.h" #include "../backend/streams.h" +//#include "../backend/graph.h" +#include #include +#include +#include #include +#include #include #include +#include #include #include #include @@ -48,6 +54,7 @@ #include #include #include +#include #include #include @@ -230,6 +237,7 @@ bool LOOT::OnInit() { BOOST_LOG_TRIVIAL(debug) << "Selecting game."; string target; + int gameIndex = -1; wxCmdLineEntryDesc cmdLineDesc[2]; cmdLineDesc[0].kind = wxCMD_LINE_OPTION; @@ -255,18 +263,36 @@ bool LOOT::OnInit() { break; } - size_t gameIndex(0); - try { - gameIndex = SelectGame(_settings, _games, target); + if (target.empty()) { + if (_settings["Game"] && _settings["Game"].as() != "auto") + target = _settings["Game"].as(); + else if (_settings["Last Game"] && _settings["Last Game"].as() != "auto") + target = _settings["Last Game"].as(); } - catch (exception &e) { - BOOST_LOG_TRIVIAL(error) << "None of the supported games were detected."; - wxMessageBox( - translate("Error: None of the supported games were detected."), - translate("LOOT: Error"), - wxOK | wxICON_ERROR, - nullptr); - return false; + + if (!target.empty()) { + for (size_t i=0, max=_games.size(); i < max; ++i) { + if (target == _games[i].FolderName() && _games[i].IsInstalled()) + gameIndex = i; + } + } + if (gameIndex < 0) { + //Set gameIndex to the first installed game. + for (size_t i=0, max=_games.size(); i < max; ++i) { + if (_games[i].IsInstalled()) { + gameIndex = i; + break; + } + } + if (gameIndex < 0) { + BOOST_LOG_TRIVIAL(error) << "None of the supported games were detected."; + wxMessageBox( + translate("Error: None of the supported games were detected."), + translate("LOOT: Error"), + wxOK | wxICON_ERROR, + nullptr); + return false; + } } BOOST_LOG_TRIVIAL(debug) << "Game selected is " << _games[gameIndex].Name();