--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. -------------------------------------------------------------------------------- function get_mods(path,retval,modpack) local mods = core.get_dir_list(path, true) for _, name in ipairs(mods) do if name:sub(1, 1) ~= "." then local prefix = path .. DIR_DELIM .. name .. DIR_DELIM local toadd = {} retval[#retval + 1] = toadd local mod_conf = Settings(prefix .. "mod.conf"):to_table() if mod_conf.name then name = mod_conf.name end toadd.name = name toadd.path = prefix if modpack ~= nil and modpack ~= "" then toadd.modpack = modpack else local modpackfile = io.open(prefix .. "modpack.txt") if modpackfile then modpackfile:close() toadd.is_modpack = true get_mods(prefix, retval, name) end end end end end --modmanager implementation modmgr = {} -------------------------------------------------------------------------------- function modmgr.extract(modfile) if modfile.type == "zip" then local tempfolder = os.tempfolder() if tempfolder ~= nil and tempfolder ~= "" then core.create_dir(tempfolder) if core.extract_zip(modfile.name,tempfolder) then return tempfolder end end end return nil 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 testfile = io.open(temppath .. DIR_DELIM .. "modpack.txt","r") if testfile ~= nil then testfile:close() return { type="modpack", path=temppath } end local subdirs = core.get_dir_list(temppath, true) --only single mod or modpack allowed if #subdirs ~= 1 then return { type = "invalid", path = "" } end testfile = 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 testfile = 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 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 if pos1 ~= nil and pos2 ~= nil then local item = line:sub(pos1+1,pos2-1) if item ~= nil and item ~= "" then local pos3 = item:find(":") if pos3 ~= nil then local retval = item:sub(1,pos3-1) if retval ~= nil and retval ~= "" then return retval end 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 if pos1 ~= nil and pos2 ~= nil then local filename = line:sub(pos1+1,pos2-1) 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() while line~= nil do local modname = nil 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 modname = modmgr.parse_register_line(line) end if line:find("dofile") then modname = modmgr.parse_dofile_line(modpath,line) end if modname ~= nil then testfile:close() return modname end line = testfile:read() end testfile:close() end return nil end -------------------------------------------------------------------------------- function modmgr.render_modlist(render_list) local retval = "" if render_list == nil then if modmgr.global_mods == nil then modmgr.refresh_globals() end render_list = modmgr.global_mods end local list = render_list:get_list() local last_modpack = nil local retval = {} local in_game_mods = false for i, v in ipairs(list) do if v.typ == "game_mod" and not in_game_mods then in_game_mods = true retval[#retval + 1] = mt_color_blue retval[#retval + 1] = "0" retval[#retval + 1] = fgettext("Subgame Mods") end local color = "" if v.is_modpack then local rawlist = render_list:get_raw_list() color = mt_color_dark_green for j = 1, #rawlist, 1 do if rawlist[j].modpack == list[i].name and rawlist[j].enabled ~= true then -- Modpack not entirely enabled so showing as grey color = mt_color_grey break end end elseif v.typ == "game_mod" then color = mt_color_blue elseif v.enabled then color = mt_color_green end retval[#retval + 1] = color if v.modpack ~= nil or v.typ == "game_mod" then retval[#retval + 1] = "1" else retval[#retval + 1] = "0" end retval[#retval + 1] = core.formspec_escape(v.name) end return table.concat(retval, ",") end -------------------------------------------------------------------------------- function modmgr.get_dependencies(modfolder) local toadd_hard = "" local toadd_soft = "" if modfolder ~= nil then local filename = modfolder .. DIR_DELIM .. "depends.txt" local hard_dependencies = {} local soft_dependencies = {} local dependencyfile = io.open(filename,"r") if dependencyfile then local dependency = dependencyfile:read("*l") while dependency do dependency = dependency:gsub("\r", "") if string.sub(dependency, -1, -1) == "?" then table.insert(soft_dependencies, stringpackage net.minetest.minetest; import android.app.NativeActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.WindowManager; public class MtNativeActivity extends NativeActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); m_MessagReturnCode = -1; m_MessageReturnValue = ""; } @Override public void onDestroy() { super.onDestroy(); } public void copyAssets() { Intent intent = new Intent(this, MinetestAssetCopy.class); startActivity(intent); } public void showDialog(String acceptButton, String hint, String current, int editType) { Intent intent = new Intent(this, MinetestTextEntry.class); Bundle params = new Bundle(); params.putString("acceptButton", acceptButton); params.putString("hint", hint); params.putString("current", current); params.putInt("editType", editType); intent.putExtras(params); startActivityForResult(intent, 101); m_MessageReturnValue = ""; m_MessagReturnCode = -1; } public static native void putMessageBoxResult(String text); /* ugly code to workaround putMessageBoxResult not beeing found */ public int getDialogState() { return m_MessagReturnCode; } public String getDialogValue() { m_MessagReturnCode = -1; return m_MessageReturnValue; } public float getDensity() { return getResources().getDisplayMetrics().density; } public int getDisplayWidth() { return getResources().getDisplayMetrics