mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
Download check (#184)
This PR makes it so that the mod hash and download confirmation are verified before proceeding. --- By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion. I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.
This commit is contained in:
commit
0341d401e7
@ -573,6 +573,13 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Data != "AG") {
|
||||||
|
UUl("Received corrupted download confirmation, aborting download.");
|
||||||
|
debug("Corrupted download confirmation: " + Data);
|
||||||
|
Terminate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Name = std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + FName;
|
std::string Name = std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + FName;
|
||||||
|
|
||||||
std::vector<char> DownloadedFile = SingleNormalDownload(Sock, ModInfoIter->FileSize, Name);
|
std::vector<char> DownloadedFile = SingleNormalDownload(Sock, ModInfoIter->FileSize, Name);
|
||||||
@ -587,11 +594,16 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
OutFile.write(DownloadedFile.data(), DownloadedFile.size());
|
OutFile.write(DownloadedFile.data(), DownloadedFile.size());
|
||||||
OutFile.flush();
|
OutFile.flush();
|
||||||
}
|
}
|
||||||
// 2. verify size
|
// 2. verify size and hash
|
||||||
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
|
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
|
||||||
error("Failed to write the entire file '" + PathToSaveTo + "' correctly (file size mismatch)");
|
error("Failed to write the entire file '" + PathToSaveTo + "' correctly (file size mismatch)");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GetSha256HashReallyFast(PathToSaveTo) != ModInfoIter->Hash) {
|
||||||
|
error("Failed to write or download the entire file '" + PathToSaveTo + "' correctly (hash mismatch)");
|
||||||
|
Terminate = true;
|
||||||
|
}
|
||||||
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
|
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
|
||||||
if (!Terminate) {
|
if (!Terminate) {
|
||||||
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user