diff --git a/include/api.h b/include/api.h index 762d449..4a975d6 100644 --- a/include/api.h +++ b/include/api.h @@ -83,7 +83,7 @@ class API std::string getResponseOAuth(const std::string& url); int getUserDetails(); int getGames(); - gameDetails getGameDetails(const std::string& game_name, const unsigned int& type = GlobalConstants::PLATFORM_WINDOWS, const unsigned int& lang = GlobalConstants::LANGUAGE_EN); + gameDetails getGameDetails(const std::string& game_name, const unsigned int& type = GlobalConstants::PLATFORM_WINDOWS, const unsigned int& lang = GlobalConstants::LANGUAGE_EN, const bool& useDuplicateHandler = false); std::string getInstallerLink(const std::string& game_name, const std::string& id); std::string getExtraLink(const std::string& game_name, const std::string& id); std::string getPatchLink(const std::string& game_name, const std::string& id); diff --git a/include/config.h b/include/config.h index e266794..688884a 100644 --- a/include/config.h +++ b/include/config.h @@ -33,6 +33,7 @@ class Config bool bVerifyPeer; bool bCheckOrphans; bool bCheckStatus; + bool bDuplicateHandler; std::string sGameRegex; std::string sDirectory; std::string sXMLFile; diff --git a/main.cpp b/main.cpp index 4912296..98526ac 100644 --- a/main.cpp +++ b/main.cpp @@ -78,6 +78,7 @@ int main(int argc, char *argv[]) bool bInsecure = false; bool bNoColor = false; bool bNoUnicode = false; + bool bNoDuplicateHandler = false; desc.add_options() ("help,h", "Print help message") ("login", bpo::value(&config.bLogin)->zero_tokens()->default_value(false), "Login") @@ -102,6 +103,7 @@ int main(int argc, char *argv[]) ("no-remote-xml", bpo::value(&config.bNoRemoteXML)->zero_tokens()->default_value(false), "Don't use remote XML for repair") ("no-unicode", bpo::value(&bNoUnicode)->zero_tokens()->default_value(false), "Don't use Unicode in the progress bar") ("no-color", bpo::value(&bNoColor)->zero_tokens()->default_value(false), "Don't use coloring in the progress bar") + ("no-duplicate-handling", bpo::value(&bNoDuplicateHandler)->zero_tokens()->default_value(false), "Don't use duplicate handler for installers\nDuplicate installers from different languages are handled separately") ("verbose", bpo::value(&config.bVerbose)->zero_tokens()->default_value(false), "Print lots of information") ("insecure", bpo::value(&bInsecure)->zero_tokens()->default_value(false), "Don't verify authenticity of SSL certificates") ("timeout", bpo::value(&config.iTimeout)->default_value(10), "Set timeout for connection\nMaximum time in seconds that connection phase is allowed to take") @@ -150,6 +152,7 @@ int main(int argc, char *argv[]) config.bVerifyPeer = !bInsecure; config.bColor = !bNoColor; config.bUnicode = !bNoUnicode; + config.bDuplicateHandler = !bNoDuplicateHandler; } catch (std::exception& e) { diff --git a/src/api.cpp b/src/api.cpp index f82c3b7..8d8074c 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -264,7 +264,7 @@ std::string API::getResponseOAuth(const std::string& url) return response; } -gameDetails API::getGameDetails(const std::string& game_name, const unsigned int& type, const unsigned int& lang) +gameDetails API::getGameDetails(const std::string& game_name, const unsigned int& type, const unsigned int& lang, const bool& useDuplicateHandler) { std::string url; gameDetails game; @@ -296,7 +296,8 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int { if (lang & GlobalConstants::LANGUAGES[j].languageId) { - installers.push_back(std::make_pair(root["game"][installer+GlobalConstants::LANGUAGES[j].languageCode],GlobalConstants::LANGUAGES[j].languageId)); + if (root["game"].isMember(installer+GlobalConstants::LANGUAGES[j].languageCode)) + installers.push_back(std::make_pair(root["game"][installer+GlobalConstants::LANGUAGES[j].languageCode],GlobalConstants::LANGUAGES[j].languageId)); } } } @@ -309,6 +310,24 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int Json::Value installer = installers[i].first[index]; unsigned int language = installers[i].second; + // Check for duplicate installers in different languages and add languageId of duplicate installer to the original installer + // https://secure.gog.com/forum/general/introducing_the_beta_release_of_the_new_gogcom_downloader/post1483 + if (useDuplicateHandler) + { + bool bDuplicate = false; + for (unsigned int j = 0; j < game.installers.size(); ++j) + { + if (game.installers[j].path == installer["link"].asString()) + { + game.installers[j].language |= language; + bDuplicate = true; + break; + } + } + if (bDuplicate) + continue; + } + game.installers.push_back( gameFile( installer["notificated"].isInt() ? installer["notificated"].asInt() : std::stoi(installer["notificated"].asString()), installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(), diff --git a/src/downloader.cpp b/src/downloader.cpp index 2537908..2b185d3 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -224,7 +224,7 @@ int Downloader::getGameDetails() for (unsigned int i = 0; i < gameNamesIds.size(); ++i) { std::cout << "Getting game info " << i+1 << " / " << gameNamesIds.size() << "\r" << std::flush; - game = gogAPI->getGameDetails(gameNamesIds[i].first, config.iInstallerType, config.iInstallerLanguage); + game = gogAPI->getGameDetails(gameNamesIds[i].first, config.iInstallerType, config.iInstallerLanguage, config.bDuplicateHandler); if (!gogAPI->getError()) { if (game.extras.empty() && !config.bNoExtras) @@ -278,11 +278,19 @@ void Downloader::listGames() { if (!config.bUpdateCheck || games[i].installers[j].updated) // Always list updated files { + std::string languages; + for (unsigned int k = 0; k < GlobalConstants::LANGUAGES.size(); k++) + { + if (games[i].installers[j].language & GlobalConstants::LANGUAGES[k].languageId) + languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].languageString; + } + std::cout << "\tid: " << games[i].installers[j].id << std::endl << "\tname: " << games[i].installers[j].name << std::endl << "\tpath: " << games[i].installers[j].path << std::endl << "\tsize: " << games[i].installers[j].size << std::endl << "\tupdated: " << (games[i].installers[j].updated ? "True" : "False") << std::endl + << "\tlanguage: " << languages << std::endl << std::endl; } } @@ -467,6 +475,8 @@ void Downloader::download() if (config.bUpdateCheck && !games[i].installers[j].updated) continue; + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[j].path, games[i].gamename); + // Get link std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id); if (gogAPI->getError()) @@ -476,8 +486,6 @@ void Downloader::download() continue; } - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].installers[j].path, games[i].gamename); - // Download if (!url.empty()) {