From 903d13ffff719f63f8f7b322ef8d81db72303f87 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 9 Jan 2025 13:15:36 +0100 Subject: [PATCH] Make sure mod paths are always absolute --- src/content/mod_configuration.cpp | 7 +++++-- src/content/mods.cpp | 3 ++- src/content/mods.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/content/mod_configuration.cpp b/src/content/mod_configuration.cpp index 37d2eadd4..810ea7626 100644 --- a/src/content/mod_configuration.cpp +++ b/src/content/mod_configuration.cpp @@ -47,7 +47,7 @@ void ModConfiguration::addMods(const std::vector &new_mods) } // Add new mods - for (int want_from_modpack = 1; want_from_modpack >= 0; --want_from_modpack) { + for (bool want_from_modpack : {true, false}) { // First iteration: // Add all the mods that come from modpacks // Second iteration: @@ -56,9 +56,12 @@ void ModConfiguration::addMods(const std::vector &new_mods) std::set seen_this_iteration; for (const ModSpec &mod : new_mods) { - if (mod.part_of_modpack != (bool)want_from_modpack) + if (mod.part_of_modpack != want_from_modpack) continue; + // unrelated to this code, but we want to assert it somewhere + assert(fs::IsPathAbsolute(mod.path)); + if (existing_mods.count(mod.name) == 0) { // GOOD CASE: completely new mod. m_unsatisfied_mods.push_back(mod); diff --git a/src/content/mods.cpp b/src/content/mods.cpp index a95ea0227..1c100f5a1 100644 --- a/src/content/mods.cpp +++ b/src/content/mods.cpp @@ -167,6 +167,7 @@ std::map getModsInPath( mod_path.clear(); mod_path.append(path).append(DIR_DELIM).append(modname); + mod_path = fs::AbsolutePath(mod_path); mod_virtual_path.clear(); // Intentionally uses / to keep paths same on different platforms @@ -174,7 +175,7 @@ std::map getModsInPath( ModSpec spec(modname, mod_path, part_of_modpack, mod_virtual_path); parseModContents(spec); - result.insert(std::make_pair(modname, spec)); + result[modname] = std::move(spec); } return result; } diff --git a/src/content/mods.h b/src/content/mods.h index b6083fe19..a7e1e5041 100644 --- a/src/content/mods.h +++ b/src/content/mods.h @@ -25,7 +25,7 @@ struct ModSpec { std::string name; std::string author; - std::string path; + std::string path; // absolute path on disk std::string desc; int release = 0;