Skip to content

Commit b26e8b2

Browse files
committed
Tweak mod update process to always install mods that aren't installed yet (fixes some cases involving version-less mods)
Also add some more logging :)
1 parent 795a8d5 commit b26e8b2

1 file changed

Lines changed: 62 additions & 29 deletions

File tree

include/launcher/modupdater.h

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,29 @@ class ModUpdateDialog : public wxDialog {
131131
bool ParseMetadata(const fs::path& metadataPath, std::string& outName, std::string& outVersion) {
132132
try {
133133
std::ifstream file(metadataPath, std::ios::binary);
134-
if (!file)
135-
return false;
134+
if (!file) {
135+
Logger::Error("[MODUPDATER::ParseMetadata] Failed to open `%s`: %s\n", metadataPath.string().c_str(), std::strerror(errno));
136+
return false;
137+
}
136138
rapidxml::file<> xmlFile(file);
137139
rapidxml::xml_document<> doc;
138140
doc.parse<0>(xmlFile.data());
139141
if (auto* root = doc.first_node("metadata")) {
140142
auto* nodeName = root->first_node("directory");
141143
auto* nodeVersion = root->first_node("version");
142144
outName = nodeName ? nodeName->value() : "";
143-
if ((nodeVersion == nullptr) ||(nodeVersion == 0)) { //fuck you minecraft explosions mod, you degenerate fuck!
144-
outVersion = "";
145-
}
146-
else {
147-
outVersion = nodeVersion ? nodeVersion->value() : "";
148-
}
145+
// Shoutout to minecraft explosions mod and Sacrilege (on its initial release)
146+
outVersion = nodeVersion ? nodeVersion->value() : "0";
147+
if (outVersion.empty()) {
148+
outVersion = "0";
149+
}
149150
return true;
150-
}
151+
} else {
152+
Logger::Error("[MODUPDATER::ParseMetadata] Failed to parse metadata from `%s`\n", metadataPath.string().c_str());
153+
}
151154
}
152-
catch (const rapidxml::parse_error&) {
155+
catch (const rapidxml::parse_error& err) {
156+
Logger::Error("[MODUPDATER::ParseMetadata] XML parse error parsing `%s`: %s\n", metadataPath.string().c_str(), err.what());
153157
}
154158
return false;
155159
}
@@ -158,24 +162,30 @@ class ModUpdateDialog : public wxDialog {
158162
bool ParseMetadataId(const fs::path& xmlPath, uint64_t& outId) {
159163
try {
160164
std::ifstream file(xmlPath, std::ios::binary);
161-
if (!file)
162-
return false;
165+
if (!file) {
166+
Logger::Error("[MODUPDATER::ParseMetadataId] Failed to open `%s`: %s\n", xmlPath.string().c_str(), std::strerror(errno));
167+
return false;
168+
}
163169
rapidxml::file<> xmlFile(file);
164170
rapidxml::xml_document<> doc;
165171
doc.parse<0>(xmlFile.data());
166172

167173
auto* root = doc.first_node("metadata");
168-
if (!root) return false;
174+
if (!root) {
175+
Logger::Error("[MODUPDATER::ParseMetadataId] Failed to parse metadata from `%s`\n", xmlPath.string().c_str());
176+
return false;
177+
}
169178

170179
auto* idNode = root->first_node("id");
171180
if (!idNode || !idNode->value()) return false;
172181

173182
outId = std::stoull(idNode->value());
174183
return true;
175184
}
176-
catch (...) {
177-
return false;
185+
catch (const std::exception& err) {
186+
Logger::Error("[MODUPDATER::ParseMetadataId] Caught exception while parsing `%s`: %s\n", xmlPath.string().c_str(), err.what());
178187
}
188+
return false;
179189
}
180190

181191
void CopyDir(const fs::path& src, const fs::path& dst) {
@@ -226,9 +236,9 @@ class ModUpdateDialog : public wxDialog {
226236
}
227237
}
228238
catch (...) {
229-
if (a != b) {
230-
return -2;
231-
}
239+
if (a != b) {
240+
return -2;
241+
}
232242
}
233243
return 0;
234244
}
@@ -319,28 +329,51 @@ class ModUpdateDialog : public wxDialog {
319329
fs::path installedFolder = targetModsDir / (cacheName + "_" + std::to_string(id));
320330
std::string installedVersion = "0";
321331
fs::path installedMetadata = installedFolder / "metadata.xml";
322-
if (fs::exists(installedMetadata)) {
332+
333+
bool installationExists = fs::exists(installedMetadata);
334+
bool shouldUpdate = !installationExists;
335+
336+
if (installationExists) {
323337
std::string inName, inVersion;
324338
if (ParseMetadata(installedMetadata, inName, inVersion))
325-
installedVersion = inVersion.empty() ? "0" : inVersion;
339+
installedVersion = inVersion;
340+
int cmp = CompareVersions(installedVersion, cacheVersion);
341+
if (cmp < 0) {
342+
if (cmp == -2) {
343+
PostProgressEvent(overallPct, "ERROR Nonnumeric Mod Version for " + cacheName + " assuming outdated...");
344+
}
345+
shouldUpdate = true;
346+
}
347+
348+
if (!shouldUpdate) {
349+
if (fs::exists(installedFolder / "Unfinished.it")) {
350+
Logger::Info("[MODUPDATER] Updating `%s` due to presence of `Unfinished.it`\n", cacheName.c_str());
351+
shouldUpdate = true;
352+
} else if (fs::exists(installedFolder / "Update.it")) {
353+
Logger::Info("[MODUPDATER] Updating `%s` due to presence of `Update.it`\n", cacheName.c_str());
354+
shouldUpdate = true;
355+
}
356+
}
326357
}
327358

328-
int cmp = CompareVersions(installedVersion, cacheVersion);
329-
if ((cmp < 0) || (fs::exists(installedFolder / "Unfinished.it") || fs::exists(installedFolder / "Update.it"))) {
330-
if (cmp == -2) {
331-
PostProgressEvent(overallPct, "ERROR Nonnumeric Mod Version for " + cacheName + " assuming outdated...");
332-
}
333-
PostProgressEvent(overallPct,"Updating " + cacheName + " (" + installedVersion + " -> " + cacheVersion + ")...");
359+
if (shouldUpdate) {
360+
if (!installationExists) {
361+
PostProgressEvent(overallPct, "Installing " + cacheName + " (version " + cacheVersion + ")...");
362+
} else {
363+
PostProgressEvent(overallPct, "Updating " + cacheName + " (" + installedVersion + " -> " + cacheVersion + ")...");
364+
}
365+
334366
try {
335367
std::ofstream(installedFolder / "Unfinished.it"); //there was some oddc ase of going back and forth between vanilla and rgon with unfinished mods so I still need to use this :(
336368
CopyDir(cachePath, installedFolder);
337369
fs::remove(installedFolder / "Unfinished.it");
338370
fs::remove(installedFolder / "Update.it"); //vanilla can still shove this shit in if interrumpted, we dont even use this here since we just copy the updated metadata.xml last....which makes unfinished.it pointless.
339371
PostProgressEvent(overallPct,"DONE: Updated " + cacheName + " to version " + cacheVersion);
340372
}
341-
catch (...) {
342-
PostProgressEvent(overallPct,"ERROR copying " + cacheName);
343-
}
373+
catch (const std::exception& err) {
374+
Logger::Error("[MODUPDATER] Caught exception while updating `%s`: %s\n", cacheName.c_str(), err.what());
375+
PostProgressEvent(overallPct, "ERROR copying " + cacheName);
376+
}
344377
}
345378

346379
//SteamAPI_RunCallbacks(); //Not needed anymore but leaving it here if I ever rework this shit to use it again (this is needed here if you are getting mod info from steam, because the steamapi needs this to be called in order to actually run the fucking steam callbacks, it's mental)

0 commit comments

Comments
 (0)