-static void collectMods(const std::string &modspath,
- std::queue<ModSpec> &mods_satisfied,
- core::list<ModSpec> &mods_unsorted,
- std::map<std::string, std::string> &mod_names,
- std::string indentation)
-{
- TRACESTREAM(<<indentation<<"collectMods(\""<<modspath<<"\")"<<std::endl);
- TRACEDO(indentation += " ");
- std::vector<fs::DirListNode> dirlist = fs::GetDirListing(modspath);
- for(u32 j=0; j<dirlist.size(); j++){
- if(!dirlist[j].dir)
- continue;
- std::string modname = dirlist[j].name;
- std::string modpath = modspath + DIR_DELIM + modname;
- TRACESTREAM(<<indentation<<"collectMods: "<<modname<<" at \""<<modpath<<"\""<<std::endl);
- // Handle modpacks (defined by containing modpack.txt)
- {
- std::ifstream is((modpath+DIR_DELIM+"modpack.txt").c_str(),
- std::ios_base::binary);
- if(is.good()){
- // Is a modpack
- is.close(); // We don't actually need the file
- // Recurse into it
- collectMods(modpath, mods_satisfied, mods_unsorted, mod_names, indentation);
- continue;
+static bool parseDependsLine(std::istream &is,
+ std::string &dep, std::set<char> &symbols)
+{
+ std::getline(is, dep);
+ dep = trim(dep);
+ symbols.clear();
+ size_t pos = dep.size();
+ while(pos > 0 && !string_allowed(dep.substr(pos-1, 1), MODNAME_ALLOWED_CHARS)){
+ // last character is a symbol, not part of the modname
+ symbols.insert(dep[pos-1]);
+ --pos;
+ }
+ dep = trim(dep.substr(0, pos));
+ return !dep.empty();
+}
+
+void parseModContents(ModSpec &spec)
+{
+ // NOTE: this function works in mutual recursion with getModsInPath
+ Settings info;
+ info.readConfigFile((spec.path+DIR_DELIM+"mod.conf").c_str());
+
+ if (info.exists("name"))
+ spec.name = info.get("name");
+
+ spec.depends.clear();
+ spec.optdepends.clear();
+ spec.is_modpack = false;
+ spec.modpack_content.clear();
+
+ // Handle modpacks (defined by containing modpack.txt)
+ std::ifstream modpack_is((spec.path+DIR_DELIM+"modpack.txt").c_str());
+ if(modpack_is.good()){ //a modpack, recursively get the mods in it
+ modpack_is.close(); // We don't actually need the file
+ spec.is_modpack = true;
+ spec.modpack_content = getModsInPath(spec.path, true);
+
+ // modpacks have no dependencies; they are defined and
+ // tracked separately for each mod in the modpack
+ }
+ else{ // not a modpack, parse the dependencies
+ std::ifstream is((spec.path+DIR_DELIM+"depends.txt").c_str());
+ while(is.good()){
+ std::string dep;
+ std::set<char> symbols;
+ if(parseDependsLine(is, dep, symbols)){
+ if(symbols.count('?') != 0){
+ spec.optdepends.insert(dep);
+ }
+ else{
+ spec.depends.insert(dep);
+ }