From 730c1ffe5875d2d7c6d31320f79b0f5be0e85890 Mon Sep 17 00:00:00 2001 From: Sude Date: Wed, 18 May 2016 14:11:37 +0300 Subject: [PATCH] Move code from Downloader::getLocalFileHash to Util::getLocalFileHash --- include/util.h | 1 + src/downloader.cpp | 27 +++------------------------ src/util.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/include/util.h b/include/util.h index 7135a5a..0317b1c 100644 --- a/include/util.h +++ b/include/util.h @@ -88,6 +88,7 @@ namespace Util unsigned int getOptionValue(const std::string& str, const std::vector& options); std::string getOptionNameString(const unsigned int& value, const std::vector& options); void parseOptionString(const std::string &option_string, std::vector &priority, unsigned int &type, const std::vector& options); + std::string getLocalFileHash(const std::string& xml_dir, const std::string& filepath, const std::string& gamename = std::string()); } #endif // UTIL_H diff --git a/src/downloader.cpp b/src/downloader.cpp index d02c85f..b15cec7 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -2555,33 +2555,12 @@ std::string Downloader::getLocalFileHash(const std::string& filepath, const std: if (config.bAutomaticXMLCreation && !boost::filesystem::exists(local_xml_file) && boost::filesystem::exists(path)) { - std::string xml_directory = config.sXMLDirectory + "/" + gamename; - Util::createXML(filepath, config.iChunkSize, xml_directory); + std::string xml_directory = config.sXMLDirectory + "/" + gamename; + Util::createXML(filepath, config.iChunkSize, xml_directory); } - if (boost::filesystem::exists(local_xml_file)) - { - tinyxml2::XMLDocument local_xml; - local_xml.LoadFile(local_xml_file.string().c_str()); - tinyxml2::XMLElement *fileElemLocal = local_xml.FirstChildElement("file"); - if (!fileElemLocal && config.bAutomaticXMLCreation) - { - std::string xml_directory = config.sXMLDirectory + "/" + gamename; - Util::createXML(filepath, config.iChunkSize, xml_directory); - local_xml.LoadFile(local_xml_file.string().c_str()); - fileElemLocal = local_xml.FirstChildElement("file"); - } - if (fileElemLocal) - { - localHash = fileElemLocal->Attribute("md5"); - return localHash; - } - } + localHash = Util::getFileHash(path.string(), RHASH_MD5); - if (boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path)) - { - localHash = Util::getFileHash(path.string(), RHASH_MD5); - } return localHash; } diff --git a/src/util.cpp b/src/util.cpp index 8f8775d..fc190b8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -540,3 +540,32 @@ void Util::parseOptionString(const std::string &option_string, std::vectorAttribute("md5"); + } + } + else if (boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path)) + { + localHash = Util::getFileHash(path.string(), RHASH_MD5); + } + + return localHash; +}