diff --git a/src/backend/game.cpp b/src/backend/game.cpp index 96d2fb9f..115ae054 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -480,6 +480,43 @@ namespace loot { lo_destroy_handle(gh); } + void Game::RedatePlugins() { + if (id != tes5) + return; + + list loadorder; + GetLoadOrder(loadorder); + + if (!loadorder.empty()) { + + time_t lastTime, thisTime; + fs::path filepath = DataPath() / loadorder.begin()->Name(); + 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) { + + filepath = DataPath() / it->Name(); + if (!fs::exists(filepath) && fs::exists(filepath.string() + ".ghost")) + filepath += ".ghost"; + + time_t thisTime = fs::last_write_time(filepath); + BOOST_LOG_TRIVIAL(info) << "Current timestamp for \"" << filepath.filename().string() << "\": " << thisTime; + if (thisTime >= lastTime) { + lastTime = thisTime; + BOOST_LOG_TRIVIAL(trace) << "No need to redate \"" << filepath.filename().string() << "\"."; + } + else { + lastTime += 60; + fs::last_write_time(filepath, lastTime); //Space timestamps by a minute. + BOOST_LOG_TRIVIAL(info) << "Redated \"" << filepath.filename().string() << "\" to: " << lastTime; + } + } + } + } + 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 839dc3fd..4372d795 100644 --- a/src/backend/game.h +++ b/src/backend/game.h @@ -65,7 +65,6 @@ namespace loot { std::string RepoURL() const; std::string RepoBranch() const; - boost::filesystem::path GamePath() const; boost::filesystem::path DataPath() const; boost::filesystem::path MasterlistPath() const; @@ -75,9 +74,10 @@ namespace loot { bool IsActive(const std::string& plugin) const; void GetLoadOrder(std::list& loadOrder) const; - void SetLoadOrder(const std::list& loadOrder) const; + void SetLoadOrder(const std::list& loadOrder) const; //Modifies game load order, even though const. void RefreshActivePluginsList(); + void RedatePlugins(); //Caches for condition results, active plugins and CRCs. boost::unordered_map conditionCache; //Holds lowercased strings. @@ -91,7 +91,7 @@ namespace loot { static const unsigned int fo3 = 3; static const unsigned int fonv = 4; private: - unsigned id; + unsigned int id; std::string _name; std::string _masterFile; diff --git a/src/gui/main.cpp b/src/gui/main.cpp index a254adce..18b58e55 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -1082,50 +1082,12 @@ void Launcher::OnRedatePlugins(wxCommandEvent& event) { if (dia->ShowModal() == wxID_YES) { BOOST_LOG_TRIVIAL(debug) << "Redating plugins."; - list loadorder; try { - _game.GetLoadOrder(loadorder); - } catch (loot::error& e) { - BOOST_LOG_TRIVIAL(error) << "Failed to get load order. " << e.what(); + _game.RedatePlugins(); + } catch (std::exception& e) { + BOOST_LOG_TRIVIAL(error) << "Failed to redate plugins. " << e.what(); wxMessageBox( - FromUTF8(format(loc::translate("Error: Failed to get load order. %1%")) % e.what()), - translate("LOOT: Error"), - wxOK | wxICON_ERROR, - this); - } - - try { - if (!loadorder.empty()) { - - time_t lastTime, thisTime; - fs::path filepath = _game.DataPath() / loadorder.begin()->Name(); - 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) { - - filepath = _game.DataPath() / it->Name(); - if (!fs::exists(filepath) && fs::exists(filepath.string() + ".ghost")) - filepath += ".ghost"; - - time_t thisTime = fs::last_write_time(filepath); - BOOST_LOG_TRIVIAL(info) << "Current timestamp for \"" << filepath.filename().string() << "\": " << thisTime; - if (thisTime >= lastTime) { - lastTime = thisTime; - BOOST_LOG_TRIVIAL(trace) << "No need to redate \"" << filepath.filename().string() << "\"."; - } else { - lastTime += 60; - fs::last_write_time(filepath, lastTime); //Space timestamps by a minute. - BOOST_LOG_TRIVIAL(info) << "Redated \"" << filepath.filename().string() << "\" to: " << lastTime; - } - } - } - } catch(fs::filesystem_error& e) { - BOOST_LOG_TRIVIAL(error) << "Failed to set plugin timestamps. " << e.what(); - wxMessageBox( - FromUTF8(format(loc::translate("Error: Failed to set plugin timestamps. %1%")) % e.what()), + FromUTF8(format(loc::translate("Error: Failed to redate plugins. %1%")) % e.what()), translate("LOOT: Error"), wxOK | wxICON_ERROR, this);