Skip to content

Commit

Permalink
modding: Additional sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 6, 2024
1 parent d65d1d2 commit 699735a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/modding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static std::vector<Sha256> mod_hash_list;


static void addLoadedMod(std::string modname, std::string filename, const std::string& fullRealPath);
static bool hasLoadedModRealPath(const std::string& fullRealPath);


static inline std::vector<std::string> split(std::string const &str, std::string const &sep)
Expand Down Expand Up @@ -122,6 +123,11 @@ size_t addSubdirs(const char *basedir, const char *subdir, const bool appendToPa
#ifdef DEBUG
debug(LOG_NEVER, "Adding [%s] to search path", tmpFullModRealPath.c_str());
#endif // DEBUG
if (hasLoadedModRealPath(tmpFullModRealPath))
{
debug(LOG_INFO, "Already loaded: %s, skipping", tmpFullModRealPath.c_str());
return true; // continue
}
if (PHYSFS_mount(tmpFullModRealPath.c_str(), NULL, appendToPath) != 0) // platform-dependent notation
{
numAddedMods++;
Expand Down Expand Up @@ -218,6 +224,13 @@ static void addLoadedMod(std::string modname, std::string filename, const std::s
mod_hash_list.clear();
}

static bool hasLoadedModRealPath(const std::string& fullRealPath)
{
return std::any_of(loaded_mods.begin(), loaded_mods.end(), [fullRealPath](const WzMods::LoadedMod& loadedMod) -> bool {
return loadedMod.fullRealPath == fullRealPath;
});
}

void clearLoadedMods()
{
loaded_mods.clear();
Expand Down

0 comments on commit 699735a

Please sign in to comment.