mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Move code from Downloader::getLocalFileHash to Util::getLocalFileHash
This commit is contained in:
parent
4c02de5d24
commit
730c1ffe58
@ -88,6 +88,7 @@ namespace Util
|
||||
unsigned int getOptionValue(const std::string& str, const std::vector<GlobalConstants::optionsStruct>& options);
|
||||
std::string getOptionNameString(const unsigned int& value, const std::vector<GlobalConstants::optionsStruct>& options);
|
||||
void parseOptionString(const std::string &option_string, std::vector<unsigned int> &priority, unsigned int &type, const std::vector<GlobalConstants::optionsStruct>& options);
|
||||
std::string getLocalFileHash(const std::string& xml_dir, const std::string& filepath, const std::string& gamename = std::string());
|
||||
}
|
||||
|
||||
#endif // UTIL_H
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
29
src/util.cpp
29
src/util.cpp
@ -540,3 +540,32 @@ void Util::parseOptionString(const std::string &option_string, std::vector<unsig
|
||||
type |= value;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Util::getLocalFileHash(const std::string& xml_dir, const std::string& filepath, const std::string& gamename)
|
||||
{
|
||||
std::string localHash;
|
||||
boost::filesystem::path path = filepath;
|
||||
boost::filesystem::path local_xml_file;
|
||||
if (!gamename.empty())
|
||||
local_xml_file = xml_dir + "/" + gamename + "/" + path.filename().string() + ".xml";
|
||||
else
|
||||
local_xml_file = xml_dir + "/" + path.filename().string() + ".xml";
|
||||
|
||||
if (boost::filesystem::exists(local_xml_file))
|
||||
{
|
||||
tinyxml2::XMLDocument local_xml;
|
||||
local_xml.LoadFile(local_xml_file.string().c_str());
|
||||
tinyxml2::XMLElement *fileElem = local_xml.FirstChildElement("file");
|
||||
|
||||
if (fileElem)
|
||||
{
|
||||
localHash = fileElem->Attribute("md5");
|
||||
}
|
||||
}
|
||||
else if (boost::filesystem::exists(path) && boost::filesystem::is_regular_file(path))
|
||||
{
|
||||
localHash = Util::getFileHash(path.string(), RHASH_MD5);
|
||||
}
|
||||
|
||||
return localHash;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user