From ff2264763e4f1b1009eb10510a0d6dd738711e26 Mon Sep 17 00:00:00 2001 From: Sude Date: Wed, 1 Jun 2016 14:17:55 +0300 Subject: [PATCH] Add support for DLC language packs --- src/downloader.cpp | 111 ++++++++++++++++++++++++++++++++++++++------ src/gamedetails.cpp | 7 +++ 2 files changed, 103 insertions(+), 15 deletions(-) diff --git a/src/downloader.cpp b/src/downloader.cpp index 97f5625..aa51923 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -650,6 +650,22 @@ void Downloader::listGames() << "\tsize: " << games[i].dlcs[j].extras[k].size << std::endl << std::endl; } + for (unsigned int k = 0; k < games[i].dlcs[j].languagepacks.size(); ++k) + { + std::string filepath = games[i].dlcs[j].languagepacks[k].getFilepath(); + if (config.blacklist.isBlacklisted(filepath)) { + if (config.bVerbose) + std::cerr << "skipped blacklisted file " << filepath << std::endl; + continue; + } + + std::cout << "\tgamename: " << games[i].dlcs[j].gamename << std::endl + << "\tid: " << games[i].dlcs[j].languagepacks[k].id << std::endl + << "\tname: " << games[i].dlcs[j].languagepacks[k].name << std::endl + << "\tpath: " << games[i].dlcs[j].languagepacks[k].path << std::endl + << "\tsize: " << games[i].dlcs[j].languagepacks[k].size << std::endl + << std::endl; + } } } } @@ -910,6 +926,41 @@ void Downloader::repair() std::cout << std::endl; } } + if (config.bLanguagePacks) + { + for (unsigned int k = 0; k < games[i].dlcs[j].languagepacks.size(); ++k) + { + std::string filepath = games[i].dlcs[j].languagepacks[k].getFilepath(); + if (config.blacklist.isBlacklisted(filepath)) { + if (config.bVerbose) + std::cerr << "skipped blacklisted file " << filepath << std::endl; + continue; + } + + // Get XML data + std::string XML = ""; + if (config.bRemoteXML) + { + XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].languagepacks[k].id); + if (gogAPI->getError()) + { + std::cerr << gogAPI->getErrorMessage() << std::endl; + gogAPI->clearError(); + } + } + + std::string url = gogAPI->getLanguagePackLink(games[i].dlcs[j].gamename, games[i].dlcs[j].languagepacks[k].id); + if (gogAPI->getError()) + { + std::cerr << gogAPI->getErrorMessage() << std::endl; + gogAPI->clearError(); + continue; + } + std::cout << "Repairing file " << filepath << std::endl; + this->repairFile(url, filepath, XML, games[i].dlcs[j].gamename); + std::cout << std::endl; + } + } } } } @@ -1013,6 +1064,13 @@ void Downloader::download() dlQueue.push(games[i].dlcs[j].extras[k]); } } + if (config.bLanguagePacks) + { + for (unsigned int k = 0; k < games[i].dlcs[j].languagepacks.size(); ++k) + { + dlQueue.push(games[i].dlcs[j].languagepacks[k]); + } + } } } } @@ -2086,8 +2144,8 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].installers[j].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string remoteHash; std::string localHash; bool bHashOK = true; // assume hash OK @@ -2149,8 +2207,8 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].extras[j].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string localHash = this->getLocalFileHash(filepath.string(), games[i].gamename); uintmax_t filesize; @@ -2172,8 +2230,8 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].patches[j].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string localHash = this->getLocalFileHash(filepath.string(), games[i].gamename); uintmax_t filesize; @@ -2195,8 +2253,8 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].languagepacks[j].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string localHash = this->getLocalFileHash(filepath.string(), games[i].gamename); uintmax_t filesize; @@ -2222,8 +2280,8 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].dlcs[j].installers[k].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string remoteHash; std::string localHash; bool bHashOK = true; // assume hash OK @@ -2285,8 +2343,8 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].dlcs[j].patches[k].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string localHash = this->getLocalFileHash(filepath.string(), games[i].dlcs[j].gamename); uintmax_t filesize; @@ -2308,8 +2366,31 @@ void Downloader::checkStatus() { boost::filesystem::path filepath = games[i].dlcs[j].extras[k].getFilepath(); - if (config.blacklist.isBlacklisted(filepath.native())) - continue; + if (config.blacklist.isBlacklisted(filepath.native())) + continue; + std::string localHash = this->getLocalFileHash(filepath.string(), games[i].dlcs[j].gamename); + uintmax_t filesize; + + if (boost::filesystem::exists(filepath) && boost::filesystem::is_regular_file(filepath)) + { + filesize = boost::filesystem::file_size(filepath); + std::cout << "OK " << games[i].dlcs[j].gamename << " " << filepath.filename().string() << " " << filesize << " " << localHash << std::endl; + } + else + { + std::cout << "ND " << games[i].dlcs[j].gamename << " " << filepath.filename().string() << std::endl; + } + } + } + + if (config.bLanguagePacks) + { + for (unsigned int k = 0; k < games[i].dlcs[j].languagepacks.size(); ++k) + { + boost::filesystem::path filepath = games[i].dlcs[j].languagepacks[k].getFilepath(); + + if (config.blacklist.isBlacklisted(filepath.native())) + continue; std::string localHash = this->getLocalFileHash(filepath.string(), games[i].dlcs[j].gamename); uintmax_t filesize; @@ -3166,7 +3247,7 @@ void Downloader::printProgress() char progress_percentage_text[200]; sprintf(progress_percentage_text, "%3.0f%% ", fraction * 100); - int progress_percentage_text_length = strlen(progress_percentage_text); + int progress_percentage_text_length = strlen(progress_percentage_text) + 1; bptime::time_duration eta(bptime::seconds((long)((progress_info.dltotal - progress_info.dlnow) / progress_info.rate))); std::stringstream eta_ss; diff --git a/src/gamedetails.cpp b/src/gamedetails.cpp index c3d6a5b..d3c7530 100644 --- a/src/gamedetails.cpp +++ b/src/gamedetails.cpp @@ -132,6 +132,13 @@ void gameDetails::makeFilepaths(const gameSpecificDirectoryConfig& config) filepath = Util::makeFilepath(directory, this->dlcs[i].extras[j].path, this->gamename, subdir, 0, this->dlcs[i].gamename); this->dlcs[i].extras[j].setFilepath(filepath); } + + for (unsigned int j = 0; j < this->dlcs[i].languagepacks.size(); ++j) + { + subdir = config.bSubDirectories ? config.sDLCSubdir + "/" + config.sLanguagePackSubdir : ""; + filepath = Util::makeFilepath(directory, this->dlcs[i].languagepacks[j].path, this->gamename, subdir, 0, this->dlcs[i].gamename); + this->dlcs[i].languagepacks[j].setFilepath(filepath); + } } }