diff --git a/include/globalconstants.h b/include/globalconstants.h index 653eabd..811c3bf 100644 --- a/include/globalconstants.h +++ b/include/globalconstants.h @@ -60,12 +60,14 @@ namespace GlobalConstants // Platform constants const unsigned int PLATFORM_WINDOWS = 1; const unsigned int PLATFORM_MAC = 2; + const unsigned int PLATFORM_LINUX = 4; struct platformStruct {const unsigned int platformId; const std::string platformCode; const std::string platformString;}; const std::vector PLATFORMS = { - { PLATFORM_WINDOWS, "win", "Windows" }, - { PLATFORM_MAC, "mac", "Mac" } + { PLATFORM_WINDOWS, "win", "Windows" }, + { PLATFORM_MAC, "mac", "Mac" }, + { PLATFORM_LINUX, "linux", "Linux" } }; }; diff --git a/main.cpp b/main.cpp index 1e22507..bb93dd3 100644 --- a/main.cpp +++ b/main.cpp @@ -142,7 +142,7 @@ int main(int argc, char *argv[]) ("limit-rate", bpo::value(&config.iDownloadRate)->default_value(0), "Limit download rate to value in kB\n0 = unlimited") ("xml-directory", bpo::value(&config.sXMLDirectory), "Set directory for GOG XML files") ("chunk-size", bpo::value(&config.iChunkSize)->default_value(10), "Chunk size (in MB) when creating XML") - ("platform", bpo::value(&config.iInstallerType)->default_value(GlobalConstants::PLATFORM_WINDOWS), platform_text.c_str()) + ("platform", bpo::value(&config.iInstallerType)->default_value(GlobalConstants::PLATFORM_WINDOWS|GlobalConstants::PLATFORM_LINUX), platform_text.c_str()) ("language", bpo::value(&config.iInstallerLanguage)->default_value(GlobalConstants::LANGUAGE_EN), language_text.c_str()) ("no-installers", bpo::value(&bNoInstallers)->zero_tokens()->default_value(false), "Don't download/list/repair installers") ("no-extras", bpo::value(&bNoExtras)->zero_tokens()->default_value(false), "Don't download/list/repair extras") diff --git a/src/api.cpp b/src/api.cpp index bbf3aa3..626e003 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -264,10 +264,11 @@ 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, const bool& useDuplicateHandler) +gameDetails API::getGameDetails(const std::string& game_name, const unsigned int& platform, const unsigned int& lang, const bool& useDuplicateHandler) { std::string url; gameDetails game; + unsigned int type = platform; url = this->config.get_game_details + game_name + "/" + "installer_win_en"; // can't get game details without file id, any file id seems to return all details which is good for us std::string json = this->getResponseOAuth(url); @@ -285,6 +286,24 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int game.title = root["game"]["title"].asString(); game.icon = root["game"]["icon"].asString(); + + // FIXME: Replace this ugly hack when GOG makes the API responses for Linux better + bool bIsLinux = false; + bool bIsMac = false; + if (type & (GlobalConstants::PLATFORM_LINUX | GlobalConstants::PLATFORM_MAC) ) + { + if (type & GlobalConstants::PLATFORM_LINUX) + bIsLinux = true; + else + bIsLinux = false; + if (type & GlobalConstants::PLATFORM_MAC) + bIsMac = true; + else + bIsMac = false; + type |= GlobalConstants::PLATFORM_MAC; // For some reason Linux installers are under Mac installer node so add Mac to installer type + } + + // Installer details // Create a list of installers from JSON std::vector> installers; @@ -329,6 +348,18 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int continue; } + // FIXME: Replace this ugly hack when GOG makes the API responses for Linux better + if (bIsLinux && !bIsMac) + { + if (installer["link"].asString().find("/mac/") != std::string::npos) + continue; + } + if (!bIsLinux && bIsMac) + { + if (installer["link"].asString().find("/linux/") != std::string::npos) + 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(), @@ -378,6 +409,8 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int unsigned int platformId; if (root["game"][patchname]["link"].asString().find("/mac/") != std::string::npos) platformId = GlobalConstants::PLATFORM_MAC; + else if (root["game"][patchname]["link"].asString().find("/linux/") != std::string::npos) + platformId = GlobalConstants::PLATFORM_LINUX; else platformId = GlobalConstants::PLATFORM_WINDOWS;