From 567e4230188b0e3a01c72936e9d5a16727d80eb5 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 20 Dec 2014 19:56:14 +0000 Subject: [PATCH] Revert "Refactored userlist comparison code." This reverts commit 67fa220f1a8c18f203a254861473814c07b04801. --- src/backend/game.cpp | 40 ++++------------------------------------ src/backend/game.h | 12 +++++------- src/backend/git.cpp | 2 +- src/gui/editor.cpp | 23 +++++++++++++++-------- src/gui/editor.h | 10 ++++------ src/gui/main.cpp | 34 ++++++++++++++++++++++++++++------ 6 files changed, 57 insertions(+), 64 deletions(-) diff --git a/src/backend/game.cpp b/src/backend/game.cpp index c4426e05..61f8252b 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -85,7 +85,7 @@ namespace loot { // MetadataList member functions //------------------------------ - void MetadataList::Load(const boost::filesystem::path& filepath) { + void MetadataList::Load(boost::filesystem::path& filepath) { plugins.clear(); messages.clear(); @@ -103,7 +103,7 @@ namespace loot { BOOST_LOG_TRIVIAL(debug) << "File loaded successfully."; } - void MetadataList::Save(const boost::filesystem::path& filepath) { + void MetadataList::Save(boost::filesystem::path& filepath) { YAML::Emitter yout; yout.SetIndent(2); yout << YAML::BeginMap @@ -116,38 +116,6 @@ namespace loot { uout.close(); } - bool MetadataList::operator == (const MetadataList& rhs) const { - if (this->plugins.size() != rhs.plugins.size() || this->messages.size() != rhs.messages.size()) { - BOOST_LOG_TRIVIAL(info) << "Metadata edited for some plugin, new and old userlists differ in size."; - return false; - } - else { - for (const auto& rhsPlugin : rhs.plugins) { - const auto it = std::find(this->plugins.begin(), this->plugins.end(), rhsPlugin); - - if (it == this->plugins.end()) { - BOOST_LOG_TRIVIAL(info) << "Metadata added for plugin: " << it->Name(); - return false; - } - - if (!it->DiffMetadata(rhsPlugin).HasNameOnly()) { - BOOST_LOG_TRIVIAL(info) << "Metadata edited for plugin: " << it->Name(); - return false; - } - } - // Messages are compared exactly by the '==' operator, so there's no need to do a more - // fine-grained check. - for (const auto& rhsMessage : rhs.messages) { - const auto it = std::find(this->messages.begin(), this->messages.end(), rhsMessage); - - if (it == this->messages.end()) { - return false; - } - } - } - return true; - } - // Masterlist member functions //---------------------------- @@ -167,14 +135,14 @@ namespace loot { } } - std::string Masterlist::GetRevision(const boost::filesystem::path& path) { + std::string Masterlist::GetRevision(boost::filesystem::path& path) { if (revision.empty()) GetGitInfo(path); return revision; } - std::string Masterlist::GetDate(const boost::filesystem::path& path) { + std::string Masterlist::GetDate(boost::filesystem::path& path) { if (date.empty()) GetGitInfo(path); diff --git a/src/backend/game.h b/src/backend/game.h index de47ec9d..5ecfe6f2 100644 --- a/src/backend/game.h +++ b/src/backend/game.h @@ -55,10 +55,8 @@ namespace loot { class MetadataList { public: - void Load(const boost::filesystem::path& filepath); - void Save(const boost::filesystem::path& filepath); - - bool operator == (const MetadataList& rhs) const; //Compares content. + void Load(boost::filesystem::path& filepath); + void Save(boost::filesystem::path& filepath); std::list plugins; std::list messages; @@ -70,11 +68,11 @@ namespace loot { void Load(Game& game, const unsigned int language); //Handles update with load fallback. void Update(Game& game, const unsigned int language); - std::string GetRevision(const boost::filesystem::path& path); - std::string GetDate(const boost::filesystem::path& path); + std::string GetRevision(boost::filesystem::path& path); + std::string GetDate(boost::filesystem::path& path); private: - void GetGitInfo(const boost::filesystem::path& path); + void GetGitInfo(boost::filesystem::path& path); std::string revision; std::string date; diff --git a/src/backend/git.cpp b/src/backend/git.cpp index 8202403e..e28b0ff3 100644 --- a/src/backend/git.cpp +++ b/src/backend/git.cpp @@ -109,7 +109,7 @@ namespace loot { return git_repository_open_ext(NULL, path.string().c_str(), GIT_REPOSITORY_OPEN_NO_SEARCH, NULL) == 0; } - void Masterlist::GetGitInfo(const boost::filesystem::path& path) { + void Masterlist::GetGitInfo(boost::filesystem::path& path) { if (!fs::exists(path.parent_path() / ".git")) { revision = "Unknown: Git repository missing"; date = "Unknown: Git repository missing"; diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index 1d9d78c1..7b45d834 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -1041,10 +1041,8 @@ void EditorPanel::ApplyCurrentEdits() { ApplyEdits(currentPlugin); } -loot::MetadataList EditorPanel::GetNewUserlist() const { - loot::MetadataList newUserlist; - newUserlist.plugins = _editedPlugins; - return newUserlist; +const std::list& EditorPanel::GetNewUserlist() const { + return _editedPlugins; } loot::Plugin EditorPanel::GetMasterData(const wxString& plugin) const { @@ -1199,7 +1197,7 @@ void MiniEditor::OnResize(wxSizeEvent& event) { event.Skip(); } -loot::MetadataList MiniEditor::GetNewUserlist() const { +const std::list& MiniEditor::GetNewUserlist() const { return editorPanel->GetNewUserlist(); } @@ -1208,7 +1206,7 @@ loot::MetadataList MiniEditor::GetNewUserlist() const { // Full Editor Class /////////////////////////////////// -FullEditor::FullEditor(wxWindow *parent, const wxString& title, wxPoint pos, wxSize size, const boost::filesystem::path& userlistPath, const std::list& basePlugins, std::list& editedPlugins, const unsigned int language, const loot::Game& game, YAML::Node &settings) : wxFrame(parent, wxID_ANY, title, pos, size), _userlistPath(userlistPath), _settings(settings) { +FullEditor::FullEditor(wxWindow *parent, const wxString& title, wxPoint pos, wxSize size, const std::string userlistPath, const std::list& basePlugins, std::list& editedPlugins, const unsigned int language, const loot::Game& game, YAML::Node &settings) : wxFrame(parent, wxID_ANY, title, pos, size), _userlistPath(userlistPath), _settings(settings) { //Set up content. editorPanel = new EditorPanel(this, basePlugins, editedPlugins, language, game); applyBtn = new wxButton(this, BUTTON_Apply, translate("Save Changes")); @@ -1247,8 +1245,17 @@ void FullEditor::OnQuit(wxCommandEvent& event) { BOOST_LOG_TRIVIAL(debug) << "Saving metadata edits to userlist."; - loot::MetadataList userlist = editorPanel->GetNewUserlist(); - userlist.Save(_userlistPath); + //Save edits to userlist. + YAML::Emitter yout; + yout.SetIndent(2); + yout << YAML::BeginMap + << YAML::Key << "plugins" << YAML::Value << editorPanel->GetNewUserlist() + << YAML::EndMap; + + boost::filesystem::path p(_userlistPath); + loot::ofstream out(p); + out << yout.c_str(); + out.close(); } Close(); } diff --git a/src/gui/editor.h b/src/gui/editor.h index ef18a0cc..21e1971a 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -26,9 +26,7 @@ #include "ids.h" #include "misc.h" - #include "../backend/metadata.h" -#include "../backend/game.h" #include #include @@ -71,7 +69,7 @@ public: void SetSimpleView(bool on = true); void ApplyCurrentEdits(); - loot::MetadataList GetNewUserlist() const; + const std::list& GetNewUserlist() const; void OnPluginSelect(wxListEvent& event); void OnPluginListRightClick(wxListEvent& event); @@ -136,7 +134,7 @@ public: void OnApply(wxCommandEvent& event); void OnResize(wxSizeEvent& event); - loot::MetadataList GetNewUserlist() const; + const std::list& GetNewUserlist() const; private: EditorPanel * editorPanel; wxStaticText * descText; @@ -146,7 +144,7 @@ private: class FullEditor : public wxFrame { public: - FullEditor(wxWindow *parent, const wxString& title, wxPoint pos, wxSize size, const boost::filesystem::path& userlistPath, const std::list& basePlugins, std::list& editedPlugins, const unsigned int language, const loot::Game& game, YAML::Node &settings); + FullEditor(wxWindow *parent, const wxString& title, wxPoint pos, wxSize size, const std::string userlistPath, const std::list& basePlugins, std::list& editedPlugins, const unsigned int language, const loot::Game& game, YAML::Node &settings); void OnQuit(wxCommandEvent& event); void OnClose(wxCloseEvent &event); @@ -155,7 +153,7 @@ private: wxButton * applyBtn; wxButton * cancelBtn; - const boost::filesystem::path _userlistPath; + const std::string _userlistPath; YAML::Node& _settings; }; #endif diff --git a/src/gui/main.cpp b/src/gui/main.cpp index dfde8c53..5021040d 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -259,7 +259,7 @@ bool LOOT::OnInit() { try { gameIndex = SelectGame(_settings, _games, target); } - catch (exception &) { + catch (exception &e) { BOOST_LOG_TRIVIAL(error) << "None of the supported games were detected."; wxMessageBox( translate("Error: None of the supported games were detected."), @@ -632,13 +632,13 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { */ + //Check for back-edges, then perform a topological sort. list plugins; try { bool applyLoadOrder = false; do { - // Perform sort. plugins = _games[_currentGame].Sort(lang, messages, progressCallback); progDia->Destroy(); @@ -653,11 +653,10 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { GetWindowSizePos(_settings["windows"]["editor"], pos, size); } - // Display mini editor. MiniEditor editor(this, translate("LOOT: Calculated Load Order"), pos, size, plugins, _games[_currentGame].userlist.plugins, _games[_currentGame]); long ret = editor.ShowModal(); - MetadataList newUserlist = editor.GetNewUserlist(); + const std::list& newUserlist = editor.GetNewUserlist(); //Record window settings. YAML::Node node; @@ -668,11 +667,34 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { _settings["windows"]["editor"] = node; + //Need to determine if any new edits have been made. + bool haveNewEdits = false; + if (newUserlist.size() != _games[_currentGame].userlist.plugins.size()) { + BOOST_LOG_TRIVIAL(info) << "Metadata edited for some plugin, new and old userlists differ in size."; + haveNewEdits = true; + } + else { + for (const auto& newEdit : newUserlist) { + const auto it = std::find(_games[_currentGame].userlist.plugins.begin(), _games[_currentGame].userlist.plugins.end(), newEdit); + if (it == _games[_currentGame].userlist.plugins.end()) { + BOOST_LOG_TRIVIAL(info) << "Metadata added for plugin: " << it->Name(); + haveNewEdits = true; + break; + } + + if (!it->DiffMetadata(newEdit).HasNameOnly()) { + BOOST_LOG_TRIVIAL(info) << "Metadata edited for plugin: " << it->Name(); + haveNewEdits = true; + break; + } + } + } + if (ret != wxID_APPLY) { applyLoadOrder = false; break; } - else if (_games[_currentGame].userlist == newUserlist) { + else if (!haveNewEdits) { applyLoadOrder = true; break; } @@ -681,7 +703,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { progDia = new wxProgressDialog(translate("LOOT: Working..."), translate("Recalculating load order..."), 1000, this, wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_ELAPSED_TIME); //User accepted edits, now apply them, then loop. - _games[_currentGame].userlist = newUserlist; + _games[_currentGame].userlist.plugins = newUserlist; //Save edits to userlist. _games[_currentGame].userlist.Save(_games[_currentGame].UserlistPath());