From 2e60491ceb0548b0bea93207c13b974d6a6cf5cc Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 29 Feb 2024 17:25:29 +0100 Subject: Re-download updates when their checksum no longer matches The Mana World currently likes to just update its "TMW.zip" file, whereas updates were always given unique names in the past. With this change, the client checks the Adler32 checksum to know when it should re-download an update file. This matches the behavior of ManaPlus commit 96150f1aeacf55d311c41ffe12d9e754b1cda001. --- src/gui/updaterwindow.cpp | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/gui') diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 2861f973..54ce8aeb 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -70,10 +70,10 @@ std::vector loadXMLFile(const std::string &fileName) continue; UpdateFile file; - file.name = XML::getProperty(fileNode, "file", ""); - file.hash = XML::getProperty(fileNode, "hash", ""); + file.name = XML::getProperty(fileNode, "file", std::string()); + file.hash = XML::getProperty(fileNode, "hash", std::string()); file.type = XML::getProperty(fileNode, "type", "data"); - file.desc = XML::getProperty(fileNode, "description", ""); + file.desc = XML::getProperty(fileNode, "description", std::string()); file.required = XML::getProperty(fileNode, "required", "yes") == "yes"; files.push_back(file); @@ -86,13 +86,14 @@ std::vector loadTxtFile(const std::string &fileName) { std::vector files; std::ifstream fileHandler; - fileHandler.open(fileName.c_str(), std::ios::in); + fileHandler.open(fileName, std::ios::in); if (fileHandler.is_open()) { while (fileHandler.good()) { - char name[256], hash[50]; + char name[256]; + char hash[50]; fileHandler.getline(name, 256, ' '); fileHandler.getline(hash, 50); @@ -101,7 +102,6 @@ std::vector loadTxtFile(const std::string &fileName) thisFile.hash = hash; thisFile.type = "data"; thisFile.required = true; - thisFile.desc.clear(); if (!thisFile.name.empty()) files.push_back(thisFile); @@ -459,35 +459,31 @@ void UpdaterWindow::logic() { if (mUpdateIndex < mUpdateFiles.size()) { - UpdateFile thisFile = mUpdateFiles[mUpdateIndex]; + const UpdateFile &thisFile = mUpdateFiles[mUpdateIndex]; if (!thisFile.required) { - // This statement checks to see if the file type is music, and if download-music is true - // If it fails, this statement returns true, and results in not downloading the file - // Else it will ignore the break, and download the file. - if ( !(thisFile.type == "music" && config.getBoolValue("download-music")) ) + if (!(thisFile.type == "music" && config.getBoolValue("download-music"))) { mUpdateIndex++; break; } } mCurrentFile = thisFile.name; - std::string checksum; - checksum = thisFile.hash; - std::stringstream ss(checksum); + std::stringstream ss(thisFile.hash); ss >> std::hex >> mCurrentChecksum; - std::ifstream temp( - (mUpdatesDir + "/" + mCurrentFile).c_str()); + std::string filename = mUpdatesDir + "/" + mCurrentFile; + FILE *file = fopen(filename.c_str(), "r+b"); - if (!temp.is_open()) + if (!file || Net::Download::fadler32(file) != mCurrentChecksum) { - temp.close(); + if (file) + fclose(file); download(); } else { - temp.close(); + fclose(file); logger->log("%s already here", mCurrentFile.c_str()); } mUpdateIndex++; -- cgit v1.2.3-70-g09d2