From e51d345a20db6dc59154678da2fa864d16f8100d Mon Sep 17 00:00:00 2001 From: Rémy Raes Date: Fri, 15 Sep 2023 00:31:37 +0200 Subject: feat: Enforce Thunderstore format for remote mods (#535) * feat: enforce Thunderstore format for remote mods * refactor: remove remote mods directory from "classic" mod loading --------- Co-authored-by: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> --- NorthstarDLL/mods/modmanager.cpp | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'NorthstarDLL/mods') diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index 044ec6d4..1ca51ad7 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -612,32 +612,35 @@ void ModManager::LoadMods() // get mod directories std::filesystem::directory_iterator classicModsDir = fs::directory_iterator(GetModFolderPath()); std::filesystem::directory_iterator remoteModsDir = fs::directory_iterator(GetRemoteModFolderPath()); + std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath()); - for (std::filesystem::directory_iterator modIterator : {classicModsDir, remoteModsDir}) - for (fs::directory_entry dir : modIterator) - if (fs::exists(dir.path() / "mod.json")) - modDirs.push_back(dir.path()); + for (fs::directory_entry dir : classicModsDir) + if (fs::exists(dir.path() / "mod.json")) + modDirs.push_back(dir.path()); - // Special case for Thunderstore mods dir - std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath()); + // Special case for Thunderstore and remote mods directories // Set up regex for `AUTHOR-MOD-VERSION` pattern std::regex pattern(R"(.*\\([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)-(\d+\.\d+\.\d+))"); - for (fs::directory_entry dir : thunderstoreModsDir) + + for (fs::directory_iterator dirIterator : {thunderstoreModsDir, remoteModsDir}) { - fs::path modsDir = dir.path() / "mods"; // Check for mods folder in the Thunderstore mod - // Use regex to match `AUTHOR-MOD-VERSION` pattern - if (!std::regex_match(dir.path().string(), pattern)) - { - spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", dir.path().string()); - continue; // skip loading mod that doesn't match - } - if (fs::exists(modsDir) && fs::is_directory(modsDir)) + for (fs::directory_entry dir : dirIterator) { - for (fs::directory_entry subDir : fs::directory_iterator(modsDir)) + fs::path modsDir = dir.path() / "mods"; // Check for mods folder in the Thunderstore mod + // Use regex to match `AUTHOR-MOD-VERSION` pattern + if (!std::regex_match(dir.path().string(), pattern)) { - if (fs::exists(subDir.path() / "mod.json")) + spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", dir.path().string()); + continue; // skip loading mod that doesn't match + } + if (fs::exists(modsDir) && fs::is_directory(modsDir)) + { + for (fs::directory_entry subDir : fs::directory_iterator(modsDir)) { - modDirs.push_back(subDir.path()); + if (fs::exists(subDir.path() / "mod.json")) + { + modDirs.push_back(subDir.path()); + } } } } -- cgit v1.2.3