From 05df996b1292390bb66292ab5943a41d8a1213a9 Mon Sep 17 00:00:00 2001 From: Dominik Kreutzer Date: Sun, 28 May 2023 23:35:32 +0200 Subject: [PATCH] Correctly create empty files during Galaxy install Empty files have no chunks and were therefore skipped when installing. Some games require these empty files to function correctly. --- src/downloader.cpp | 10 +++++++++- src/galaxyapi.cpp | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/downloader.cpp b/src/downloader.cpp index d66d3f7..e24af2b 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -4023,7 +4023,7 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con if (filesize == item.totalSizeUncompressed) { // File is same size - if (Util::getFileHash(path.string(), RHASH_MD5) == item.md5) + if (item.totalSizeUncompressed == 0 || Util::getFileHash(path.string(), RHASH_MD5) == item.md5) { msgQueue.push(Message(path.string() + ": OK", MSGTYPE_SUCCESS, msg_prefix, MSGLEVEL_DEFAULT)); continue; @@ -4125,6 +4125,14 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con bool bChunkFailure = false; std::time_t timestamp = -1; + // Handle empty files + if (item.chunks.empty()) + { + // Create empty file + std::ofstream ofs(path.string(), std::ofstream::out | std::ofstream::binary); + if (ofs) + ofs.close(); + } for (unsigned int j = start_chunk; j < item.chunks.size(); ++j) { // Refresh Galaxy login if token is expired diff --git a/src/galaxyapi.cpp b/src/galaxyapi.cpp index 7ab8b2e..be83b12 100644 --- a/src/galaxyapi.cpp +++ b/src/galaxyapi.cpp @@ -258,7 +258,7 @@ std::vector galaxyAPI::getDepotItemsVector(const std::string& h for (unsigned int i = 0; i < json["depot"]["items"].size(); ++i) { - if (!json["depot"]["items"][i]["chunks"].empty()) + if (json["depot"]["items"][i]["chunks"].isArray()) { galaxyDepotItem item; item.totalSizeCompressed = 0; @@ -287,6 +287,8 @@ std::vector galaxyAPI::getDepotItemsVector(const std::string& h item.md5 = json["depot"]["items"][i]["md5"].asString(); else if (json["depot"]["items"][i]["chunks"].size() == 1) item.md5 = json["depot"]["items"][i]["chunks"][0]["md5"].asString(); + else + item.md5 = std::string(); items.push_back(item); }