mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Add support for Linux installers
This commit is contained in:
parent
42a461ed55
commit
630d8a31c3
@ -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<platformStruct> PLATFORMS =
|
||||
{
|
||||
{ PLATFORM_WINDOWS, "win", "Windows" },
|
||||
{ PLATFORM_MAC, "mac", "Mac" }
|
||||
{ PLATFORM_MAC, "mac", "Mac" },
|
||||
{ PLATFORM_LINUX, "linux", "Linux" }
|
||||
};
|
||||
};
|
||||
|
||||
|
2
main.cpp
2
main.cpp
@ -142,7 +142,7 @@ int main(int argc, char *argv[])
|
||||
("limit-rate", bpo::value<curl_off_t>(&config.iDownloadRate)->default_value(0), "Limit download rate to value in kB\n0 = unlimited")
|
||||
("xml-directory", bpo::value<std::string>(&config.sXMLDirectory), "Set directory for GOG XML files")
|
||||
("chunk-size", bpo::value<size_t>(&config.iChunkSize)->default_value(10), "Chunk size (in MB) when creating XML")
|
||||
("platform", bpo::value<unsigned int>(&config.iInstallerType)->default_value(GlobalConstants::PLATFORM_WINDOWS), platform_text.c_str())
|
||||
("platform", bpo::value<unsigned int>(&config.iInstallerType)->default_value(GlobalConstants::PLATFORM_WINDOWS|GlobalConstants::PLATFORM_LINUX), platform_text.c_str())
|
||||
("language", bpo::value<unsigned int>(&config.iInstallerLanguage)->default_value(GlobalConstants::LANGUAGE_EN), language_text.c_str())
|
||||
("no-installers", bpo::value<bool>(&bNoInstallers)->zero_tokens()->default_value(false), "Don't download/list/repair installers")
|
||||
("no-extras", bpo::value<bool>(&bNoExtras)->zero_tokens()->default_value(false), "Don't download/list/repair extras")
|
||||
|
35
src/api.cpp
35
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<std::pair<Json::Value,unsigned int>> 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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user