From 8435fb2566d49f01cf800dc71e670a94b957d114 Mon Sep 17 00:00:00 2001 From: Sude Date: Tue, 18 Mar 2014 18:43:53 +0200 Subject: [PATCH] Use duplicate handler for patches --- src/api.cpp | 34 ++++++++++++++++++++++++++++++++++ src/downloader.cpp | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/src/api.cpp b/src/api.cpp index 7a09cc0..2117cb9 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -391,6 +391,23 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int { Json::Value patch = patchnode[index]; + // Check for duplicate patches in different languages and add languageId of duplicate patch to the original patch + if (useDuplicateHandler) + { + bool bDuplicate = false; + for (unsigned int j = 0; j < game.patches.size(); ++j) + { + if (game.patches[j].path == patch["link"].asString()) + { + game.patches[j].language |= GlobalConstants::LANGUAGES[i].languageId; // Add language code to patch + bDuplicate = true; + break; + } + } + if (bDuplicate) + continue; + } + game.patches.push_back( gameFile( false, /* patches don't have "updated" flag */ patch["id"].isInt() ? std::to_string(patch["id"].asInt()) : patch["id"].asString(), @@ -404,6 +421,23 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int } else // Patch is a single file { + // Check for duplicate patches in different languages and add languageId of duplicate patch to the original patch + if (useDuplicateHandler) + { + bool bDuplicate = false; + for (unsigned int j = 0; j < game.patches.size(); ++j) + { + if (game.patches[j].path == patchnode["link"].asString()) + { + game.patches[j].language |= GlobalConstants::LANGUAGES[i].languageId; // Add language code to patch + bDuplicate = true; + break; + } + } + if (bDuplicate) + continue; + } + game.patches.push_back( gameFile( false, /* patches don't have "updated" flag */ patchnode["id"].isInt() ? std::to_string(patchnode["id"].asInt()) : patchnode["id"].asString(), diff --git a/src/downloader.cpp b/src/downloader.cpp index 326c561..1216179 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -312,10 +312,18 @@ void Downloader::listGames() std::cout << "patches: " << std::endl; for (unsigned int j = 0; j < games[i].patches.size(); ++j) { + std::string languages; + for (unsigned int k = 0; k < GlobalConstants::LANGUAGES.size(); k++) // Check which languages the installer supports + { + if (games[i].installers[j].language & GlobalConstants::LANGUAGES[k].languageId) + languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].languageString; + } + std::cout << "\tid: " << games[i].patches[j].id << std::endl << "\tname: " << games[i].patches[j].name << std::endl << "\tpath: " << games[i].patches[j].path << std::endl << "\tsize: " << games[i].patches[j].size << std::endl + << "\tlanguage: " << languages << std::endl << std::endl; } }