X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmods.cpp;h=a81dd46045d48fdc7d66ce6875052f9fd451723a;hb=0ba1cf82033a810dd2e6178e23794bb135ede46a;hp=75c2dd89cd636ce6cf0434ddff1741b07ca0724d;hpb=967121a34bbc60e6b46c7ec470b151f668ef1fef;p=minetest.git diff --git a/src/mods.cpp b/src/mods.cpp index 75c2dd89c..a81dd4604 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -17,15 +17,15 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include #include "mods.h" -#include "main.h" #include "filesys.h" #include "strfnd.h" #include "log.h" #include "subgame.h" #include "settings.h" #include "strfnd.h" -#include #include "convert_json.h" static bool parseDependsLine(std::istream &is, @@ -47,6 +47,11 @@ static bool parseDependsLine(std::istream &is, 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(); @@ -77,16 +82,6 @@ void parseModContents(ModSpec &spec) } } } - - // FIXME: optdepends.txt is deprecated - // remove this code at some point in the future - std::ifstream is2((spec.path+DIR_DELIM+"optdepends.txt").c_str()); - while(is2.good()){ - std::string dep; - std::set symbols; - if(parseDependsLine(is2, dep, symbols)) - spec.optdepends.insert(dep); - } } } @@ -114,26 +109,6 @@ std::map getModsInPath(std::string path, bool part_of_modp return result; } -ModSpec findCommonMod(const std::string &modname) -{ - // Try to find in {$user,$share}/games/common/$modname - std::vector find_paths; - find_paths.push_back(porting::path_user + DIR_DELIM + "games" + - DIR_DELIM + "common" + DIR_DELIM + "mods" + DIR_DELIM + modname); - find_paths.push_back(porting::path_share + DIR_DELIM + "games" + - DIR_DELIM + "common" + DIR_DELIM + "mods" + DIR_DELIM + modname); - for(u32 i=0; i flattenModTree(std::map mods) { std::map result; @@ -143,11 +118,11 @@ std::map flattenModTree(std::map mod ModSpec mod = (*it).second; if(mod.is_modpack) { - std::map content = + std::map content = flattenModTree(mod.modpack_content); result.insert(content.begin(),content.end()); result.insert(std::make_pair(mod.name,mod)); - } + } else //not a modpack { result.insert(std::make_pair(mod.name,mod)); @@ -168,8 +143,8 @@ std::vector flattenMods(std::map mods) std::vector content = flattenMods(mod.modpack_content); result.reserve(result.size() + content.size()); result.insert(result.end(),content.begin(),content.end()); - - } + + } else //not a modpack { result.push_back(mod); @@ -182,36 +157,6 @@ ModConfiguration::ModConfiguration(std::string worldpath) { SubgameSpec gamespec = findWorldSubgame(worldpath); - // Add common mods - std::map common_mods; - std::vector inexistent_common_mods; - Settings gameconf; - if(getGameConfig(gamespec.path, gameconf)){ - if(gameconf.exists("common_mods")){ - Strfnd f(gameconf.get("common_mods")); - while(!f.atend()){ - std::string modname = trim(f.next(",")); - if(modname.empty()) - continue; - ModSpec spec = findCommonMod(modname); - if(spec.name.empty()) - inexistent_common_mods.push_back(modname); - else - common_mods.insert(std::make_pair(modname, spec)); - } - } - } - if(!inexistent_common_mods.empty()){ - std::string s = "Required common mods "; - for(u32 i=0; i names = worldmt_settings.getNames(); std::set include_mod_names; - for(std::vector::iterator it = names.begin(); + for(std::vector::iterator it = names.begin(); it != names.end(); ++it) - { - std::string name = *it; + { + std::string name = *it; // for backwards compatibility: exclude only mods which are // explicitely excluded. if mod is not mentioned at all, it is // enabled. So by default, all installed mods are enabled. @@ -294,13 +239,13 @@ void ModConfiguration::addMods(std::vector new_mods) // Add all the mods that come from modpacks // Second iteration: // Add all the mods that didn't come from modpacks - + std::set seen_this_iteration; for(std::vector::const_iterator it = new_mods.begin(); it != new_mods.end(); ++it){ const ModSpec &mod = *it; - if(mod.part_of_modpack != want_from_modpack) + if(mod.part_of_modpack != (bool)want_from_modpack) continue; if(existing_mods.count(mod.name) == 0){ // GOOD CASE: completely new mod. @@ -385,7 +330,7 @@ void ModConfiguration::resolveDependencies() else{ ++it; } - } + } } // Step 4: write back list of unsatisfied mods @@ -395,25 +340,18 @@ void ModConfiguration::resolveDependencies() #if USE_CURL Json::Value getModstoreUrl(std::string url) { - struct curl_slist *chunk = NULL; + std::vector extra_headers; bool special_http_header = true; - try{ + try { special_http_header = g_settings->getBool("modstore_disable_special_http_header"); - } - catch(SettingNotFoundException &e) { - } - - if (special_http_header) - chunk = curl_slist_append(chunk, "Accept: application/vnd.minetest.mmdb-v1+json"); + } catch (SettingNotFoundException) {} - Json::Value retval = fetchJsonValue(url,chunk); - - if (chunk != NULL) - curl_slist_free_all(chunk); - - return retval; + if (special_http_header) { + extra_headers.push_back("Accept: application/vnd.minetest.mmdb-v1+json"); + } + return fetchJsonValue(url, special_http_header ? &extra_headers : NULL); } #endif