Add support for priority in game specific language and platform options

This commit is contained in:
Sude 2016-02-20 15:34:51 +02:00
parent 9cf9a8f378
commit 0de2a9f64b
6 changed files with 68 additions and 45 deletions

View File

@ -23,13 +23,13 @@ class gameDetails
std::string title;
std::string icon;
std::string serials;
void filterWithPriorities(const Config& config);
void filterWithPriorities(const gameSpecificConfig& config);
void makeFilepaths(const gameSpecificDirectoryConfig& config);
std::string getSerialsFilepath();
Json::Value getDetailsAsJson();
virtual ~gameDetails();
protected:
void filterListWithPriorities(std::vector<gameFile>& list, const Config& config);
void filterListWithPriorities(std::vector<gameFile>& list, const gameSpecificConfig& config);
private:
std::string serialsFilepath;
};

View File

@ -39,6 +39,8 @@ struct gameSpecificConfig
bool bDLC;
bool bIgnoreDLCCount;
gameSpecificDirectoryConfig dirConf;
std::vector<unsigned int> vLanguagePriority;
std::vector<unsigned int> vPlatformPriority;
};
namespace Util
@ -61,6 +63,7 @@ namespace Util
std::vector<std::string> tokenize(const std::string& str, const std::string& separator = ",");
unsigned int getOptionValue(const std::string& str, const std::vector<GlobalConstants::optionsStruct>& options);
std::string getOptionNameString(const unsigned int& value, const std::vector<GlobalConstants::optionsStruct>& options);
void parseOptionString(const std::string &option_string, std::vector<unsigned int> &priority, unsigned int &type, const std::vector<GlobalConstants::optionsStruct>& options);
}
#endif // UTIL_H

View File

@ -20,24 +20,6 @@ template<typename T> void set_vm_value(std::map<std::string, bpo::variable_value
vm[option].value() = boost::any(value);
}
// Parse the options string
void parseOptionString(const std::string &option_string, std::vector<unsigned int> &priority, unsigned int &type, const std::vector<GlobalConstants::optionsStruct>& options)
{
type = 0;
std::vector<std::string> tokens_priority = Util::tokenize(option_string, ",");
for (std::vector<std::string>::iterator it_priority = tokens_priority.begin(); it_priority != tokens_priority.end(); it_priority++)
{
unsigned int value = 0;
std::vector<std::string> tokens_value = Util::tokenize(*it_priority, "+");
for (std::vector<std::string>::iterator it_value = tokens_value.begin(); it_value != tokens_value.end(); it_value++)
{
value |= Util::getOptionValue(*it_value, options);
}
priority.push_back(value);
type |= value;
}
}
int main(int argc, char *argv[])
{
// Constants for option selection with include/exclude
@ -342,8 +324,8 @@ int main(int argc, char *argv[])
if (config.sXMLFile == "automatic")
config.bAutomaticXMLCreation = true;
parseOptionString(sInstallerLanguage, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES);
parseOptionString(sInstallerPlatform, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS);
Util::parseOptionString(sInstallerLanguage, config.vLanguagePriority, config.iInstallerLanguage, GlobalConstants::LANGUAGES);
Util::parseOptionString(sInstallerPlatform, config.vPlatformPriority, config.iInstallerPlatform, GlobalConstants::PLATFORMS);
unsigned int include_value = 0;
unsigned int exclude_value = 0;

View File

@ -270,17 +270,48 @@ int Downloader::getGameDetails()
conf.iInstallerLanguage = config.iInstallerLanguage;
conf.iInstallerPlatform = config.iInstallerPlatform;
conf.dirConf = dirConfDefault;
conf.vLanguagePriority = config.vLanguagePriority;
conf.vPlatformPriority = config.vPlatformPriority;
if (!config.bUpdateCache) // Disable game specific config files for cache update
{
int iOptionsOverridden = Util::getGameSpecificConfig(gameItems[i].name, &conf);
if (iOptionsOverridden > 0)
{
std::cout << std::endl << gameItems[i].name << " - " << iOptionsOverridden << " options overridden with game specific options" << std::endl;
if (config.bVerbose)
{
if (conf.bIgnoreDLCCount)
std::cout << "\tIgnore DLC count" << std::endl;
if (conf.bDLC != config.bDLC)
std::cout << "\tDLC: " << (conf.bDLC ? "true" : "false") << std::endl;
if (conf.iInstallerLanguage != config.iInstallerLanguage)
std::cout << "\tLanguage: " << Util::getOptionNameString(conf.iInstallerLanguage, GlobalConstants::LANGUAGES) << std::endl;
if (conf.vLanguagePriority != config.vLanguagePriority)
{
std::cout << "\tLanguage priority:" << std::endl;
for (unsigned int j = 0; j < conf.vLanguagePriority.size(); ++j)
{
std::cout << "\t " << j << ": " << Util::getOptionNameString(conf.vLanguagePriority[j], GlobalConstants::LANGUAGES) << std::endl;
}
}
if (conf.iInstallerPlatform != config.iInstallerPlatform)
std::cout << "\tPlatform: " << Util::getOptionNameString(conf.iInstallerPlatform, GlobalConstants::PLATFORMS) << std::endl;
if (conf.vPlatformPriority != config.vPlatformPriority)
{
std::cout << "\tPlatform priority:" << std::endl;
for (unsigned int j = 0; j < conf.vPlatformPriority.size(); ++j)
{
std::cout << "\t " << j << ": " << Util::getOptionNameString(conf.vPlatformPriority[j], GlobalConstants::PLATFORMS) << std::endl;
}
}
}
}
}
game = gogAPI->getGameDetails(gameItems[i].name, conf.iInstallerPlatform, conf.iInstallerLanguage, config.bDuplicateHandler);
if (!gogAPI->getError())
{
game.filterWithPriorities(config);
game.filterWithPriorities(conf);
Json::Value gameDetailsJSON;
if (game.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras
@ -311,7 +342,7 @@ int Downloader::getGameDetails()
{
gameDetails dlc;
dlc = gogAPI->getGameDetails(gameItems[i].dlcnames[j], conf.iInstallerPlatform, conf.iInstallerLanguage, config.bDuplicateHandler);
dlc.filterWithPriorities(config);
dlc.filterWithPriorities(conf);
if (dlc.extras.empty() && config.bExtras) // Try to get extras from account page if API didn't return any extras
{
if (gameDetailsJSON.empty())
@ -3058,6 +3089,8 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
conf.bDLC = config.bDLC;
conf.iInstallerLanguage = config.iInstallerLanguage;
conf.iInstallerPlatform = config.iInstallerPlatform;
conf.vLanguagePriority = config.vLanguagePriority;
conf.vPlatformPriority = config.vPlatformPriority;
if (Util::getGameSpecificConfig(game.gamename, &conf) > 0)
std::cout << game.gamename << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerPlatform << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl;
@ -3107,7 +3140,7 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
}
if (!game.extras.empty() || !game.installers.empty() || !game.patches.empty() || !game.languagepacks.empty() || !game.dlcs.empty())
{
game.filterWithPriorities(config);
game.filterWithPriorities(conf);
details.push_back(game);
}
}

View File

@ -10,7 +10,7 @@ gameDetails::~gameDetails()
//dtor
}
void gameDetails::filterWithPriorities(const Config& config)
void gameDetails::filterWithPriorities(const gameSpecificConfig& config)
{
if (config.vPlatformPriority.empty() && config.vLanguagePriority.empty())
return;
@ -20,7 +20,7 @@ void gameDetails::filterWithPriorities(const Config& config)
filterListWithPriorities(languagepacks, config);
}
void gameDetails::filterListWithPriorities(std::vector<gameFile>& list, const Config& config)
void gameDetails::filterListWithPriorities(std::vector<gameFile>& list, const gameSpecificConfig& config)
{
/*
Compute the score of each item - we use a scoring mechanism and we keep all ties

View File

@ -240,36 +240,22 @@ int Util::getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf,
{
if (root.isMember("language"))
{
unsigned int language = 0;
if (root["language"].isInt())
language = root["language"].asUInt();
conf->iInstallerLanguage = root["language"].asUInt();
else
{
std::vector<std::string> tokens = Util::tokenize(root["language"].asString(), "+");
for (std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); it++)
{
language |= Util::getOptionValue(*it, GlobalConstants::LANGUAGES);
}
Util::parseOptionString(root["language"].asString(), conf->vLanguagePriority, conf->iInstallerLanguage, GlobalConstants::LANGUAGES);
}
conf->iInstallerLanguage = language;
res++;
}
if (root.isMember("platform"))
{
unsigned int platform = 0;
if (root["platform"].isInt())
platform = root["platform"].asUInt();
conf->iInstallerPlatform = root["platform"].asUInt();
else
{
std::vector<std::string> tokens = Util::tokenize(root["platform"].asString(), "+");
for (std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); it++)
{
platform |= Util::getOptionValue(*it, GlobalConstants::PLATFORMS);
}
Util::parseOptionString(root["platform"].asString(), conf->vPlatformPriority, conf->iInstallerPlatform, GlobalConstants::PLATFORMS);
}
conf->iInstallerPlatform = platform;
res++;
}
if (root.isMember("dlc"))
@ -535,3 +521,22 @@ std::string Util::getOptionNameString(const unsigned int& value, const std::vect
}
return str;
}
// Parse the options string
void Util::parseOptionString(const std::string &option_string, std::vector<unsigned int> &priority, unsigned int &type, const std::vector<GlobalConstants::optionsStruct>& options)
{
type = 0;
priority.clear();
std::vector<std::string> tokens_priority = Util::tokenize(option_string, ",");
for (std::vector<std::string>::iterator it_priority = tokens_priority.begin(); it_priority != tokens_priority.end(); it_priority++)
{
unsigned int value = 0;
std::vector<std::string> tokens_value = Util::tokenize(*it_priority, "+");
for (std::vector<std::string>::iterator it_value = tokens_value.begin(); it_value != tokens_value.end(); it_value++)
{
value |= Util::getOptionValue(*it_value, options);
}
priority.push_back(value);
type |= value;
}
}