mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Refactored plugin redating code.
This commit is contained in:
@@ -480,6 +480,43 @@ namespace loot {
|
||||
lo_destroy_handle(gh);
|
||||
}
|
||||
|
||||
void Game::RedatePlugins() {
|
||||
if (id != tes5)
|
||||
return;
|
||||
|
||||
list<loot::Plugin> 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<loot::Plugin>::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 {
|
||||
|
||||
+3
-3
@@ -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<Plugin>& loadOrder) const;
|
||||
void SetLoadOrder(const std::list<Plugin>& loadOrder) const;
|
||||
void SetLoadOrder(const std::list<Plugin>& loadOrder) const; //Modifies game load order, even though const.
|
||||
|
||||
void RefreshActivePluginsList();
|
||||
void RedatePlugins();
|
||||
|
||||
//Caches for condition results, active plugins and CRCs.
|
||||
boost::unordered_map<std::string, bool> 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;
|
||||
|
||||
|
||||
+4
-42
@@ -1082,50 +1082,12 @@ void Launcher::OnRedatePlugins(wxCommandEvent& event) {
|
||||
|
||||
if (dia->ShowModal() == wxID_YES) {
|
||||
BOOST_LOG_TRIVIAL(debug) << "Redating plugins.";
|
||||
list<loot::Plugin> 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<loot::Plugin>::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);
|
||||
|
||||
Reference in New Issue
Block a user