2013-06-23 18:30:21 +02:00
|
|
|
--Minetest
|
|
|
|
--Copyright (C) 2013 sapier
|
|
|
|
--
|
|
|
|
--This program is free software; you can redistribute it and/or modify
|
|
|
|
--it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
--the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
--(at your option) any later version.
|
|
|
|
--
|
|
|
|
--This program is distributed in the hope that it will be useful,
|
|
|
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
--GNU Lesser General Public License for more details.
|
|
|
|
--
|
|
|
|
--You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2013-07-15 22:56:53 +02:00
|
|
|
function get_mods(path,retval,modpack)
|
2015-05-04 20:59:13 +02:00
|
|
|
local mods = core.get_dir_list(path, true)
|
2014-12-07 11:14:52 +01:00
|
|
|
|
2015-12-07 04:49:01 +01:00
|
|
|
for _, name in ipairs(mods) do
|
|
|
|
if name:sub(1, 1) ~= "." then
|
|
|
|
local prefix = path .. DIR_DELIM .. name .. DIR_DELIM
|
2014-12-07 11:14:52 +01:00
|
|
|
local toadd = {}
|
2015-12-07 04:49:01 +01:00
|
|
|
table.insert(retval, toadd)
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2015-12-07 04:49:01 +01:00
|
|
|
local mod_conf = Settings(prefix .. "mod.conf"):to_table()
|
|
|
|
if mod_conf.name then
|
|
|
|
name = mod_conf.name
|
2014-12-07 11:14:52 +01:00
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2015-12-07 04:49:01 +01:00
|
|
|
toadd.name = name
|
|
|
|
toadd.path = prefix
|
|
|
|
|
|
|
|
if modpack ~= nil and modpack ~= "" then
|
|
|
|
toadd.modpack = modpack
|
2014-12-07 11:14:52 +01:00
|
|
|
else
|
2015-12-07 04:49:01 +01:00
|
|
|
local modpackfile = io.open(prefix .. "modpack.txt")
|
|
|
|
if modpackfile then
|
|
|
|
modpackfile:close()
|
|
|
|
toadd.is_modpack = true
|
|
|
|
get_mods(prefix, retval, name)
|
|
|
|
end
|
2014-12-07 11:14:52 +01:00
|
|
|
end
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--modmanager implementation
|
|
|
|
modmgr = {}
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.extract(modfile)
|
|
|
|
if modfile.type == "zip" then
|
|
|
|
local tempfolder = os.tempfolder()
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if tempfolder ~= nil and
|
2013-11-26 18:15:31 +01:00
|
|
|
tempfolder ~= "" then
|
2014-04-18 15:39:15 +02:00
|
|
|
core.create_dir(tempfolder)
|
|
|
|
if core.extract_zip(modfile.name,tempfolder) then
|
2013-12-11 23:07:38 +01:00
|
|
|
return tempfolder
|
|
|
|
end
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
2013-12-11 23:07:38 +01:00
|
|
|
return nil
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
function modmgr.getbasefolder(temppath)
|
|
|
|
|
|
|
|
if temppath == nil then
|
|
|
|
return {
|
|
|
|
type = "invalid",
|
|
|
|
path = ""
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local testfile = io.open(temppath .. DIR_DELIM .. "init.lua","r")
|
|
|
|
if testfile ~= nil then
|
|
|
|
testfile:close()
|
|
|
|
return {
|
|
|
|
type="mod",
|
|
|
|
path=temppath
|
|
|
|
}
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
testfile = io.open(temppath .. DIR_DELIM .. "modpack.txt","r")
|
|
|
|
if testfile ~= nil then
|
|
|
|
testfile:close()
|
|
|
|
return {
|
|
|
|
type="modpack",
|
|
|
|
path=temppath
|
|
|
|
}
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2015-05-04 20:59:13 +02:00
|
|
|
local subdirs = core.get_dir_list(temppath, true)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
--only single mod or modpack allowed
|
|
|
|
if #subdirs ~= 1 then
|
|
|
|
return {
|
|
|
|
type = "invalid",
|
|
|
|
path = ""
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-11-26 18:15:31 +01:00
|
|
|
testfile =
|
2013-06-23 18:30:21 +02:00
|
|
|
io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."init.lua","r")
|
|
|
|
if testfile ~= nil then
|
|
|
|
testfile:close()
|
|
|
|
return {
|
|
|
|
type="mod",
|
|
|
|
path= temppath .. DIR_DELIM .. subdirs[1]
|
|
|
|
}
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
|
|
|
testfile =
|
2013-06-23 18:30:21 +02:00
|
|
|
io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."modpack.txt","r")
|
|
|
|
if testfile ~= nil then
|
|
|
|
testfile:close()
|
|
|
|
return {
|
|
|
|
type="modpack",
|
|
|
|
path=temppath .. DIR_DELIM .. subdirs[1]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
type = "invalid",
|
|
|
|
path = ""
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.isValidModname(modpath)
|
|
|
|
if modpath:find("-") ~= nil then
|
|
|
|
return false
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.parse_register_line(line)
|
|
|
|
local pos1 = line:find("\"")
|
|
|
|
local pos2 = nil
|
|
|
|
if pos1 ~= nil then
|
|
|
|
pos2 = line:find("\"",pos1+1)
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if pos1 ~= nil and pos2 ~= nil then
|
|
|
|
local item = line:sub(pos1+1,pos2-1)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if item ~= nil and
|
|
|
|
item ~= "" then
|
|
|
|
local pos3 = item:find(":")
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if pos3 ~= nil then
|
2013-07-17 21:04:17 +02:00
|
|
|
local retval = item:sub(1,pos3-1)
|
|
|
|
if retval ~= nil and
|
|
|
|
retval ~= "" then
|
|
|
|
return retval
|
2013-11-26 18:15:31 +01:00
|
|
|
end
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.parse_dofile_line(modpath,line)
|
|
|
|
local pos1 = line:find("\"")
|
|
|
|
local pos2 = nil
|
|
|
|
if pos1 ~= nil then
|
|
|
|
pos2 = line:find("\"",pos1+1)
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if pos1 ~= nil and pos2 ~= nil then
|
|
|
|
local filename = line:sub(pos1+1,pos2-1)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if filename ~= nil and
|
|
|
|
filename ~= "" and
|
|
|
|
filename:find(".lua") then
|
|
|
|
return modmgr.identify_modname(modpath,filename)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.identify_modname(modpath,filename)
|
|
|
|
local testfile = io.open(modpath .. DIR_DELIM .. filename,"r")
|
|
|
|
if testfile ~= nil then
|
|
|
|
local line = testfile:read()
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
while line~= nil do
|
|
|
|
local modname = nil
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
if line:find("minetest.register_tool") then
|
|
|
|
modname = modmgr.parse_register_line(line)
|
|
|
|
end
|
|
|
|
|
|
|
|
if line:find("minetest.register_craftitem") then
|
|
|
|
modname = modmgr.parse_register_line(line)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if line:find("minetest.register_node") then
|
2013-06-23 18:30:21 +02:00
|
|
|
modname = modmgr.parse_register_line(line)
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if line:find("dofile") then
|
|
|
|
modname = modmgr.parse_dofile_line(modpath,line)
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if modname ~= nil then
|
|
|
|
testfile:close()
|
|
|
|
return modname
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
line = testfile:read()
|
|
|
|
end
|
|
|
|
testfile:close()
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
2013-07-15 22:56:53 +02:00
|
|
|
function modmgr.render_modlist(render_list)
|
2013-06-23 18:30:21 +02:00
|
|
|
local retval = ""
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if render_list == nil then
|
|
|
|
if modmgr.global_mods == nil then
|
|
|
|
modmgr.refresh_globals()
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
2013-07-15 22:56:53 +02:00
|
|
|
render_list = modmgr.global_mods
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
local list = render_list:get_list()
|
2013-07-15 22:56:53 +02:00
|
|
|
local last_modpack = nil
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
for i,v in ipairs(list) do
|
|
|
|
if retval ~= "" then
|
|
|
|
retval = retval ..","
|
|
|
|
end
|
2013-08-19 11:26:51 +02:00
|
|
|
|
|
|
|
local color = ""
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if v.is_modpack then
|
2014-04-18 15:39:15 +02:00
|
|
|
local rawlist = render_list:get_raw_list()
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
local all_enabled = true
|
|
|
|
for j=1,#rawlist,1 do
|
|
|
|
if rawlist[j].modpack == list[i].name and
|
|
|
|
rawlist[j].enabled ~= true then
|
|
|
|
all_enabled = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if all_enabled == false then
|
2013-08-19 11:26:51 +02:00
|
|
|
color = mt_color_grey
|
2013-07-15 22:56:53 +02:00
|
|
|
else
|
2013-08-19 11:26:51 +02:00
|
|
|
color = mt_color_dark_green
|
2013-07-15 22:56:53 +02:00
|
|
|
end
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if v.typ == "game_mod" then
|
2013-08-19 11:26:51 +02:00
|
|
|
color = mt_color_blue
|
2013-07-15 22:56:53 +02:00
|
|
|
else
|
|
|
|
if v.enabled then
|
2013-08-19 11:26:51 +02:00
|
|
|
color = mt_color_green
|
2013-07-15 22:56:53 +02:00
|
|
|
end
|
|
|
|
end
|
2013-08-19 11:26:51 +02:00
|
|
|
|
|
|
|
retval = retval .. color
|
2013-07-15 22:56:53 +02:00
|
|
|
if v.modpack ~= nil then
|
|
|
|
retval = retval .. " "
|
|
|
|
end
|
|
|
|
retval = retval .. v.name
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
return retval
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2013-07-15 22:56:53 +02:00
|
|
|
function modmgr.get_dependencies(modfolder)
|
2013-06-23 18:30:21 +02:00
|
|
|
local toadd = ""
|
2013-07-15 22:56:53 +02:00
|
|
|
if modfolder ~= nil then
|
|
|
|
local filename = modfolder ..
|
|
|
|
DIR_DELIM .. "depends.txt"
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
local dependencyfile = io.open(filename,"r")
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if dependencyfile then
|
|
|
|
local dependency = dependencyfile:read("*l")
|
|
|
|
while dependency do
|
2013-11-26 18:15:31 +01:00
|
|
|
if toadd ~= "" then
|
2013-07-15 22:56:53 +02:00
|
|
|
toadd = toadd .. ","
|
|
|
|
end
|
|
|
|
toadd = toadd .. dependency
|
|
|
|
dependency = dependencyfile:read()
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
2013-07-15 22:56:53 +02:00
|
|
|
dependencyfile:close()
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return toadd
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.get_worldconfig(worldpath)
|
|
|
|
local filename = worldpath ..
|
|
|
|
DIR_DELIM .. "world.mt"
|
|
|
|
|
2013-09-10 21:09:21 +02:00
|
|
|
local worldfile = Settings(filename)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
local worldconfig = {}
|
|
|
|
worldconfig.global_mods = {}
|
|
|
|
worldconfig.game_mods = {}
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-09-10 21:09:21 +02:00
|
|
|
for key,value in pairs(worldfile:to_table()) do
|
|
|
|
if key == "gameid" then
|
|
|
|
worldconfig.id = value
|
2015-03-15 14:52:10 +01:00
|
|
|
elseif key:sub(0, 9) == "load_mod_" then
|
2014-04-18 15:39:15 +02:00
|
|
|
worldconfig.global_mods[key] = core.is_yes(value)
|
2015-03-15 14:52:10 +01:00
|
|
|
else
|
|
|
|
worldconfig[key] = value
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
--read gamemods
|
2013-08-19 13:55:04 +02:00
|
|
|
local gamespec = gamemgr.find_by_gameid(worldconfig.id)
|
|
|
|
gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
|
2013-06-23 18:30:21 +02:00
|
|
|
|
|
|
|
return worldconfig
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.installmod(modfilename,basename)
|
2013-07-16 20:56:18 +02:00
|
|
|
local modfile = modmgr.identify_filetype(modfilename)
|
2013-06-23 18:30:21 +02:00
|
|
|
local modpath = modmgr.extract(modfile)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if modpath == nil then
|
2013-08-14 19:22:23 +02:00
|
|
|
gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
|
2013-12-11 23:07:38 +01:00
|
|
|
fgettext("\nInstall Mod: unsupported filetype \"$1\" or broken archive", modfile.type)
|
2013-06-23 18:30:21 +02:00
|
|
|
return
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
local basefolder = modmgr.getbasefolder(modpath)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if basefolder.type == "modpack" then
|
|
|
|
local clean_path = nil
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if basename ~= nil then
|
|
|
|
clean_path = "mp_" .. basename
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if clean_path == nil then
|
|
|
|
clean_path = get_last_folder(cleanup_path(basefolder.path))
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if clean_path ~= nil then
|
2014-04-18 15:39:15 +02:00
|
|
|
local targetpath = core.get_modpath() .. DIR_DELIM .. clean_path
|
|
|
|
if not core.copy_dir(basefolder.path,targetpath) then
|
2013-08-14 19:22:23 +02:00
|
|
|
gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
|
2013-07-12 21:56:09 +02:00
|
|
|
end
|
2013-06-23 18:30:21 +02:00
|
|
|
else
|
2013-08-14 19:22:23 +02:00
|
|
|
gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if basefolder.type == "mod" then
|
|
|
|
local targetfolder = basename
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if targetfolder == nil then
|
|
|
|
targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
--if heuristic failed try to use current foldername
|
|
|
|
if targetfolder == nil then
|
|
|
|
targetfolder = get_last_folder(basefolder.path)
|
2013-11-26 18:15:31 +01:00
|
|
|
end
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
|
2014-04-18 15:39:15 +02:00
|
|
|
local targetpath = core.get_modpath() .. DIR_DELIM .. targetfolder
|
|
|
|
core.copy_dir(basefolder.path,targetpath)
|
2013-06-23 18:30:21 +02:00
|
|
|
else
|
2013-08-14 19:22:23 +02:00
|
|
|
gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
core.delete_dir(modpath)
|
2013-07-15 22:56:53 +02:00
|
|
|
|
|
|
|
modmgr.refresh_globals()
|
|
|
|
|
2013-06-23 18:30:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2013-07-15 22:56:53 +02:00
|
|
|
function modmgr.preparemodlist(data)
|
|
|
|
local retval = {}
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
local global_mods = {}
|
|
|
|
local game_mods = {}
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
--read global mods
|
2014-04-18 15:39:15 +02:00
|
|
|
local modpath = core.get_modpath()
|
2013-07-15 22:56:53 +02:00
|
|
|
|
|
|
|
if modpath ~= nil and
|
|
|
|
modpath ~= "" then
|
|
|
|
get_mods(modpath,global_mods)
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
for i=1,#global_mods,1 do
|
|
|
|
global_mods[i].typ = "global_mod"
|
|
|
|
table.insert(retval,global_mods[i])
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
--read game mods
|
2013-08-19 13:55:04 +02:00
|
|
|
local gamespec = gamemgr.find_by_gameid(data.gameid)
|
|
|
|
gamemgr.get_game_mods(gamespec, game_mods)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
for i=1,#game_mods,1 do
|
|
|
|
game_mods[i].typ = "game_mod"
|
|
|
|
table.insert(retval,game_mods[i])
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if data.worldpath == nil then
|
|
|
|
return retval
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
--read world mod configuration
|
|
|
|
local filename = data.worldpath ..
|
|
|
|
DIR_DELIM .. "world.mt"
|
|
|
|
|
2013-09-10 21:09:21 +02:00
|
|
|
local worldfile = Settings(filename)
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-09-10 21:09:21 +02:00
|
|
|
for key,value in pairs(worldfile:to_table()) do
|
|
|
|
if key:sub(1, 9) == "load_mod_" then
|
|
|
|
key = key:sub(10)
|
|
|
|
local element = nil
|
|
|
|
for i=1,#retval,1 do
|
2014-04-18 15:39:15 +02:00
|
|
|
if retval[i].name == key and
|
|
|
|
not retval[i].is_modpack then
|
2013-09-10 21:09:21 +02:00
|
|
|
element = retval[i]
|
|
|
|
break
|
2013-07-15 22:56:53 +02:00
|
|
|
end
|
|
|
|
end
|
2013-09-10 21:09:21 +02:00
|
|
|
if element ~= nil then
|
2014-04-18 15:39:15 +02:00
|
|
|
element.enabled = core.is_yes(value)
|
2013-09-10 21:09:21 +02:00
|
|
|
else
|
2014-04-18 15:39:15 +02:00
|
|
|
core.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
|
2013-09-10 21:09:21 +02:00
|
|
|
end
|
2013-07-15 22:56:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return retval
|
|
|
|
end
|
2013-06-23 18:30:21 +02:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.comparemod(elem1,elem2)
|
|
|
|
if elem1 == nil or elem2 == nil then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if elem1.name ~= elem2.name then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if elem1.is_modpack ~= elem2.is_modpack then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if elem1.typ ~= elem2.typ then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
if elem1.modpack ~= elem2.modpack then
|
|
|
|
return false
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
if elem1.path ~= elem2.path then
|
|
|
|
return false
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.mod_exists(basename)
|
|
|
|
|
|
|
|
if modmgr.global_mods == nil then
|
|
|
|
modmgr.refresh_globals()
|
|
|
|
end
|
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
if modmgr.global_mods:raw_index_by_uid(basename) > 0 then
|
2013-07-15 22:56:53 +02:00
|
|
|
return true
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-15 22:56:53 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.get_global_mod(idx)
|
|
|
|
|
|
|
|
if modmgr.global_mods == nil then
|
|
|
|
return nil
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
if idx == nil or idx < 1 or
|
|
|
|
idx > modmgr.global_mods:size() then
|
2013-07-15 22:56:53 +02:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2014-04-18 15:39:15 +02:00
|
|
|
return modmgr.global_mods:get_list()[idx]
|
2013-07-15 22:56:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.refresh_globals()
|
|
|
|
modmgr.global_mods = filterlist.create(
|
|
|
|
modmgr.preparemodlist, --refresh
|
|
|
|
modmgr.comparemod, --compare
|
|
|
|
function(element,uid) --uid match
|
|
|
|
if element.name == uid then
|
|
|
|
return true
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
end,
|
2013-07-15 22:56:53 +02:00
|
|
|
nil, --filter
|
|
|
|
{}
|
|
|
|
)
|
2014-04-18 15:39:15 +02:00
|
|
|
modmgr.global_mods:add_sort_mechanism("alphabetic", sort_mod_list)
|
|
|
|
modmgr.global_mods:set_sortmode("alphabetic")
|
2013-07-15 22:56:53 +02:00
|
|
|
end
|
2013-07-16 20:56:18 +02:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
function modmgr.identify_filetype(name)
|
|
|
|
|
|
|
|
if name:sub(-3):lower() == "zip" then
|
|
|
|
return {
|
|
|
|
name = name,
|
|
|
|
type = "zip"
|
|
|
|
}
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-16 20:56:18 +02:00
|
|
|
if name:sub(-6):lower() == "tar.gz" or
|
|
|
|
name:sub(-3):lower() == "tgz"then
|
|
|
|
return {
|
|
|
|
name = name,
|
|
|
|
type = "tgz"
|
|
|
|
}
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-16 20:56:18 +02:00
|
|
|
if name:sub(-6):lower() == "tar.bz2" then
|
|
|
|
return {
|
|
|
|
name = name,
|
|
|
|
type = "tbz"
|
|
|
|
}
|
|
|
|
end
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2013-07-16 20:56:18 +02:00
|
|
|
if name:sub(-2):lower() == "7z" then
|
|
|
|
return {
|
|
|
|
name = name,
|
|
|
|
type = "7z"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
name = name,
|
|
|
|
type = "ukn"
|
|
|
|
}
|
|
|
|
end
|