This commit is contained in:
Sude 2022-11-22 16:41:45 +02:00
commit a4423b0548
2 changed files with 65 additions and 41 deletions

View File

@ -142,6 +142,7 @@ class Downloader
std::string getResponse(const std::string& url); std::string getResponse(const std::string& url);
std::string getLocalFileHash(const std::string& filepath, const std::string& gamename = std::string()); std::string getLocalFileHash(const std::string& filepath, const std::string& gamename = std::string());
std::string getRemoteFileHash(const gameFile& gf); std::string getRemoteFileHash(const gameFile& gf);
void addStatusLine(const std::string& statusCode, const std::string& gamename, const std::string& filepath, const uintmax_t& filesize, const std::string& localHash);
int loadGameDetailsCache(); int loadGameDetailsCache();
int saveGameDetailsCache(); int saveGameDetailsCache();
std::vector<gameDetails> getGameDetailsFromJsonNode(Json::Value root, const int& recursion_level = 0); std::vector<gameDetails> getGameDetailsFromJsonNode(Json::Value root, const int& recursion_level = 0);

View File

@ -1962,27 +1962,12 @@ void Downloader::checkStatus()
if (Globals::globalConfig.blacklist.isBlacklisted(filepath.native())) if (Globals::globalConfig.blacklist.isBlacklisted(filepath.native()))
continue; continue;
std::string filePathString = filepath.filename().string();
std::string gamename = vGameFiles[i].gamename; std::string gamename = vGameFiles[i].gamename;
if (boost::filesystem::exists(filepath) && boost::filesystem::is_regular_file(filepath)) if (boost::filesystem::exists(filepath) && boost::filesystem::is_regular_file(filepath))
{ {
std::string remoteHash;
bool bHashOK = true; // assume hash OK
uintmax_t filesize = boost::filesystem::file_size(filepath); uintmax_t filesize = boost::filesystem::file_size(filepath);
// GOG only provides xml data for installers, patches and language packs
if (type & (GFTYPE_INSTALLER | GFTYPE_PATCH | GFTYPE_LANGPACK))
remoteHash = this->getRemoteFileHash(vGameFiles[i]);
std::string localHash = this->getLocalFileHash(filepath.string(), gamename);
if (!remoteHash.empty())
{
if (remoteHash != localHash)
bHashOK = false;
else
{
// Check for incomplete file by comparing the filesizes
// Remote hash was saved but download was incomplete and therefore getLocalFileHash returned the same as getRemoteFileHash
uintmax_t filesize_xml = 0; uintmax_t filesize_xml = 0;
boost::filesystem::path path = filepath; boost::filesystem::path path = filepath;
boost::filesystem::path local_xml_file; boost::filesystem::path local_xml_file;
@ -2003,22 +1988,60 @@ void Downloader::checkStatus()
} }
} }
if (Globals::globalConfig.bSizeOnly)
{
// Check for incomplete file by comparing the filesizes
if (filesize_xml > 0 && filesize_xml != filesize)
{
addStatusLine("FS", gamename, filePathString, filesize, "");
continue;
}
else
{
addStatusLine("OK", gamename, filePathString, filesize, "");
continue;
}
}
else
{
std::string remoteHash;
bool bHashOK = true; // assume hash OK
// GOG only provides xml data for installers, patches and language packs
if (type & (GFTYPE_INSTALLER | GFTYPE_PATCH | GFTYPE_LANGPACK))
remoteHash = this->getRemoteFileHash(vGameFiles[i]);
std::string localHash = this->getLocalFileHash(filepath.string(), gamename);
if (!remoteHash.empty())
{
if (remoteHash != localHash)
bHashOK = false;
else
{
// Check for incomplete file by comparing the filesizes
// Remote hash was saved but download was incomplete and therefore getLocalFileHash returned the same as getRemoteFileHash
if (filesize_xml > 0 && filesize_xml != filesize) if (filesize_xml > 0 && filesize_xml != filesize)
{ {
localHash = Util::getFileHash(path.string(), RHASH_MD5); localHash = Util::getFileHash(path.string(), RHASH_MD5);
std::cout << "FS " << gamename << " " << filepath.filename().string() << " " << filesize << " " << localHash << std::endl; addStatusLine("FS", gamename, filePathString, filesize, localHash);
continue; continue;
} }
} }
} }
std::cout << (bHashOK ? "OK " : "MD5 ") << gamename << " " << filepath.filename().string() << " " << filesize << " " << localHash << std::endl; addStatusLine(bHashOK ? "OK" : "MD5", gamename, filePathString, filesize, localHash);
}
} }
else else
{ {
std::cout << "ND " << gamename << " " << filepath.filename().string() << std::endl; addStatusLine("ND", gamename, filePathString, 0, "");
} }
} }
return;
}
void Downloader::addStatusLine(const std::string& statusCode, const std::string& gamename, const std::string& filepath, const uintmax_t& filesize, const std::string& localHash)
{
std::cout << statusCode << " " << gamename << " " << filepath << " " << filesize << " " << localHash << std::endl;
return; return;
} }