From d35567dd477f3fee2765b9a94a292dd464717674 Mon Sep 17 00:00:00 2001 From: Tixx <83774803+WiserTixx@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:07:25 +0100 Subject: [PATCH] Look for new mods in the old format --- src/Network/Resources.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 8dbb2ec..6df646c 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -458,6 +458,40 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vectorFileName).filename(); + fs::exists(OldCachedPath) && GetSha256HashReallyFast(OldCachedPath.string()) == ModInfoIter->Hash) { + debug("Mod '" + FileName + "' found in old cache, copying it to the new cache"); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + try { + fs::copy_file(OldCachedPath, PathToSaveTo, fs::copy_options::overwrite_existing); + + if (!fs::exists(GetGamePath() + "mods/multiplayer")) { + fs::create_directories(GetGamePath() + "mods/multiplayer"); + } + + auto modname = ModInfoIter->FileName; + +#if defined(__linux__) + // Linux version of the game doesnt support uppercase letters in mod names + for (char& c : modname) { + c = ::tolower(c); + } +#endif + + debug("Mod name: " + modname); + auto name = std::filesystem::path(GetGamePath()) / "mods/multiplayer" / modname; + std::string tmp_name = name.string(); + tmp_name += ".tmp"; + + fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing); + fs::rename(tmp_name, name); + } catch (std::exception& e) { + error("Failed copy to the mods folder! " + std::string(e.what())); + Terminate = true; + continue; + } + WaitForConfirm(); + continue; } CheckForDir(); std::string FName = ModInfoIter->FileName;