mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Revert "Refactored game selection code."
This reverts commit bdfb13c82b.
This commit is contained in:
+4
-24
@@ -62,26 +62,6 @@ namespace loot {
|
||||
return games;
|
||||
}
|
||||
|
||||
size_t SelectGame(const YAML::Node& settings, const std::vector<Game>& games, const std::string& cmdLineGame) {
|
||||
string preferredGame(cmdLineGame);
|
||||
if (preferredGame.empty()) {
|
||||
// Get preferred game from settings.
|
||||
if (settings["Game"] && settings["Game"].as<string>() != "auto")
|
||||
preferredGame = settings["Game"].as<string>();
|
||||
else if (settings["Last Game"] && settings["Last Game"].as<string>() != "auto")
|
||||
preferredGame = settings["Last Game"].as<string>();
|
||||
}
|
||||
|
||||
// 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<std::string, uintmax_t> tempMap;
|
||||
size_t meanFileSize = 0;
|
||||
unordered_map<std::string, size_t> tempMap;
|
||||
std::vector<Plugin*> 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) {
|
||||
|
||||
@@ -158,8 +158,6 @@ namespace loot {
|
||||
};
|
||||
|
||||
std::vector<Game> GetGames(const YAML::Node& settings);
|
||||
|
||||
size_t SelectGame(const YAML::Node& settings, const std::vector<Game>& games, const std::string& cmdLineGame);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+37
-11
@@ -34,12 +34,18 @@
|
||||
#include "../backend/helpers.h"
|
||||
#include "../backend/generators.h"
|
||||
#include "../backend/streams.h"
|
||||
//#include "../backend/graph.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <ctime>
|
||||
#include <clocale>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/log/core.hpp>
|
||||
@@ -48,6 +54,7 @@
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/support/date_time.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <wx/snglinst.h>
|
||||
#include <wx/aboutdlg.h>
|
||||
@@ -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<string>() != "auto")
|
||||
target = _settings["Game"].as<string>();
|
||||
else if (_settings["Last Game"] && _settings["Last Game"].as<string>() != "auto")
|
||||
target = _settings["Last Game"].as<string>();
|
||||
}
|
||||
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user