Added support for language packs and improved patch detection

This commit is contained in:
Sude 2013-08-09 23:14:10 +03:00
parent e0a238b587
commit fe238a2959
5 changed files with 172 additions and 67 deletions

View File

@ -34,6 +34,7 @@ class gameDetails {
std::vector<gameFile> extras; std::vector<gameFile> extras;
std::vector<gameFile> installers; std::vector<gameFile> installers;
std::vector<gameFile> patches; std::vector<gameFile> patches;
std::vector<gameFile> languagepacks;
std::string gamename; std::string gamename;
std::string title; std::string title;
std::string icon; std::string icon;
@ -85,6 +86,7 @@ class API
std::string getInstallerLink(const std::string& game_name, const std::string& id); std::string getInstallerLink(const std::string& game_name, const std::string& id);
std::string getExtraLink(const std::string& game_name, const std::string& id); std::string getExtraLink(const std::string& game_name, const std::string& id);
std::string getPatchLink(const std::string& game_name, const std::string& id); std::string getPatchLink(const std::string& game_name, const std::string& id);
std::string getLanguagePackLink(const std::string& game_name, const std::string& id);
std::string getXML(const std::string& game_name, const std::string& id); std::string getXML(const std::string& game_name, const std::string& id);
void clearError(); void clearError();
bool getError() { return this->error; }; bool getError() { return this->error; };

View File

@ -28,6 +28,7 @@ class Config
bool bNoInstallers; bool bNoInstallers;
bool bNoExtras; bool bNoExtras;
bool bNoPatches; bool bNoPatches;
bool bNoLanguagePacks;
bool bNoUnicode; // don't use Unicode in console output bool bNoUnicode; // don't use Unicode in console output
bool bNoColor; // don't use colors bool bNoColor; // don't use colors
bool bVerifyPeer; bool bVerifyPeer;

View File

@ -95,6 +95,7 @@ int main(int argc, char *argv[])
("no-installers", bpo::value<bool>(&config.bNoInstallers)->zero_tokens()->default_value(false), "Don't download/list/repair installers") ("no-installers", bpo::value<bool>(&config.bNoInstallers)->zero_tokens()->default_value(false), "Don't download/list/repair installers")
("no-extras", bpo::value<bool>(&config.bNoExtras)->zero_tokens()->default_value(false), "Don't download/list/repair extras") ("no-extras", bpo::value<bool>(&config.bNoExtras)->zero_tokens()->default_value(false), "Don't download/list/repair extras")
("no-patches", bpo::value<bool>(&config.bNoPatches)->zero_tokens()->default_value(false), "Don't download/list/repair patches") ("no-patches", bpo::value<bool>(&config.bNoPatches)->zero_tokens()->default_value(false), "Don't download/list/repair patches")
("no-language-packs", bpo::value<bool>(&config.bNoLanguagePacks)->zero_tokens()->default_value(false), "Don't download/list/repair language packs")
("no-cover", bpo::value<bool>(&config.bNoCover)->zero_tokens()->default_value(false), "Don't download cover images") ("no-cover", bpo::value<bool>(&config.bNoCover)->zero_tokens()->default_value(false), "Don't download cover images")
("no-remote-xml", bpo::value<bool>(&config.bNoRemoteXML)->zero_tokens()->default_value(false), "Don't use remote XML for repair") ("no-remote-xml", bpo::value<bool>(&config.bNoRemoteXML)->zero_tokens()->default_value(false), "Don't use remote XML for repair")
("no-unicode", bpo::value<bool>(&config.bNoUnicode)->zero_tokens()->default_value(false), "Don't use Unicode in the progress bar") ("no-unicode", bpo::value<bool>(&config.bNoUnicode)->zero_tokens()->default_value(false), "Don't use Unicode in the progress bar")

View File

@ -341,16 +341,28 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
{ {
if (lang & GlobalConstants::LANGUAGES[i].languageId) if (lang & GlobalConstants::LANGUAGES[i].languageId)
{ {
unsigned int patch_number = 1; // Try to find a patch
unsigned int patch_number = 0;
const unsigned int maxTries = 8;
std::vector<std::string> patchnames;
while (patch_number < maxTries)
{
unsigned int patch_number_file = 0; unsigned int patch_number_file = 0;
while (patch_number_file < maxTries)
{
std::string patchname = GlobalConstants::LANGUAGES[i].languageCode + std::to_string(patch_number) + "patch" + std::to_string(patch_number_file); std::string patchname = GlobalConstants::LANGUAGES[i].languageCode + std::to_string(patch_number) + "patch" + std::to_string(patch_number_file);
if (root["game"].isMember(patchname)) // found a patch node if (root["game"].isMember(patchname))
patchnames.push_back(patchname);
patch_number_file++;
}
patch_number++;
}
if (!patchnames.empty()) // found at least one patch
{ {
Json::Value patchnode = root["game"][patchname]; for (unsigned int i = 0; i < patchnames.size(); ++i)
while (!patchnode.empty()) // patch numbers
{
while(!patchnode.empty()) // patch file numbers
{ {
Json::Value patchnode = root["game"][patchnames[i]];
if (patchnode.isArray()) if (patchnode.isArray())
{ {
for ( unsigned int index = 0; index < patchnode.size(); ++index ) for ( unsigned int index = 0; index < patchnode.size(); ++index )
@ -380,14 +392,47 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
) )
); );
} }
patch_number_file++;
patchname = GlobalConstants::LANGUAGES[i].languageCode + std::to_string(patch_number) + "patch" + std::to_string(patch_number_file);
patchnode = root["game"][patchname];
} }
patch_number++; }
patch_number_file = 0; }
patchname = GlobalConstants::LANGUAGES[i].languageCode + std::to_string(patch_number) + "patch" + std::to_string(patch_number_file); }
patchnode = root["game"][patchname];
// Language pack details
for (unsigned int i = 0; i < GlobalConstants::LANGUAGES.size(); ++i)
{
if (lang & GlobalConstants::LANGUAGES[i].languageId)
{
// Try to find a language pack
unsigned int lang_pack_number = 0;
const unsigned int maxTries = 4;
std::vector<std::string> langpacknames;
while (lang_pack_number < maxTries)
{
unsigned int lang_pack_number_file = 0;
while (lang_pack_number_file < maxTries)
{
std::string langpackname = GlobalConstants::LANGUAGES[i].languageCode + std::to_string(lang_pack_number) + "langpack" + std::to_string(lang_pack_number_file);
if (root["game"].isMember(langpackname))
langpacknames.push_back(langpackname);
lang_pack_number_file++;
}
lang_pack_number++;
}
if (!langpacknames.empty()) // found at least one language pack
{
for (unsigned int i = 0; i < langpacknames.size(); ++i)
{
Json::Value langpack = root["game"][langpacknames[i]];
game.languagepacks.push_back(
gameFile( false, /* language packs don't have "updated" flag */
langpack["id"].isInt() ? std::to_string(langpack["id"].asInt()) : langpack["id"].asString(),
langpack["name"].asString(),
langpack["link"].asString(),
langpack["size"].asString(),
GlobalConstants::LANGUAGES[i].languageId
)
);
} }
} }
} }
@ -488,6 +533,11 @@ std::string API::getPatchLink(const std::string& game_name, const std::string& i
return this->getInstallerLink(game_name, id); return this->getInstallerLink(game_name, id);
} }
std::string API::getLanguagePackLink(const std::string& game_name, const std::string& id)
{
return this->getInstallerLink(game_name, id);
}
std::string API::getXML(const std::string& game_name, const std::string& id) std::string API::getXML(const std::string& game_name, const std::string& id)
{ {
std::string url, XML; std::string url, XML;

View File

@ -300,6 +300,19 @@ void Downloader::listGames()
<< std::endl; << std::endl;
} }
} }
// List language packs
if (!config.bNoLanguagePacks && !config.bUpdateCheck && !games[i].languagepacks.empty())
{
std::cout << "language packs: " << std::endl;
for (unsigned int j = 0; j < games[i].languagepacks.size(); ++j)
{
std::cout << "\tid: " << games[i].languagepacks[j].id << std::endl
<< "\tname: " << games[i].languagepacks[j].name << std::endl
<< "\tpath: " << games[i].languagepacks[j].path << std::endl
<< "\tsize: " << games[i].languagepacks[j].size << std::endl
<< std::endl;
}
}
} }
} }
else else
@ -378,22 +391,6 @@ void Downloader::repair()
{ {
std::string filepath = Util::makeFilepath(config.sDirectory, games[i].patches[j].path, games[i].gamename); std::string filepath = Util::makeFilepath(config.sDirectory, games[i].patches[j].path, games[i].gamename);
// Get XML data
std::string XML = "";
if (!config.bNoRemoteXML)
{
XML = gogAPI->getXML(games[i].gamename, games[i].patches[j].id);
if (gogAPI->getError())
{
std::cout << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError();
continue;
}
}
// Repair
if (!XML.empty() || config.bNoRemoteXML)
{
std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id); std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
@ -402,11 +399,31 @@ void Downloader::repair()
continue; continue;
} }
std::cout << "Repairing file " << filepath << std::endl; std::cout << "Repairing file " << filepath << std::endl;
this->repairFile(url, filepath, XML); this->repairFile(url, filepath);
std::cout << std::endl; std::cout << std::endl;
} }
} }
// Language packs (GOG doesn't provide XML data for language packs, use local file)
if (!config.bNoLanguagePacks)
{
for (unsigned int j = 0; j < games[i].languagepacks.size(); ++j)
{
std::string filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename);
std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id);
if (gogAPI->getError())
{
std::cout << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError();
continue;
} }
std::cout << "Repairing file " << filepath << std::endl;
this->repairFile(url, filepath);
std::cout << std::endl;
}
}
} }
} }
@ -513,14 +530,48 @@ void Downloader::download()
// Download // Download
if (!url.empty()) if (!url.empty())
{ {
std::string XML;
if (!config.bNoRemoteXML)
XML = gogAPI->getXML(games[i].gamename, games[i].patches[j].id);
if (!games[i].patches[j].name.empty()) if (!games[i].patches[j].name.empty())
std::cout << "Dowloading: " << games[i].gamename << " " << games[i].patches[j].name << std::endl; std::cout << "Dowloading: " << games[i].gamename << " " << games[i].patches[j].name << std::endl;
std::cout << filepath << std::endl; std::cout << filepath << std::endl;
this->downloadFile(url, filepath, XML); CURLcode result = downloadFile(url, filepath);
std::cout << std::endl; std::cout << std::endl;
if (result==CURLE_OK && config.sXMLFile == "automatic")
{
std::cout << "Starting automatic XML creation" << std::endl;
Util::createXML(filepath, config.iChunkSize, config.sXMLDirectory);
}
}
}
}
// Download language packs
if (!config.bNoLanguagePacks)
{
for (unsigned int j = 0; j < games[i].languagepacks.size(); ++j)
{
// Get link
std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id);
if (gogAPI->getError())
{
std::cout << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError();
continue;
}
std::string filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename);
// Download
if (!url.empty())
{
if (!games[i].languagepacks[j].name.empty())
std::cout << "Dowloading: " << games[i].gamename << " " << games[i].languagepacks[j].name << std::endl;
std::cout << filepath << std::endl;
CURLcode result = downloadFile(url, filepath);
std::cout << std::endl;
if (result==CURLE_OK && config.sXMLFile == "automatic")
{
std::cout << "Starting automatic XML creation" << std::endl;
Util::createXML(filepath, config.iChunkSize, config.sXMLDirectory);
}
} }
} }
} }