From c20db02f155caeaac9d241fd8ee19d50f71abec0 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 3 Jun 2024 13:07:42 -0700 Subject: [PATCH] Unload zips before loading zips This fixes a minor issue where if you had a zip in the levels list, but then removed it, it would still show up in the levels list after reloading it (if you also had a .vvvvvv file named the same as in the zip) even though it shouldn't. Thankfully, this didn't lead to a memory leak or duplicate zip mounts or anything like that, because PhysFS ignores mounting a zip if it's already mounted. This also didn't result in a level entry from a zip persisting after removal after reloading the levels list, because the entry would be gone due to the .vvvvvv file not being found. --- desktop_version/src/CustomLevels.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 2a7494cf..704bed37 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -251,6 +251,23 @@ static void levelMetaDataCallback(const char* filename) } } +static void unloadZips(void) +{ + char** list = PHYSFS_getSearchPath(); + if (list == NULL) + { + return; + } + for (char** path = list; *path != NULL; path++) + { + if (SDL_strncmp(*path, "levels/", 7) == 0 && endsWith(*path, ".zip")) + { + PHYSFS_unmount(*path); + } + } + PHYSFS_freeList(list); +} + void customlevelclass::getDirectoryData(void) { @@ -258,6 +275,8 @@ void customlevelclass::getDirectoryData(void) FILESYSTEM_clearLevelDirError(); + unloadZips(); + loadZips(); FILESYSTEM_enumerateLevelDirFileNames(levelMetaDataCallback);