From 0309af134ef01e0074057e0580c8155028998fcf Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sun, 16 Jul 2023 21:23:50 +0200 Subject: Add support for loading Thunderstore mods natively (#503) Allows for loading Thunderstore mods directly from a separate directory called `packages`. --- NorthstarDLL/mods/modmanager.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'NorthstarDLL/mods/modmanager.cpp') diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp index d2cc8eb8..c54314c0 100644 --- a/NorthstarDLL/mods/modmanager.cpp +++ b/NorthstarDLL/mods/modmanager.cpp @@ -587,6 +587,7 @@ void ModManager::LoadMods() // ensure dirs exist fs::remove_all(GetCompiledAssetsPath()); fs::create_directories(GetModFolderPath()); + fs::create_directories(GetThunderstoreModFolderPath()); fs::create_directories(GetRemoteModFolderPath()); m_DependencyConstants.clear(); @@ -616,6 +617,31 @@ void ModManager::LoadMods() 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()); + // 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) + { + 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': {}", modsDir.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)) + { + if (fs::exists(subDir.path() / "mod.json")) + { + modDirs.push_back(subDir.path()); + } + } + } + } + for (fs::path modDir : modDirs) { // read mod json file @@ -1049,6 +1075,10 @@ fs::path GetModFolderPath() { return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX); } +fs::path GetThunderstoreModFolderPath() +{ + return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX); +} fs::path GetRemoteModFolderPath() { return fs::path(GetNorthstarPrefix() + REMOTE_MOD_FOLDER_SUFFIX); -- cgit v1.2.3