]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mods.cpp
Translated using Weblate (Chinese (Taiwan))
[dragonfireclient.git] / src / mods.cpp
index bcdda01ef72911e252cc17ca83c3b1b5023f857c..1b1bdb07b69ca7a420fed58fd58602adb3b82e60 100644 (file)
@@ -17,16 +17,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include <cctype>
+#include <fstream>
 #include "mods.h"
-#include "main.h"
 #include "filesys.h"
-#include "strfnd.h"
+#include "util/strfnd.h"
 #include "log.h"
 #include "subgame.h"
 #include "settings.h"
-#include "strfnd.h"
-#include <cctype>
+#include "util/strfnd.h"
 #include "convert_json.h"
+#include "exceptions.h"
 
 static bool parseDependsLine(std::istream &is,
                std::string &dep, std::set<char> &symbols)
@@ -47,6 +48,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 +83,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<char> symbols;
-                       if(parseDependsLine(is2, dep, symbols))
-                               spec.optdepends.insert(dep);
-               }
        }
 }
 
@@ -123,11 +119,11 @@ std::map<std::string, ModSpec> flattenModTree(std::map<std::string, ModSpec> mod
                ModSpec mod = (*it).second;
                if(mod.is_modpack)
                {
-                       std::map<std::string, ModSpec> content = 
+                       std::map<std::string, ModSpec> 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));
@@ -148,8 +144,8 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
                        std::vector<ModSpec> 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);
@@ -173,10 +169,10 @@ ModConfiguration::ModConfiguration(std::string worldpath)
        worldmt_settings.readConfigFile(worldmt.c_str());
        std::vector<std::string> names = worldmt_settings.getNames();
        std::set<std::string> include_mod_names;
-       for(std::vector<std::string>::iterator it = names.begin(); 
+       for(std::vector<std::string>::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.
@@ -244,13 +240,13 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
                // Add all the mods that come from modpacks
                // Second iteration:
                // Add all the mods that didn't come from modpacks
-               
+
                std::set<std::string> seen_this_iteration;
 
                for(std::vector<ModSpec>::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.
@@ -261,7 +257,7 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
                                // BAD CASE: name conflict in different levels.
                                u32 oldindex = existing_mods[mod.name];
                                const ModSpec &oldmod = m_unsatisfied_mods[oldindex];
-                               actionstream<<"WARNING: Mod name conflict detected: \""
+                               warningstream<<"Mod name conflict detected: \""
                                        <<mod.name<<"\""<<std::endl
                                        <<"Will not load: "<<oldmod.path<<std::endl
                                        <<"Overridden by: "<<mod.path<<std::endl;
@@ -275,7 +271,7 @@ void ModConfiguration::addMods(std::vector<ModSpec> new_mods)
                                // VERY BAD CASE: name conflict in the same level.
                                u32 oldindex = existing_mods[mod.name];
                                const ModSpec &oldmod = m_unsatisfied_mods[oldindex];
-                               errorstream<<"WARNING: Mod name conflict detected: \""
+                               warningstream<<"Mod name conflict detected: \""
                                        <<mod.name<<"\""<<std::endl
                                        <<"Will not load: "<<oldmod.path<<std::endl
                                        <<"Will not load: "<<mod.path<<std::endl;
@@ -335,7 +331,7 @@ void ModConfiguration::resolveDependencies()
                        else{
                                ++it;
                        }
-               }       
+               }
        }
 
        // Step 4: write back list of unsatisfied mods
@@ -345,25 +341,18 @@ void ModConfiguration::resolveDependencies()
 #if USE_CURL
 Json::Value getModstoreUrl(std::string url)
 {
-       struct curl_slist *chunk = NULL;
+       std::vector<std::string> extra_headers;
 
        bool special_http_header = true;
 
-       try{
+       try {
                special_http_header = g_settings->getBool("modstore_disable_special_http_header");
-       }
-       catch(SettingNotFoundException &e) {
-       }
+       } catch (SettingNotFoundException) {}
 
-       if (special_http_header)
-               chunk = curl_slist_append(chunk, "Accept: application/vnd.minetest.mmdb-v1+json");
-
-       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