From c2eddf21402ff216a02ea71c7f439bbbfdd3a718 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Fri, 21 Mar 2014 00:00:38 +0000 Subject: [PATCH] Some mostly backend changes. Metadata editor now lists plugins in their load order though. --- src/backend/game.cpp | 26 +++++++++++++++++++++----- src/backend/game.h | 5 +++-- src/backend/metadata.cpp | 11 ----------- src/backend/metadata.h | 4 ---- src/gui/editor.cpp | 1 + src/gui/main.cpp | 19 ++++++++----------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/backend/game.cpp b/src/backend/game.cpp index e89a2bae..b26d9785 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -313,7 +313,7 @@ namespace loot { return activePlugins.find(boost::to_lower_copy(plugin)) != activePlugins.end(); } - void Game::GetLoadOrder(std::list& loadOrder) const { + void Game::GetLoadOrder(std::list& loadOrder) const { BOOST_LOG_TRIVIAL(trace) << "Setting load order for game: " << _name; lo_game_handle gh; @@ -480,21 +480,21 @@ namespace loot { if (id != tes5) return; - list loadorder; + list loadorder; GetLoadOrder(loadorder); if (!loadorder.empty()) { time_t lastTime, thisTime; - fs::path filepath = DataPath() / loadorder.begin()->Name(); + fs::path filepath = DataPath() / *loadorder.begin(); if (!fs::exists(filepath) && fs::exists(filepath.string() + ".ghost")) filepath += ".ghost"; lastTime = fs::last_write_time(filepath); - for (list::const_iterator it = loadorder.begin(), itend = loadorder.end(); it != itend; ++it) { + for (list::const_iterator it = loadorder.begin(), itend = loadorder.end(); it != itend; ++it) { - filepath = DataPath() / it->Name(); + filepath = DataPath() / *it; if (!fs::exists(filepath) && fs::exists(filepath.string() + ".ghost")) filepath += ".ghost"; @@ -513,6 +513,22 @@ namespace loot { } } + void Game::LoadPlugins(bool headersOnly) { + //Add all plugins in data folder not already in the hashset to the hashset, and load them. + for (fs::directory_iterator it(DataPath()); it != fs::directory_iterator(); ++it) { + if (fs::is_regular_file(it->status()) && IsPlugin(it->path().string())) { + const string filename = it->path().filename().string(); + + if (plugins.find(filename) == plugins.end()) + plugins.insert(std::pair(filename, Plugin(filename))); + } + } + + for (boost::unordered_map::iterator it = plugins.begin(), itend = plugins.end(); it != itend; ++it) { + it->second = Plugin(*this, it->second.Name(), headersOnly); + } + } + void Game::CreateLOOTGameFolder() { //Make sure that the LOOT game path exists. try { diff --git a/src/backend/game.h b/src/backend/game.h index 293b7e55..a398d40c 100644 --- a/src/backend/game.h +++ b/src/backend/game.h @@ -85,11 +85,12 @@ namespace loot { bool IsActive(const std::string& plugin) const; - void GetLoadOrder(std::list& loadOrder) const; + void GetLoadOrder(std::list& loadOrder) const; void SetLoadOrder(const std::list& loadOrder) const; //Modifies game load order, even though const. void RefreshActivePluginsList(); void RedatePlugins(); //Change timestamps to match load order (Skyrim only). + void LoadPlugins(bool headersOnly); //Loads all installed plugins. //Caches for condition results, active plugins and CRCs. boost::unordered_map conditionCache; //Holds lowercased strings. @@ -98,7 +99,7 @@ namespace loot { //Plugin data and metadata lists. MetadataList masterlist; MetadataList userlist; - boost::unordered_set plugins; + boost::unordered_map plugins; //Map so that plugin data can be edited. espm::Settings espm_settings; diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index 4e9130c3..a5954413 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -795,17 +795,6 @@ namespace loot { return rhs == lhs; } - bool alpha_sort(const Plugin& lhs, const Plugin& rhs) { - return boost::ilexicographical_compare(rhs.Name(), lhs.Name()); - } - - bool master_sort(const Plugin& lhs, const Plugin& rhs) { - if (lhs.IsMaster() && !rhs.IsMaster()) - return true; - else - return false; - } - bool IsPlugin(const std::string& file) { if (boost::iends_with(file, ".esp") || boost::iends_with(file, ".esm") || boost::iends_with(file, ".esp.ghost") || boost::iends_with(file, ".esm.ghost")) diff --git a/src/backend/metadata.h b/src/backend/metadata.h index 02d8d494..9a0af0dc 100644 --- a/src/backend/metadata.h +++ b/src/backend/metadata.h @@ -260,10 +260,6 @@ namespace loot { bool operator == (const std::string& lhs, const Plugin& rhs); - bool alpha_sort(const Plugin& lhs, const Plugin& rhs); - - bool master_sort(const Plugin& lhs, const Plugin& rhs); - bool IsPlugin(const std::string& file); } diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index 03ead905..c769b293 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -649,6 +649,7 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli if (std::find(_editedPlugins.begin(), _editedPlugins.end(), *it) != _editedPlugins.end()) { pluginList->SetItemFont(i, wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold()); } + ++i; } pluginList->SetColumnWidth(0, wxLIST_AUTOSIZE); diff --git a/src/gui/main.cpp b/src/gui/main.cpp index f04640e2..a9a723d8 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -955,12 +955,15 @@ void Launcher::OnEditMetadata(wxCommandEvent& event) { //Scan for installed plugins. BOOST_LOG_TRIVIAL(debug) << "Reading installed plugins' headers."; - for (fs::directory_iterator it(_game.DataPath()); it != fs::directory_iterator(); ++it) { - if (fs::is_regular_file(it->status()) && IsPlugin(it->path().string())) { - installed.push_back(loot::Plugin(_game, it->path().filename().string(), true)); + _game.LoadPlugins(true); + //Sort plugins into their load order. + list loadOrder; + _game.GetLoadOrder(loadOrder); + for (list::const_iterator it = loadOrder.begin(), itend = loadOrder.end(); it != itend; ++it) { + boost::unordered_map::const_iterator pos = _game.plugins.find(*it); - progDia->Pulse(); - } + if (pos != _game.plugins.end()) + installed.push_back(pos->second); } //Parse masterlist. @@ -1027,12 +1030,6 @@ void Launcher::OnEditMetadata(wxCommandEvent& event) { progDia->Pulse(); - //Sort into alphabetical order. - BOOST_LOG_TRIVIAL(debug) << "Sorting plugin list into alphabetical order."; - installed.sort(loot::alpha_sort); - - progDia->Pulse(); - //Set language. unsigned int lang; if (_settings["Language"])