summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-29 17:25:29 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-02-29 17:25:29 +0100
commit2e60491ceb0548b0bea93207c13b974d6a6cf5cc (patch)
tree43ea8aefa4aa1646df82a5163b9cdae0a39df48e /src/gui
parentdd1db3753ecf8a4d782aee1f518759763d8caf87 (diff)
downloadMana-2e60491ceb0548b0bea93207c13b974d6a6cf5cc.tar.gz
Mana-2e60491ceb0548b0bea93207c13b974d6a6cf5cc.tar.bz2
Mana-2e60491ceb0548b0bea93207c13b974d6a6cf5cc.tar.xz
Mana-2e60491ceb0548b0bea93207c13b974d6a6cf5cc.zip
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.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/updaterwindow.cpp34
1 files changed, 15 insertions, 19 deletions
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<UpdateFile> 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<UpdateFile> loadTxtFile(const std::string &fileName)
{
std::vector<UpdateFile> 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<UpdateFile> 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++;