2
0
mirror of https://github.com/Sude-/lgogdownloader.git synced 2025-03-08 20:35:18 +01:00

Add language to installer path if it is missing

This commit is contained in:
Sude 2013-03-23 15:42:09 +02:00
parent d2566de2f4
commit 97e948abb4
4 changed files with 50 additions and 16 deletions

@ -32,12 +32,13 @@ extern "C" {
class gameFile {
public:
gameFile(const bool& t_updated, const std::string& t_id, const std::string& t_name, const std::string& t_path, const std::string& t_size);
gameFile(const bool& t_updated, const std::string& t_id, const std::string& t_name, const std::string& t_path, const std::string& t_size, const unsigned int& t_language = LANGUAGE_EN);
bool updated;
std::string id;
std::string name;
std::string path;
std::string size;
unsigned int language;
virtual ~gameFile();
};

@ -59,6 +59,7 @@ class Downloader
int downloadCovers(std::string gamename, std::string directory, std::string cover_xml_data);
int login();
int getGameDetails();
void fixInstallerLanguagePath(gameDetails& game);
void getGameList();
size_t getResumePosition();
CURLcode beginDownload();

@ -18,13 +18,14 @@ size_t writeMemoryCallback(char *ptr, size_t size, size_t nmemb, void *userp) {
return count;
}
gameFile::gameFile(const bool& t_updated, const std::string& t_id, const std::string& t_name, const std::string& t_path, const std::string& t_size)
gameFile::gameFile(const bool& t_updated, const std::string& t_id, const std::string& t_name, const std::string& t_path, const std::string& t_size, const unsigned int& t_language)
{
this->updated = t_updated;
this->id = t_id;
this->name = t_name;
this->path = t_path;
this->size = t_size;
this->language = t_language;
}
gameFile::~gameFile()
@ -287,45 +288,47 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
game.icon = root["game"]["icon"].asString();
// Installer details
std::vector<Json::Value> installers;
std::vector<std::pair<Json::Value,unsigned int>> installers;
if (type & INSTALLER_WINDOWS)
{
if (lang & LANGUAGE_EN)
installers.push_back(root["game"]["installer_win_en"]);
installers.push_back(std::make_pair(root["game"]["installer_win_en"],LANGUAGE_EN));
if (lang & LANGUAGE_DE)
installers.push_back(root["game"]["installer_win_de"]);
installers.push_back(std::make_pair(root["game"]["installer_win_de"],LANGUAGE_DE));
if (lang & LANGUAGE_FR)
installers.push_back(root["game"]["installer_win_fr"]);
installers.push_back(std::make_pair(root["game"]["installer_win_fr"],LANGUAGE_FR));
if (lang & LANGUAGE_PL)
installers.push_back(root["game"]["installer_win_pl"]);
installers.push_back(std::make_pair(root["game"]["installer_win_pl"],LANGUAGE_PL));
if (lang & LANGUAGE_RU)
installers.push_back(root["game"]["installer_win_ru"]);
installers.push_back(std::make_pair(root["game"]["installer_win_ru"],LANGUAGE_RU));
}
if (type & INSTALLER_MAC)
{
if (lang & LANGUAGE_EN)
installers.push_back(root["game"]["installer_mac_en"]);
installers.push_back(std::make_pair(root["game"]["installer_mac_en"],LANGUAGE_EN));
if (lang & LANGUAGE_DE)
installers.push_back(root["game"]["installer_mac_de"]);
installers.push_back(std::make_pair(root["game"]["installer_mac_de"],LANGUAGE_DE));
if (lang & LANGUAGE_FR)
installers.push_back(root["game"]["installer_mac_fr"]);
installers.push_back(std::make_pair(root["game"]["installer_mac_fr"],LANGUAGE_FR));
if (lang & LANGUAGE_PL)
installers.push_back(root["game"]["installer_mac_pl"]);
installers.push_back(std::make_pair(root["game"]["installer_mac_pl"],LANGUAGE_PL));
if (lang & LANGUAGE_RU)
installers.push_back(root["game"]["installer_mac_ru"]);
installers.push_back(std::make_pair(root["game"]["installer_mac_ru"],LANGUAGE_RU));
}
for ( unsigned int i = 0; i < installers.size(); ++i )
{
for ( unsigned int index = 0; index < installers[i].size(); ++index )
for ( unsigned int index = 0; index < installers[i].first.size(); ++index )
{
Json::Value installer = installers[i][index];
Json::Value installer = installers[i].first[index];
unsigned int language = installers[i].second;
game.installers.push_back(
gameFile( installer["#updated"].isBool() ? installer["#updated"].asBool() : false,
installer["id"].isInt() ? std::to_string(installer["id"].asInt()) : installer["id"].asString(),
installer["#name"].asString(),
installer["link"].asString(),
installer["size"].asString()
installer["size"].asString(),
language
)
);
}

@ -228,6 +228,7 @@ int Downloader::getGameDetails()
game = gogAPI->getGameDetails(gameNames[i], config.iInstallerType, config.iInstallerLanguage);
if (!gogAPI->getError())
{
this->fixInstallerLanguagePath(game);
if (!config.bUpdateCheck)
games.push_back(game);
else
@ -258,6 +259,34 @@ int Downloader::getGameDetails()
return 0;
}
// Adds language to installer path if it is missing
void Downloader::fixInstallerLanguagePath(gameDetails& game)
{
for (unsigned int i = 0; i < game.installers.size(); ++i)
{
if (game.installers[i].language != LANGUAGE_EN)
{
std::string lang;
if (game.installers[i].language == LANGUAGE_DE)
lang = "_de_";
else if (game.installers[i].language == LANGUAGE_FR)
lang = "_fr_";
else if (game.installers[i].language == LANGUAGE_PL)
lang = "_pl_";
else if (game.installers[i].language == LANGUAGE_RU)
lang = "_ru_";
boost::match_results<std::string::const_iterator> what;
boost::regex expression(lang, boost::regex::perl | boost::regex::icase);
if (!boost::regex_search(game.installers[i].path, what, expression))
{
boost::regex expression("(.*)_(\\d+\\.\\d+.*$)", boost::regex::perl | boost::regex::icase);
boost::regex_search(game.installers[i].path,what,expression);
game.installers[i].path = what[1] + lang + what[2];
}
}
}
}
void Downloader::listGames()
{
if (config.bListDetails) // Detailed list