Some minor code cleanup

This commit is contained in:
Sude 2015-09-01 13:59:54 +03:00
parent 129768743e
commit 9b560d786e
6 changed files with 20 additions and 25 deletions

View File

@ -75,7 +75,7 @@ class Config
std::vector<unsigned int> vLanguagePriority;
std::vector<unsigned int> vPlatformPriority;
unsigned int iInstallerType;
unsigned int iInstallerPlatform;
unsigned int iInstallerLanguage;
int iRetries;
int iWait;

View File

@ -21,7 +21,7 @@
struct gameSpecificConfig
{
unsigned int iInstallerType;
unsigned int iInstallerPlatform;
unsigned int iInstallerLanguage;
bool bDLC;
bool bIgnoreDLCCount;

View File

@ -157,7 +157,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|GlobalConstants::PLATFORM_LINUX), platform_text.c_str())
("platform", bpo::value<unsigned int>(&config.iInstallerPlatform)->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")
@ -338,7 +338,7 @@ int main(int argc, char *argv[])
if (!config.sLanguagePriority.empty())
handle_priority("languages", config.sLanguagePriority, config.vLanguagePriority, config.iInstallerLanguage);
if (!config.sPlatformPriority.empty())
handle_priority("platforms", config.sPlatformPriority, config.vPlatformPriority, config.iInstallerType);
handle_priority("platforms", config.sPlatformPriority, config.vPlatformPriority, config.iInstallerPlatform);
}
catch (std::exception& e)
@ -352,7 +352,7 @@ int main(int argc, char *argv[])
return 1;
}
if (config.iInstallerType < GlobalConstants::PLATFORMS[0].id || config.iInstallerType > platform_sum)
if (config.iInstallerPlatform < GlobalConstants::PLATFORMS[0].id || config.iInstallerPlatform > platform_sum)
{
std::cout << "Invalid value for --platform" << std::endl;
return 1;

View File

@ -275,7 +275,6 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
{
std::string url;
gameDetails game;
unsigned int type = platform;
struct gameFileInfo
{
Json::Value jsonNode;
@ -305,7 +304,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
std::vector<gameFileInfo> installers;
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
{ // Check against the specified platforms
if (type & GlobalConstants::PLATFORMS[i].id)
if (platform & GlobalConstants::PLATFORMS[i].id)
{
std::string installer = "installer_" + GlobalConstants::PLATFORMS[i].code + "_";
for (unsigned int j = 0; j < GlobalConstants::LANGUAGES.size(); ++j)
@ -402,7 +401,7 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
else
patchInfo.platform = GlobalConstants::PLATFORM_WINDOWS;
if (type & patchInfo.platform)
if (platform & patchInfo.platform)
patches.push_back(patchInfo);
}
}

View File

@ -249,14 +249,14 @@ int Downloader::getGameDetails()
conf.bDLC = config.bDLC;
conf.bIgnoreDLCCount = false;
conf.iInstallerLanguage = config.iInstallerLanguage;
conf.iInstallerType = config.iInstallerType;
conf.iInstallerPlatform = config.iInstallerPlatform;
if (!config.bUpdateCache) // Disable game specific config files for cache update
{
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") << ", Ignore DLC count: " << (conf.bIgnoreDLCCount ? "true" : "false") << std::endl;
std::cout << std::endl << gameItems[i].name << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerPlatform << ", DLC: " << (conf.bDLC ? "true" : "false") << ", Ignore DLC count: " << (conf.bIgnoreDLCCount ? "true" : "false") << std::endl;
}
game = gogAPI->getGameDetails(gameItems[i].name, conf.iInstallerType, conf.iInstallerLanguage, config.bDuplicateHandler);
game = gogAPI->getGameDetails(gameItems[i].name, conf.iInstallerPlatform, conf.iInstallerLanguage, config.bDuplicateHandler);
if (!gogAPI->getError())
{
game.filterWithPriorities(config);
@ -289,7 +289,7 @@ int Downloader::getGameDetails()
for (unsigned int j = 0; j < gameItems[i].dlcnames.size(); ++j)
{
gameDetails dlc;
dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], conf.iInstallerType, conf.iInstallerLanguage, config.bDuplicateHandler);
dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], conf.iInstallerPlatform, conf.iInstallerLanguage, config.bDuplicateHandler);
if (dlc.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras
{
if (gameDetailsJSON.empty())
@ -2163,7 +2163,7 @@ std::vector<gameItem> Downloader::getGames()
platform |= GlobalConstants::PLATFORM_LINUX;
// Skip if platform doesn't match
if (config.bPlatformDetection && !(platform & config.iInstallerType))
if (config.bPlatformDetection && !(platform & config.iInstallerPlatform))
continue;
// Filter the game list
@ -3043,9 +3043,9 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
gameSpecificConfig conf;
conf.bDLC = config.bDLC;
conf.iInstallerLanguage = config.iInstallerLanguage;
conf.iInstallerType = config.iInstallerType;
conf.iInstallerPlatform = config.iInstallerPlatform;
if (Util::getGameSpecificConfig(game.gamename, &conf) > 0)
std::cout << game.gamename << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerType << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl;
std::cout << game.gamename << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerPlatform << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl;
for (unsigned int j = 0; j < nodes.size(); ++j)
{
@ -3069,7 +3069,7 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
fileDetails.language = fileDetailsNode["language"].asUInt();
fileDetails.silent = fileDetailsNode["silent"].asInt();
if (nodeName != "extras" && !(fileDetails.platform & conf.iInstallerType))
if (nodeName != "extras" && !(fileDetails.platform & conf.iInstallerPlatform))
continue;
if (nodeName != "extras" && !(fileDetails.language & conf.iInstallerLanguage))
continue;
@ -3103,12 +3103,8 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
void Downloader::updateCache()
{
// Make sure that all details get cached
unsigned int all_platforms = GlobalConstants::PLATFORM_WINDOWS;
unsigned int all_languages = GlobalConstants::LANGUAGE_EN;
for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i)
all_platforms |= GlobalConstants::PLATFORMS[i].id;
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
all_languages |= GlobalConstants::LANGUAGES[i].id;
unsigned int all_platforms = (2 << (GlobalConstants::PLATFORMS.size() - 1)) - 1;
unsigned int all_languages = (2 << (GlobalConstants::LANGUAGES.size() - 1)) - 1;
config.bExtras = true;
config.bInstallers = true;
@ -3117,7 +3113,7 @@ void Downloader::updateCache()
config.bDLC = true;
config.sGameRegex = ".*";
config.iInstallerLanguage = all_languages;
config.iInstallerType = all_platforms;
config.iInstallerPlatform = all_platforms;
config.vLanguagePriority.clear();
config.vPlatformPriority.clear();
@ -3266,7 +3262,7 @@ void Downloader::showWishlist()
platform |= GlobalConstants::PLATFORM_LINUX;
// Skip if platform doesn't match
if (config.bPlatformDetection && !(platform & config.iInstallerType))
if (config.bPlatformDetection && !(platform & config.iInstallerPlatform))
continue;
for (unsigned int j = 0; j < GlobalConstants::PLATFORMS.size(); ++j)

View File

@ -245,7 +245,7 @@ int Util::getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf,
}
if (root.isMember("platform"))
{
conf->iInstallerType = root["platform"].asUInt();
conf->iInstallerPlatform = root["platform"].asUInt();
res++;
}
if (root.isMember("dlc"))