mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
Handle new modlist being empty but still valid
This commit is contained in:
parent
3cf1a2e51b
commit
4fbd25b551
@ -362,13 +362,15 @@ std::string GetSha256HashReallyFast(const std::string& filename) {
|
||||
}
|
||||
|
||||
struct ModInfo {
|
||||
static std::vector<ModInfo> ParseModInfosFromPacket(const std::string& packet) {
|
||||
static std::pair<bool, std::vector<ModInfo>> ParseModInfosFromPacket(const std::string& packet) {
|
||||
bool success = false;
|
||||
std::vector<ModInfo> modInfos;
|
||||
try {
|
||||
auto json = nlohmann::json::parse(packet);
|
||||
if (json.empty()) {
|
||||
return modInfos;
|
||||
return std::make_pair(true, modInfos);
|
||||
}
|
||||
|
||||
for (const auto& entry : json) {
|
||||
ModInfo modInfo {
|
||||
.FileName = entry["file_name"],
|
||||
@ -377,13 +379,14 @@ struct ModInfo {
|
||||
.HashAlgorithm = entry["hash_algorithm"],
|
||||
};
|
||||
modInfos.push_back(modInfo);
|
||||
success = true;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
debug(std::string("Failed to receive mod list: ") + e.what());
|
||||
error("Failed to receive mod list!");
|
||||
// TODO: Cry and die
|
||||
}
|
||||
return modInfos;
|
||||
return std::make_pair(success, modInfos);
|
||||
}
|
||||
std::string FileName;
|
||||
size_t FileSize;
|
||||
@ -392,6 +395,13 @@ struct ModInfo {
|
||||
};
|
||||
|
||||
void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<ModInfo> ModInfos) {
|
||||
if (ModInfos.empty()) {
|
||||
CoreSend("L");
|
||||
TCPSend("Done", Sock);
|
||||
info("Done!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SecurityWarning())
|
||||
return;
|
||||
|
||||
@ -518,8 +528,8 @@ void SyncResources(SOCKET Sock) {
|
||||
|
||||
auto ModInfos = ModInfo::ParseModInfosFromPacket(Ret);
|
||||
|
||||
if (!ModInfos.empty()) {
|
||||
NewSyncResources(Sock, Ret, ModInfos);
|
||||
if (ModInfos.first) {
|
||||
NewSyncResources(Sock, Ret, ModInfos.second);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user