Fixed masterlist date display when update fails.

This commit is contained in:
WrinklyNinja
2014-05-14 18:57:03 +01:00
parent 9ebe3de6c0
commit 9600456c2f
3 changed files with 39 additions and 11 deletions
+25 -8
View File
@@ -110,12 +110,12 @@ namespace loot {
return true;
}
std::string GetMasterlistRevision(const Game& game) {
std::pair<string, string> GetMasterlistRevision(const Game& game) {
if (!fs::exists(game.MasterlistPath().parent_path() / ".git")) {
return "Unknown: Git repository missing";
return pair<string, string>("Unknown: Git repository missing", "Unknown: Git repository missing");
}
else if (!fs::exists(game.MasterlistPath()))
return "N/A: No masterlist present";
return pair<string, string>("N/A: No masterlist present", "N/A: No masterlist present");
else {
/* Compares HEAD to the working dir.
1. Get an object for the masterlist in HEAD.
@@ -147,19 +147,36 @@ namespace loot {
BOOST_LOG_TRIVIAL(debug) << "Comparing files.";
if (are_files_equal(git_blob_rawcontent(git.blob), git_blob_rawsize(git.blob), mlist.data(), mlist.length())) {
char revision[10];
string revision, date;
//Need to get the HEAD object, because the individual file has a different SHA.
git_object_free(git.obj);
git.obj = NULL; //Just to be safe.
BOOST_LOG_TRIVIAL(trace) << "Getting HEAD object revision SHA.";
BOOST_LOG_TRIVIAL(info) << "Getting the Git object for the tree at HEAD.";
git.call(git_revparse_single(&git.obj, git.repo, "HEAD"));
git_oid_tostr(revision, 10, git_object_id(git.obj));
BOOST_LOG_TRIVIAL(trace) << "Getting the Git object ID.";
const git_oid * oid = git_object_id(git.obj);
BOOST_LOG_TRIVIAL(trace) << "Generating hex string for Git object ID.";
char sha1[10];
git_oid_tostr(sha1, 10, oid);
revision = sha1;
BOOST_LOG_TRIVIAL(trace) << "Getting date for Git object ID.";
git.call(git_commit_lookup(&git.commit, git.repo, oid));
git_time_t time = git_commit_time(git.commit);
boost::locale::date_time dateTime(time);
stringstream out;
out << boost::locale::as::ftime("%Y-%m-%d") << dateTime;
date = out.str();
git.free();
return string(revision);
return pair<string, string>(revision, date);
}
else {
git.free();
return "Unknown: Masterlist edited";
return pair<string, string>("Unknown: Masterlist edited", "Unknown: Masterlist edited");
}
}
}
+1 -1
View File
@@ -35,6 +35,6 @@ namespace loot {
std::pair<std::string, std::string> UpdateMasterlist(Game& game, std::list<Message>& parsingErrors, std::list<Plugin>& plugins, std::list<Message>& messages);
std::string GetMasterlistRevision(const Game& game);
std::pair<std::string, std::string> GetMasterlistRevision(const Game& game);
}
#endif
+13 -2
View File
@@ -120,7 +120,9 @@ struct masterlist_updater_parser {
_errors.push_back(loot::Message(loot::Message::error, (format(loc::translate("Masterlist update failed. Details: %1%")) % e.what()).str()));
//Try getting masterlist revision anyway.
try {
_revision = GetMasterlistRevision(_game);
pair<string, string> ret = GetMasterlistRevision(_game);
_revision = ret.first;
_date = ret.second;
}
catch (loot::error& e) {
BOOST_LOG_TRIVIAL(error) << "Masterlist revision check failed. Details: " << e.what();
@@ -131,7 +133,9 @@ struct masterlist_updater_parser {
else {
BOOST_LOG_TRIVIAL(debug) << "Getting masterlist revision";
try {
_revision = GetMasterlistRevision(_game);
pair<string, string> ret = GetMasterlistRevision(_game);
_revision = ret.first;
_date = ret.second;
}
catch (loot::error& e) {
BOOST_LOG_TRIVIAL(error) << "Masterlist revision check failed. Details: " << e.what();
@@ -165,6 +169,13 @@ struct masterlist_updater_parser {
else
_revision = loc::translate("No masterlist");
}
if (_date.empty()) {
if (fs::exists(_game.MasterlistPath()))
_date = loc::translate("Unknown");
else
_date = loc::translate("No masterlist");
}
}
bool _doUpdate;