From 824084909b6038e7d14174338d2a1dddd2c447f4 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Mon, 9 Sep 2013 17:10:21 +0100 Subject: [PATCH] Tidied up plugin reading, removed extra delete causing crashes. --- src/backend/metadata.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index 9abff60c..6cee6d4e 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -262,14 +262,9 @@ namespace boss { Plugin::Plugin(boss::Game& game, const std::string& n, const bool headerOnly) : name(n), enabled(true), priority(0) { - //If the name passed ends in '.ghost', that should be trimmed. - if (boost::iends_with(name, ".ghost")) - name = name.substr(0, name.length() - 6); - // Get data from file contents using libespm. Assumes libespm has already been initialised. + BOOST_LOG_TRIVIAL(trace) << "Opening plugin with libespm..."; boost::filesystem::path filepath = game.DataPath() / name; - if (!boost::filesystem::exists(filepath) && boost::filesystem::exists(filepath.string() + ".ghost")) - filepath += ".ghost"; espm::File * file; if (game.Id() == g_game_tes4) file = new espm::tes4::File(filepath, game.espm_settings, false, headerOnly); @@ -280,25 +275,33 @@ namespace boss { else file = new espm::fonv::File(filepath, game.espm_settings, false, headerOnly); + //If the name passed ends in '.ghost', that should be trimmed. + BOOST_LOG_TRIVIAL(trace) << "Trimming '.ghost' extension."; + if (boost::iends_with(name, ".ghost")) + name = name.substr(0, name.length() - 6); + + BOOST_LOG_TRIVIAL(trace) << "Checking to see if plugin is a master or not."; isMaster = file->isMaster(game.espm_settings); + + BOOST_LOG_TRIVIAL(trace) << "Getting the plugin's masters."; masters = file->getMasters(); crc = file->crc; game.crcCache.insert(pair(n, crc)); + BOOST_LOG_TRIVIAL(trace) << "Getting the plugin's FormIDs."; vector records = file->getFormIDs(); vector plugins = masters; plugins.push_back(name); - for (vector::const_iterator it = records.begin(),endIt = records.end(); it != endIt; ++it) - formIDs.insert(FormID(plugins, *it)); - - //Calculate how many records are override records. - for (set::const_iterator it = formIDs.begin(), endIt=formIDs.end(); it != endIt; ++it) { - if (!boost::iequals(it->Plugin(), name)) + for (vector::const_iterator it = records.begin(),endIt = records.end(); it != endIt; ++it) { + FormID fid = FormID(plugins, *it); + formIDs.insert(fid); + if (!boost::iequals(fid.Plugin(), name)) ++numOverrideRecords; } //Also read Bash Tags applied and version string in description. + BOOST_LOG_TRIVIAL(trace) << "Reading the plugin description."; string text = file->getDescription(); delete file; @@ -307,6 +310,7 @@ namespace boss { begin = text.begin(); end = text.end(); + BOOST_LOG_TRIVIAL(trace) << "Attempting to read the plugin version from its description."; for(int j = 0; j < 7 && version.empty(); j++) { boost::smatch what; while (boost::regex_search(begin, end, what, version_checks[j])) { @@ -322,6 +326,7 @@ namespace boss { } } + BOOST_LOG_TRIVIAL(trace) << "Attempting to extract Bash Tags from the description."; size_t pos1 = text.find("{{BASH:"); if (pos1 == string::npos) return; @@ -340,8 +345,6 @@ namespace boss { for (int i=0,max=bashTags.size(); i