diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index a71c41f..1cfa90e 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -478,8 +478,9 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector> CachedMods = {}; if (deleteDuplicateMods) { for (const auto& entry : fs::directory_iterator(CachingDirectory)) { - if (entry.is_regular_file() && entry.path().extension() == ".zip" && entry.path().filename().string().length() > 10) { - CachedMods.push_back(std::make_pair(entry.path().filename().string().substr(0, entry.path().filename().string().length() - 13) + ".zip", entry.path())); + const std::string filename = entry.path().filename().string(); + if (entry.is_regular_file() && entry.path().extension() == ".zip" && filename.length() > 10) { + CachedMods.push_back(std::make_pair(filename.substr(0, filename.length() - 13) + ".zip", entry.path())); } } } @@ -490,7 +491,9 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vectorFileName && CachedMod.second.stem().string() + ".zip" != std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + ".zip") { + const bool cachedModExists = CachedMod.first == ModInfoIter->FileName; + const bool cachedModIsNotNewestVersion = CachedMod.second.stem().string() + ".zip" != std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + ".zip"; + if (cachedModExists && cachedModIsNotNewestVersion) { debug("Found duplicate mod '" + CachedMod.second.stem().string() + ".zip" + "' in cache, removing it"); std::filesystem::remove(CachedMod.second); break;