From 1c26af48d2a93e72a1855c3f57f9cfc09c4b5ef5 Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 17 Feb 2014 14:19:40 +0200 Subject: [PATCH] Use subdirectories for extras, patches and languagepacks The simple extras detection in Util::makeFilePath is replaced with argument for setting subdirectory --- include/util.h | 2 +- src/downloader.cpp | 18 +++++++++--------- src/util.cpp | 14 ++++++-------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/util.h b/include/util.h index 7c088e0..27eba08 100644 --- a/include/util.h +++ b/include/util.h @@ -17,7 +17,7 @@ namespace Util { - std::string makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename); + std::string makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename, std::string subdirectory = ""); std::string getFileHash(const std::string& filename, unsigned hash_id); std::string getChunkHash(unsigned char* chunk, size_t chunk_size, unsigned hash_id); int createXML(std::string filepath, size_t chunk_size, std::string xml_dir = std::string()); diff --git a/src/downloader.cpp b/src/downloader.cpp index 00fe35f..28f05f9 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -390,7 +390,7 @@ void Downloader::repair() { for (unsigned int j = 0; j < games[i].extras.size(); ++j) { - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename, "extras"); std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id); if (gogAPI->getError()) @@ -410,7 +410,7 @@ void Downloader::repair() { for (unsigned int j = 0; j < games[i].patches.size(); ++j) { - 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, "patches"); std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id); if (gogAPI->getError()) @@ -430,7 +430,7 @@ void Downloader::repair() { 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 filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename, "languagepacks"); std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id); if (gogAPI->getError()) @@ -520,7 +520,7 @@ void Downloader::download() continue; } - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename, "extras"); // Download if (!url.empty()) @@ -553,7 +553,7 @@ void Downloader::download() continue; } - 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, "patches"); // Download if (!url.empty()) @@ -586,7 +586,7 @@ void Downloader::download() continue; } - std::string filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename); + std::string filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename, "languagepacks"); // Download if (!url.empty()) @@ -1644,7 +1644,7 @@ void Downloader::checkStatus() { for (unsigned int j = 0; j < games[i].extras.size(); ++j) { - boost::filesystem::path filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename); + boost::filesystem::path filepath = Util::makeFilepath(config.sDirectory, games[i].extras[j].path, games[i].gamename, "extras"); std::string localHash = this->getLocalFileHash(filepath.string()); size_t filesize; @@ -1665,7 +1665,7 @@ void Downloader::checkStatus() { for (unsigned int j = 0; j < games[i].patches.size(); ++j) { - boost::filesystem::path filepath = Util::makeFilepath(config.sDirectory, games[i].patches[j].path, games[i].gamename); + boost::filesystem::path filepath = Util::makeFilepath(config.sDirectory, games[i].patches[j].path, games[i].gamename, "patches"); std::string localHash = this->getLocalFileHash(filepath.string()); size_t filesize; @@ -1686,7 +1686,7 @@ void Downloader::checkStatus() { for (unsigned int j = 0; j < games[i].languagepacks.size(); ++j) { - boost::filesystem::path filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename); + boost::filesystem::path filepath = Util::makeFilepath(config.sDirectory, games[i].languagepacks[j].path, games[i].gamename, "languagepacks"); std::string localHash = this->getLocalFileHash(filepath.string()); size_t filesize; diff --git a/src/util.cpp b/src/util.cpp index 6d2224a..523dad7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -14,7 +14,7 @@ Remove the leading slash from path if needed Use gamename as base directory if specified */ -std::string Util::makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename) +std::string Util::makeFilepath(const std::string& directory, const std::string& path, const std::string& gamename, std::string subdirectory) { std::string filepath; @@ -32,14 +32,12 @@ std::string Util::makeFilepath(const std::string& directory, const std::string& } else { - std::string extras = ""; - if (path.find("extras")!=std::string::npos) - { - extras = "/extras"; - } - std::string filename = path.substr(path.find_last_of("/")+1, path.length()); - filepath = directory + gamename + extras + "/" + filename; + if (!subdirectory.empty()) + { + subdirectory = "/" + subdirectory; + } + filepath = directory + gamename + subdirectory + "/" + filename; } return filepath;