mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-05 15:26:11 +00:00
Check hashes after downloading
This commit is contained in:
@@ -127,7 +127,7 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
||||
return Ret;
|
||||
}
|
||||
|
||||
bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path) {
|
||||
bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path, const std::string& Hash) {
|
||||
static std::mutex Lock;
|
||||
std::scoped_lock Guard(Lock);
|
||||
|
||||
@@ -139,6 +139,16 @@ bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string RetHash = Utils::GetSha256HashReallyFast(Ret, Path);
|
||||
|
||||
debug("Return hash: " + RetHash);
|
||||
debug("Expected hash: " + Hash);
|
||||
|
||||
if (RetHash != Hash) {
|
||||
error("Downloaded file hash does not match expected hash");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ofstream File(Path, std::ios::binary);
|
||||
if (File.is_open()) {
|
||||
File << Ret;
|
||||
|
||||
Reference in New Issue
Block a user