Skip to content

Commit

Permalink
feat: Enforce Thunderstore format for remote mods (#535)
Browse files Browse the repository at this point in the history
* feat: enforce Thunderstore format for remote mods

* refactor: remove remote mods directory from "classic" mod loading

---------

Co-authored-by: GeckoEidechse <[email protected]>
  • Loading branch information
Alystrasz and GeckoEidechse authored Sep 14, 2023
1 parent a27368d commit e51d345
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions NorthstarDLL/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
Expand Down

0 comments on commit e51d345

Please sign in to comment.