#include <queue>
#include <fstream>
#include <sstream>
+#include <map>
#include "filesys.h"
#include "strfnd.h"
+#include "log.h"
// Get a dependency-sorted list of ModSpecs
core::list<ModSpec> getMods(core::list<std::string> &modspaths)
std::queue<ModSpec> mods_satisfied;
core::list<ModSpec> mods_unsorted;
core::list<ModSpec> mods_sorted;
+ // name, path: For detecting name conflicts
+ std::map<std::string, std::string> mod_names;
for(core::list<std::string>::Iterator i = modspaths.begin();
i != modspaths.end(); i++){
std::string modspath = *i;
continue;
std::string modname = dirlist[j].name;
std::string modpath = modspath + DIR_DELIM + modname;
+ // Detect mod name conflicts
+ {
+ std::map<std::string, std::string>::const_iterator i;
+ i = mod_names.find(modname);
+ if(i != mod_names.end()){
+ std::string s;
+ infostream<<"WARNING: Mod name conflict detected: "
+ <<std::endl
+ <<"Already loaded: "<<i->second<<std::endl
+ <<"Will not load: "<<modpath<<std::endl;
+ continue;
+ }
+ }
std::set<std::string> depends;
std::ifstream is((modpath+DIR_DELIM+"depends.txt").c_str(),
std::ios_base::binary);
mods_unsorted.push_back(spec);
if(depends.empty())
mods_satisfied.push(spec);
+ mod_names[modname] = modpath;
}
}
// Sort by depencencies
std::string builtinpath = porting::path_data + DIR_DELIM + "builtin.lua";
// Add default global mod search path
- m_modspaths.push_back(porting::path_data + DIR_DELIM + "mods");
+ m_modspaths.push_front(porting::path_data + DIR_DELIM + "mods");
// Add world mod search path
- m_modspaths.push_back(mapsavedir + DIR_DELIM + "mods");
+ m_modspaths.push_front(mapsavedir + DIR_DELIM + "mods");
// Initialize scripting