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; +}