Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change mod loading location #746

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions primedev/mods/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ void ModManager::LoadMods()

// ensure dirs exist
fs::remove_all(GetCompiledAssetsPath());
fs::create_directories(GetModFolderPath());
fs::create_directories(GetThunderstoreModFolderPath());
fs::create_directories(GetCoreModFolderPath());
fs::create_directories(GetManualModFolderPath());
fs::create_directories(GetThunderstoreLegacyModFolderPath());
fs::create_directories(GetRemoteModFolderPath());

m_DependencyConstants.clear();
Expand All @@ -138,11 +139,27 @@ void ModManager::LoadMods()
}

// get mod directories
std::filesystem::directory_iterator classicModsDir = fs::directory_iterator(GetModFolderPath());
std::filesystem::directory_iterator coreModsDir = fs::directory_iterator(GetCoreModFolderPath());
std::filesystem::directory_iterator manualModsDir = fs::directory_iterator(GetManualModFolderPath());
std::filesystem::directory_iterator remoteModsDir = fs::directory_iterator(GetRemoteModFolderPath());
std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath());
std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreLegacyModFolderPath());

for (fs::directory_entry dir : classicModsDir)
// Set up regex for `Northstar.*` pattern
std::regex northstar_pattern(R"(.*\\Northstar\..+)");
for (fs::directory_entry dir : coreModsDir)
{
if (!std::regex_match(dir.path().string(), northstar_pattern))
{
spdlog::warn(
"The following directory did not match 'Northstar.*' and is most likely an incorrectly manually installed mod: {}",
dir.path().string());
continue; // skip loading mod that doesn't match
}
if (fs::exists(dir.path() / "mod.json"))
modDirs.push_back(dir.path());
}

for (fs::directory_entry dir : manualModsDir)
if (fs::exists(dir.path() / "mod.json"))
modDirs.push_back(dir.path());

Expand Down Expand Up @@ -666,13 +683,17 @@ void ConCommand_reload_mods(const CCommand& args)
g_pModManager->LoadMods();
}

fs::path GetModFolderPath()
fs::path GetCoreModFolderPath()
{
return fs::path(GetNorthstarPrefix() + CORE_MOD_FOLDER_SUFFIX);
}
fs::path GetManualModFolderPath()
{
return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX);
return fs::path(GetNorthstarPrefix() + MANUAL_MOD_FOLDER_SUFFIX);
}
fs::path GetThunderstoreModFolderPath()
fs::path GetThunderstoreLegacyModFolderPath()
{
return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX);
return fs::path(GetNorthstarPrefix() + THUNDERSTORE_LEGACY_MOD_FOLDER_SUFFIX);
}
fs::path GetRemoteModFolderPath()
{
Expand Down
10 changes: 6 additions & 4 deletions primedev/mods/modmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

namespace fs = std::filesystem;

const std::string MOD_FOLDER_SUFFIX = "\\mods";
const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\packages";
const std::string CORE_MOD_FOLDER_SUFFIX = "\\mods\\core";
const std::string MANUAL_MOD_FOLDER_SUFFIX = "\\mods\\manual";
const std::string THUNDERSTORE_LEGACY_MOD_FOLDER_SUFFIX = "\\mods\\thunderstore-legacy";
const std::string REMOTE_MOD_FOLDER_SUFFIX = "\\runtime\\remote\\mods";
const fs::path MOD_OVERRIDE_DIR = "mod";
const std::string COMPILED_ASSETS_SUFFIX = "\\runtime\\compiled";
Expand Down Expand Up @@ -60,9 +61,10 @@ class ModManager
void BuildKBActionsList();
};

fs::path GetModFolderPath();
fs::path GetCoreModFolderPath();
fs::path GetManualModFolderPath();
fs::path GetRemoteModFolderPath();
fs::path GetThunderstoreModFolderPath();
fs::path GetThunderstoreLegacyModFolderPath();
fs::path GetCompiledAssetsPath();

extern ModManager* g_pModManager;
4 changes: 2 additions & 2 deletions primedev/plugins/pluginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool PluginManager::LoadPlugins(bool reloaded)
return false;
}

fs::create_directories(GetThunderstoreModFolderPath());
fs::create_directories(GetThunderstoreLegacyModFolderPath());

std::vector<fs::path> paths;

Expand All @@ -73,7 +73,7 @@ bool PluginManager::LoadPlugins(bool reloaded)
FindPlugins(pluginPath, paths);

// Special case for Thunderstore mods dir
std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath());
std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreLegacyModFolderPath());
// 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)
Expand Down