Deprecate modpack.txt and use modpack.conf instead (#7892)
authorrubenwardy <rw@rubenwardy.com>
Sun, 6 Jan 2019 09:23:35 +0000 (09:23 +0000)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sun, 6 Jan 2019 09:23:35 +0000 (10:23 +0100)
* Deprecate modpack.txt and use modpack.conf instead

builtin/mainmenu/dlg_contentstore.lua
builtin/mainmenu/pkgmgr.lua
doc/client_lua_api.txt
doc/lua_api.txt
src/content/content.cpp
src/content/mods.cpp

index bab2c73f3c41ea1ec965dfd6a1fdf81c7e941ff6..414c2685314bf00af59a6711d6ac9250a693649d 100644 (file)
@@ -76,10 +76,17 @@ local function start_install(calling_dialog, package)
                        if not path then
                                gamedata.errormessage = msg
                        else
+                               core.log("action", "Installed package to " .. path)
+
                                local conf_path
                                local name_is_title = false
                                if result.package.type == "mod" then
-                                       conf_path = path .. DIR_DELIM .. "mod.conf"
+                                       local actual_type = pkgmgr.get_folder_type(path)
+                                       if actual_type.type == "modpack" then
+                                               conf_path = path .. DIR_DELIM .. "modpack.conf"
+                                       else
+                                               conf_path = path .. DIR_DELIM .. "mod.conf"
+                                       end
                                elseif result.package.type == "game" then
                                        conf_path = path .. DIR_DELIM .. "game.conf"
                                        name_is_title = true
index ebd8ece6b7dee88aa8c96b4e212ee28a246c66ee..f6015ef7277fa49c4f63ea9c0bd80302ba0e74f2 100644 (file)
@@ -25,27 +25,46 @@ function get_mods(path,retval,modpack)
                        local toadd = {}
                        retval[#retval + 1] = toadd
 
-                       local mod_conf = Settings(prefix .. DIR_DELIM .. "mod.conf"):to_table()
-                       if mod_conf.name then
-                               name = mod_conf.name
+                       -- Get config file
+                       local mod_conf
+                       local modpack_conf = io.open(prefix .. DIR_DELIM .. "modpack.conf")
+                       if modpack_conf then
+                               toadd.is_modpack = true
+                               modpack_conf:close()
+
+                               mod_conf = Settings(prefix .. DIR_DELIM .. "modpack.conf"):to_table()
+                               if mod_conf.name then
+                                       name = mod_conf.name
+                               end
+                       else
+                               mod_conf = Settings(prefix .. DIR_DELIM .. "mod.conf"):to_table()
+                               if mod_conf.name then
+                                       name = mod_conf.name
+                               end
                        end
 
+                       -- Read from config
                        toadd.name = name
                        toadd.author = mod_conf.author
                        toadd.release = tonumber(mod_conf.release or "0")
                        toadd.path = prefix
                        toadd.type = "mod"
 
-                       if modpack ~= nil and modpack ~= "" then
+                       -- Check modpack.txt
+                       --  Note: modpack.conf is already checked above
+                       local modpackfile = io.open(prefix .. DIR_DELIM .. "modpack.txt")
+                       if modpackfile then
+                               modpackfile:close()
+                               toadd.is_modpack = true
+                       end
+
+                       -- Deal with modpack contents
+                       if modpack and modpack ~= "" then
                                toadd.modpack = modpack
-                       else
-                               local modpackfile = io.open(prefix .. DIR_DELIM .. "modpack.txt")
-                               if modpackfile then
-                                       modpackfile:close()
-                                       toadd.type = "modpack"
-                                       toadd.is_modpack = true
-                                       get_mods(prefix, retval, name)
-                               end
+                       elseif toadd.is_modpack then
+                               toadd.type = "modpack"
+                               toadd.is_modpack = true
+                               get_mods(prefix, retval, name)
                        end
                end
        end
@@ -114,6 +133,12 @@ function pkgmgr.get_folder_type(path)
                return { type = "mod", path = path }
        end
 
+       testfile = io.open(path .. DIR_DELIM .. "modpack.conf","r")
+       if testfile ~= nil then
+               testfile:close()
+               return { type = "modpack", path = path }
+       end
+
        testfile = io.open(path .. DIR_DELIM .. "modpack.txt","r")
        if testfile ~= nil then
                testfile:close()
@@ -422,7 +447,7 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
                else
                        local clean_path = nil
                        if basename ~= nil then
-                               clean_path = "mp_" .. basename
+                               clean_path = basename
                        end
                        if not clean_path then
                                clean_path = get_last_folder(cleanup_path(basefolder.path))
index 41560b98311ac01b6c96972a505cad4ac00908e3..f0e585355d89cd4a2f27d5408726ccb4a2a383c8 100644 (file)
@@ -68,8 +68,12 @@ Modpack support
 **NOTE: Not implemented yet.**
 
 Mods can be put in a subdirectory, if the parent directory, which otherwise
-should be a mod, contains a file named `modpack.txt`. This file shall be
-empty, except for lines starting with `#`, which are comments.
+should be a mod, contains a file named `modpack.conf`.
+The file is a key-value store of modpack details.
+
+* `name`: The modpack name.
+* `description`: Description of mod to be shown in the Mods tab of the main
+                 menu.
 
 Mod directory structure
 ------------------------
index 0b08282a0dfbbfbd8619fc93a49eb774139900a5..a8380e1cc867b8f6a0fd8cd28451f53e2ec5e6ee 100644 (file)
@@ -119,8 +119,14 @@ Modpacks
 --------
 
 Mods can be put in a subdirectory, if the parent directory, which otherwise
-should be a mod, contains a file named `modpack.txt`. This file shall be
-empty, except for lines starting with `#`, which are comments.
+should be a mod, contains a file named `modpack.conf`.
+The file is a key-value store of modpack details.
+
+* `name`: The modpack name.
+* `description`: Description of mod to be shown in the Mods tab of the main
+                 menu.
+
+Note: to support 0.4.x, please also create an empty modpack.txt file.
 
 Mod directory structure
 -----------------------
index d7a2c965238fe7cfbe37ed9aa793c5f556208bf1..66ef83d42bbfec76362f5512d7426bde565b39b3 100644 (file)
@@ -41,6 +41,12 @@ ContentType getContentType(const ContentSpec &spec)
                return ECT_MODPACK;
        }
 
+       std::ifstream modpack2_is((spec.path + DIR_DELIM + "modpack.conf").c_str());
+       if (modpack2_is.good()) {
+               modpack2_is.close();
+               return ECT_MODPACK;
+       }
+
        std::ifstream init_is((spec.path + DIR_DELIM + "init.lua").c_str());
        if (init_is.good()) {
                init_is.close();
@@ -73,7 +79,7 @@ void parseContentInfo(ContentSpec &spec)
                break;
        case ECT_MODPACK:
                spec.type = "modpack";
-               conf_path = spec.path + DIR_DELIM + "mod.conf";
+               conf_path = spec.path + DIR_DELIM + "modpack.conf";
                break;
        case ECT_GAME:
                spec.type = "game";
index a3e70676063ee9a215ee432bf72c327882431ca5..3cb168e1914e06bc1d2eb10cc5209c33bb059948 100644 (file)
@@ -66,12 +66,16 @@ void parseModContents(ModSpec &spec)
 
        // 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
+       std::ifstream modpack2_is((spec.path + DIR_DELIM + "modpack.conf").c_str());
+       if (modpack_is.good() || modpack2_is.good()) {
+               if (modpack_is.good())
+                       modpack_is.close();
+
+               if (modpack2_is.good())
+                       modpack2_is.close();
+
                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 {
                // Attempt to load dependencies from mod.conf