diff --git a/include/util.h b/include/util.h index eacc1ae..b1c8e05 100644 --- a/include/util.h +++ b/include/util.h @@ -15,6 +15,13 @@ #include #include +struct gameSpecificConfig +{ + unsigned int iInstallerType; + unsigned int iInstallerLanguage; + bool bDLC; +}; + namespace Util { std::string makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename, std::string subdirectory = ""); @@ -22,6 +29,7 @@ namespace Util std::string getFileHash(const std::string& filename, unsigned hash_id); std::string getChunkHash(unsigned char* chunk, size_t chunk_size, unsigned hash_id); int createXML(std::string filepath, size_t chunk_size, std::string xml_dir = std::string()); + int getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory = std::string()); } #endif // UTIL_H diff --git a/man/lgogdownloader.supplemental.groff b/man/lgogdownloader.supplemental.groff index 4e8aa99..bf719eb 100644 --- a/man/lgogdownloader.supplemental.groff +++ b/man/lgogdownloader.supplemental.groff @@ -66,5 +66,22 @@ Allows user to specify individual files that should not be downloaded or mention .br It doesn't have to exist, but if it does exist, it must be readable to lgogdownloader. +.TP +\fI$XDG_CONFIG_HOME/lgogdownloader/gamename.conf\fP +JSON formatted file. Sets game specific settings for \fBgamename\fP. +.br +Allowed settings are \fBlanguage\fP, \fBplatform\fP and \fBdlc\fP. +.br +The \fBdlc\fP option is limited to disabling DLC for specific game. It can't enable DLC listing/downloading if \fB--no-dlc\fP option is used. +.br +Must be in the following format: +.br +{ + "language" : , + "platform" : , + "dlc" : +.br +} + [availability] The latest version of this distribution is available from \fIhttps://github.com/Sude-/lgogdownloader\fP diff --git a/src/downloader.cpp b/src/downloader.cpp index 5014bb6..abf36f0 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -210,19 +210,27 @@ int Downloader::getGameDetails() { std::cout << "Getting game info " << i+1 << " / " << gameItems.size() << "\r" << std::flush; bool bHasDLC = !gameItems[i].dlcnames.empty(); - game = gogAPI->getGameDetails(gameItems[i].name, config.iInstallerType, config.iInstallerLanguage, config.bDuplicateHandler); + + gameSpecificConfig conf; + conf.bDLC = config.bDLC; + conf.iInstallerLanguage = config.iInstallerLanguage; + conf.iInstallerType = config.iInstallerType; + if (Util::getGameSpecificConfig(gameItems[i].name, &conf) > 0) + std::cout << std::endl << gameItems[i].name << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerType << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl; + + game = gogAPI->getGameDetails(gameItems[i].name, conf.iInstallerType, conf.iInstallerLanguage, config.bDuplicateHandler); if (!gogAPI->getError()) { if (game.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras { game.extras = this->getExtras(gameItems[i].name, gameItems[i].id); } - if (game.dlcs.empty() && bHasDLC && config.bDLC) + if (game.dlcs.empty() && bHasDLC && conf.bDLC) { for (unsigned int j = 0; j < gameItems[i].dlcnames.size(); ++j) { gameDetails dlc; - dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], config.iInstallerType, config.iInstallerLanguage, config.bDuplicateHandler); + dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], conf.iInstallerType, conf.iInstallerLanguage, config.bDuplicateHandler); if (dlc.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras { dlc.extras = this->getExtras(gameItems[i].dlcnames[j], gameItems[i].id); diff --git a/src/util.cpp b/src/util.cpp index 68ab8bc..69c5fc3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include /* Create filepath from specified directory and path @@ -192,3 +194,65 @@ int Util::createXML(std::string filepath, size_t chunk_size, std::string xml_dir return res; } + +/* + Overrides global settings with game specific settings + returns 0 if fails + returns number of changed settings if succesful +*/ +int Util::getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory) +{ + int res = 0; + + if (directory.empty()) + { + char *xdghome = getenv("XDG_CONFIG_HOME"); + if (xdghome) + directory = (std::string)xdghome + "/lgogdownloader"; + else + { + std::string home = (std::string)getenv("HOME"); + directory = home + "/.config/lgogdownloader"; + } + } + + std::string filepath = directory + "/" + gamename + ".conf"; + + // Make sure file exists + boost::filesystem::path path = filepath; + if (!boost::filesystem::exists(path)) { + return res; + } + + std::ifstream json(filepath, std::ifstream::binary); + Json::Value root; + Json::Reader *jsonparser = new Json::Reader; + if (jsonparser->parse(json, root)) + { + if (root.isMember("language")) + { + conf->iInstallerLanguage = root["language"].asUInt(); + res++; + } + if (root.isMember("platform")) + { + conf->iInstallerType = root["platform"].asUInt(); + res++; + } + if (root.isMember("dlc")) + { + conf->bDLC = root["dlc"].asBool(); + res++; + } + } + else + { + std::cout << "Failed to parse game specific config" << std::endl; + std::cout << jsonparser->getFormatedErrorMessages() << std::endl; + } + delete jsonparser; + if (json) + json.close(); + + return res; +}