From 1f0e8aaa4805db0298e5b6047b3c6628932a82fc Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 5 Jul 2024 00:19:18 +0200 Subject: [PATCH 1/5] wip: Change paths to load core and thunderstore mods from --- primedev/mods/modmanager.cpp | 6 +++--- primedev/mods/modmanager.h | 6 +++--- primedev/plugins/pluginmanager.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp index edf69c9fb..38bf1dc70 100644 --- a/primedev/mods/modmanager.cpp +++ b/primedev/mods/modmanager.cpp @@ -616,7 +616,7 @@ void ModManager::LoadMods() // ensure dirs exist fs::remove_all(GetCompiledAssetsPath()); fs::create_directories(GetModFolderPath()); - fs::create_directories(GetThunderstoreModFolderPath()); + fs::create_directories(GetThunderstoreLegacyModFolderPath()); fs::create_directories(GetRemoteModFolderPath()); m_DependencyConstants.clear(); @@ -640,7 +640,7 @@ 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()); + std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreLegacyModFolderPath()); for (fs::directory_entry dir : classicModsDir) if (fs::exists(dir.path() / "mod.json")) @@ -1131,7 +1131,7 @@ fs::path GetModFolderPath() { return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX); } -fs::path GetThunderstoreModFolderPath() +fs::path GetThunderstoreLegacyModFolderPath() { return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX); } diff --git a/primedev/mods/modmanager.h b/primedev/mods/modmanager.h index 233f004d4..7500a3d53 100644 --- a/primedev/mods/modmanager.h +++ b/primedev/mods/modmanager.h @@ -9,8 +9,8 @@ #include #include -const std::string MOD_FOLDER_SUFFIX = "\\mods"; -const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\packages"; +const std::string MOD_FOLDER_SUFFIX = "\\mods\\core"; +const std::string THUNDERSTORE_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"; @@ -181,7 +181,7 @@ class ModManager fs::path GetModFolderPath(); fs::path GetRemoteModFolderPath(); -fs::path GetThunderstoreModFolderPath(); +fs::path GetThunderstoreLegacyModFolderPath(); fs::path GetCompiledAssetsPath(); extern ModManager* g_pModManager; diff --git a/primedev/plugins/pluginmanager.cpp b/primedev/plugins/pluginmanager.cpp index 718e69568..1abd0def2 100644 --- a/primedev/plugins/pluginmanager.cpp +++ b/primedev/plugins/pluginmanager.cpp @@ -58,7 +58,7 @@ bool PluginManager::LoadPlugins(bool reloaded) return false; } - fs::create_directories(GetThunderstoreModFolderPath()); + fs::create_directories(GetThunderstoreLegacyModFolderPath()); std::vector paths; @@ -71,7 +71,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) From f5707e2b36a338961b3dabfde1c1668304f6ae66 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 5 Jul 2024 20:50:55 +0200 Subject: [PATCH 2/5] refactor: Rename mods folder to core mods --- primedev/mods/modmanager.cpp | 10 +++++----- primedev/mods/modmanager.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp index 38bf1dc70..b2a7e7135 100644 --- a/primedev/mods/modmanager.cpp +++ b/primedev/mods/modmanager.cpp @@ -615,7 +615,7 @@ void ModManager::LoadMods() // ensure dirs exist fs::remove_all(GetCompiledAssetsPath()); - fs::create_directories(GetModFolderPath()); + fs::create_directories(GetCoreModFolderPath()); fs::create_directories(GetThunderstoreLegacyModFolderPath()); fs::create_directories(GetRemoteModFolderPath()); @@ -638,11 +638,11 @@ 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 remoteModsDir = fs::directory_iterator(GetRemoteModFolderPath()); std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreLegacyModFolderPath()); - for (fs::directory_entry dir : classicModsDir) + for (fs::directory_entry dir : coreModsDir) if (fs::exists(dir.path() / "mod.json")) modDirs.push_back(dir.path()); @@ -1127,9 +1127,9 @@ void ConCommand_reload_mods(const CCommand& args) g_pModManager->LoadMods(); } -fs::path GetModFolderPath() +fs::path GetCoreModFolderPath() { - return fs::path(GetNorthstarPrefix() + MOD_FOLDER_SUFFIX); + return fs::path(GetNorthstarPrefix() + CORE_MOD_FOLDER_SUFFIX); } fs::path GetThunderstoreLegacyModFolderPath() { diff --git a/primedev/mods/modmanager.h b/primedev/mods/modmanager.h index 7500a3d53..ace79e327 100644 --- a/primedev/mods/modmanager.h +++ b/primedev/mods/modmanager.h @@ -9,7 +9,7 @@ #include #include -const std::string MOD_FOLDER_SUFFIX = "\\mods\\core"; +const std::string CORE_MOD_FOLDER_SUFFIX = "\\mods\\core"; const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\mods\\thunderstore-legacy"; const std::string REMOTE_MOD_FOLDER_SUFFIX = "\\runtime\\remote\\mods"; const fs::path MOD_OVERRIDE_DIR = "mod"; @@ -179,7 +179,7 @@ class ModManager void BuildKBActionsList(); }; -fs::path GetModFolderPath(); +fs::path GetCoreModFolderPath(); fs::path GetRemoteModFolderPath(); fs::path GetThunderstoreLegacyModFolderPath(); fs::path GetCompiledAssetsPath(); From 02c22d71624e567a770b9faa352ed0da3c39104f Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 5 Jul 2024 21:10:16 +0200 Subject: [PATCH 3/5] feat: Add support for manual mods folder --- primedev/mods/modmanager.cpp | 10 ++++++++++ primedev/mods/modmanager.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp index b2a7e7135..90f544494 100644 --- a/primedev/mods/modmanager.cpp +++ b/primedev/mods/modmanager.cpp @@ -616,6 +616,7 @@ void ModManager::LoadMods() // ensure dirs exist fs::remove_all(GetCompiledAssetsPath()); fs::create_directories(GetCoreModFolderPath()); + fs::create_directories(GetManualModFolderPath()); fs::create_directories(GetThunderstoreLegacyModFolderPath()); fs::create_directories(GetRemoteModFolderPath()); @@ -639,6 +640,7 @@ void ModManager::LoadMods() // get mod directories 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(GetThunderstoreLegacyModFolderPath()); @@ -646,6 +648,10 @@ void ModManager::LoadMods() 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()); + // 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+))"); @@ -1131,6 +1137,10 @@ fs::path GetCoreModFolderPath() { return fs::path(GetNorthstarPrefix() + CORE_MOD_FOLDER_SUFFIX); } +fs::path GetManualModFolderPath() +{ + return fs::path(GetNorthstarPrefix() + MANUAL_MOD_FOLDER_SUFFIX); +} fs::path GetThunderstoreLegacyModFolderPath() { return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX); diff --git a/primedev/mods/modmanager.h b/primedev/mods/modmanager.h index ace79e327..517b33a72 100644 --- a/primedev/mods/modmanager.h +++ b/primedev/mods/modmanager.h @@ -10,6 +10,7 @@ #include const std::string CORE_MOD_FOLDER_SUFFIX = "\\mods\\core"; +const std::string MANUAL_MOD_FOLDER_SUFFIX = "\\mods\\manual"; const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\mods\\thunderstore-legacy"; const std::string REMOTE_MOD_FOLDER_SUFFIX = "\\runtime\\remote\\mods"; const fs::path MOD_OVERRIDE_DIR = "mod"; @@ -180,6 +181,7 @@ class ModManager }; fs::path GetCoreModFolderPath(); +fs::path GetManualModFolderPath(); fs::path GetRemoteModFolderPath(); fs::path GetThunderstoreLegacyModFolderPath(); fs::path GetCompiledAssetsPath(); From 2d57c5d0ce5fffdf99e84fb5be6a24c9b1eed708 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 5 Jul 2024 21:17:07 +0200 Subject: [PATCH 4/5] refactor: Rename const for legacy thunderstore mod string --- primedev/mods/modmanager.cpp | 2 +- primedev/mods/modmanager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp index 90f544494..f0ddb0f51 100644 --- a/primedev/mods/modmanager.cpp +++ b/primedev/mods/modmanager.cpp @@ -1143,7 +1143,7 @@ fs::path GetManualModFolderPath() } fs::path GetThunderstoreLegacyModFolderPath() { - return fs::path(GetNorthstarPrefix() + THUNDERSTORE_MOD_FOLDER_SUFFIX); + return fs::path(GetNorthstarPrefix() + THUNDERSTORE_LEGACY_MOD_FOLDER_SUFFIX); } fs::path GetRemoteModFolderPath() { diff --git a/primedev/mods/modmanager.h b/primedev/mods/modmanager.h index 517b33a72..5f6d07e75 100644 --- a/primedev/mods/modmanager.h +++ b/primedev/mods/modmanager.h @@ -11,7 +11,7 @@ const std::string CORE_MOD_FOLDER_SUFFIX = "\\mods\\core"; const std::string MANUAL_MOD_FOLDER_SUFFIX = "\\mods\\manual"; -const std::string THUNDERSTORE_MOD_FOLDER_SUFFIX = "\\mods\\thunderstore-legacy"; +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"; From d4273d698523f7b8966bbee83beecc8131a21678 Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Fri, 5 Jul 2024 23:11:58 +0200 Subject: [PATCH 5/5] feat: Require core Northstar mods to be formatted starting with `Northstar.` in their mod name --- primedev/mods/modmanager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp index f0ddb0f51..b99c87610 100644 --- a/primedev/mods/modmanager.cpp +++ b/primedev/mods/modmanager.cpp @@ -644,9 +644,20 @@ void ModManager::LoadMods() std::filesystem::directory_iterator remoteModsDir = fs::directory_iterator(GetRemoteModFolderPath()); std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreLegacyModFolderPath()); + // 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"))