2 --Copyright (C) 2013 sapier
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 --GNU Lesser General Public License for more details.
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 --------------------------------------------------------------------------------
19 function get_mods(path,retval,modpack)
21 local mods = engine.get_dirlist(path,true)
24 local modpackfile = nil
27 toadd.path = path .. DIR_DELIM .. mods[i] .. DIR_DELIM
30 toadd.modpack = modpack
32 local filename = path .. DIR_DELIM .. mods[i] .. DIR_DELIM .. "modpack.txt"
34 modpackfile,error = io.open(filename,"r")
37 if modpackfile ~= nil then
39 toadd.is_modpack = true
40 table.insert(retval,toadd)
41 get_mods(path .. DIR_DELIM .. mods[i],retval,mods[i])
43 table.insert(retval,toadd)
48 --modmanager implementation
51 --------------------------------------------------------------------------------
52 function modmgr.extract(modfile)
53 if modfile.type == "zip" then
54 local tempfolder = os.tempfolder()
56 if tempfolder ~= nil and
58 engine.create_dir(tempfolder)
59 if engine.extract_zip(modfile.name,tempfolder) then
67 -------------------------------------------------------------------------------
68 function modmgr.getbasefolder(temppath)
70 if temppath == nil then
77 local testfile = io.open(temppath .. DIR_DELIM .. "init.lua","r")
78 if testfile ~= nil then
86 testfile = io.open(temppath .. DIR_DELIM .. "modpack.txt","r")
87 if testfile ~= nil then
95 local subdirs = engine.get_dirlist(temppath,true)
97 --only single mod or modpack allowed
106 io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."init.lua","r")
107 if testfile ~= nil then
111 path= temppath .. DIR_DELIM .. subdirs[1]
116 io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."modpack.txt","r")
117 if testfile ~= nil then
121 path=temppath .. DIR_DELIM .. subdirs[1]
131 --------------------------------------------------------------------------------
132 function modmgr.isValidModname(modpath)
133 if modpath:find("-") ~= nil then
140 --------------------------------------------------------------------------------
141 function modmgr.parse_register_line(line)
142 local pos1 = line:find("\"")
145 pos2 = line:find("\"",pos1+1)
148 if pos1 ~= nil and pos2 ~= nil then
149 local item = line:sub(pos1+1,pos2-1)
153 local pos3 = item:find(":")
156 local retval = item:sub(1,pos3-1)
167 --------------------------------------------------------------------------------
168 function modmgr.parse_dofile_line(modpath,line)
169 local pos1 = line:find("\"")
172 pos2 = line:find("\"",pos1+1)
175 if pos1 ~= nil and pos2 ~= nil then
176 local filename = line:sub(pos1+1,pos2-1)
178 if filename ~= nil and
180 filename:find(".lua") then
181 return modmgr.identify_modname(modpath,filename)
187 --------------------------------------------------------------------------------
188 function modmgr.identify_modname(modpath,filename)
189 local testfile = io.open(modpath .. DIR_DELIM .. filename,"r")
190 if testfile ~= nil then
191 local line = testfile:read()
196 if line:find("minetest.register_tool") then
197 modname = modmgr.parse_register_line(line)
200 if line:find("minetest.register_craftitem") then
201 modname = modmgr.parse_register_line(line)
205 if line:find("minetest.register_node") then
206 modname = modmgr.parse_register_line(line)
209 if line:find("dofile") then
210 modname = modmgr.parse_dofile_line(modpath,line)
213 if modname ~= nil then
218 line = testfile:read()
226 --------------------------------------------------------------------------------
227 function modmgr.tab()
229 if modmgr.global_mods == nil then
230 modmgr.refresh_globals()
233 if modmgr.selected_mod == nil then
234 modmgr.selected_mod = 1
238 "vertlabel[0,-0.25;".. fgettext("MODS") .. "]" ..
239 "label[0.8,-0.25;".. fgettext("Installed Mods:") .. "]" ..
240 "textlist[0.75,0.25;4.5,4;modlist;" ..
241 modmgr.render_modlist(modmgr.global_mods) ..
242 ";" .. modmgr.selected_mod .. "]"
245 "label[0.8,4.2;" .. fgettext("Add mod:") .. "]" ..
246 -- TODO Disabled due to upcoming release 0.4.8 and irrlicht messing up localization
247 -- "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
248 "button[2.45,4.85;3.05,0.5;btn_mod_mgr_download;".. fgettext("Online mod repository") .. "]"
250 local selected_mod = nil
252 if filterlist.size(modmgr.global_mods) >= modmgr.selected_mod then
253 selected_mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
256 if selected_mod ~= nil then
257 local modscreenshot = nil
259 --check for screenshot beeing available
260 local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
262 screenshotfile,error = io.open(screenshotfilename,"r")
264 screenshotfile:close()
265 modscreenshot = screenshotfilename
268 if modscreenshot == nil then
269 modscreenshot = modstore.basetexturedir .. "no_screenshot.png"
273 .. "image[5.5,0;3,2;" .. engine.formspec_escape(modscreenshot) .. "]"
274 .. "label[8.25,0.6;" .. selected_mod.name .. "]"
276 local descriptionlines = nil
278 local descriptionfilename = selected_mod.path .. "description.txt"
279 descriptionfile,error = io.open(descriptionfilename,"r")
281 descriptiontext = descriptionfile:read("*all")
283 descriptionlines = engine.splittext(descriptiontext,42)
284 descriptionfile:close()
286 descriptionlines = {}
287 table.insert(descriptionlines,fgettext("No mod description available"))
291 "label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
292 "textlist[5.5,2.2;6.2,2.4;description;"
294 for i=1,#descriptionlines,1 do
295 retval = retval .. engine.formspec_escape(descriptionlines[i]) .. ","
299 if selected_mod.is_modpack then
300 retval = retval .. ";0]" ..
301 "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
302 fgettext("Rename") .. "]"
303 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
304 .. fgettext("Uninstall selected modpack") .. "]"
308 retval = retval .. ",Depends:,"
310 toadd = modmgr.get_dependencies(selected_mod.path)
312 retval = retval .. toadd .. ";0]"
314 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
315 .. fgettext("Uninstall selected mod") .. "]"
321 --------------------------------------------------------------------------------
322 function modmgr.dialog_rename_modpack()
324 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
327 "label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
328 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
331 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
332 fgettext("Accept") .. "]" ..
333 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
334 fgettext("Cancel") .. "]"
339 --------------------------------------------------------------------------------
340 function modmgr.precheck()
342 if modmgr.world_config_selected_world == nil then
343 modmgr.world_config_selected_world = 1
346 if modmgr.world_config_selected_mod == nil then
347 modmgr.world_config_selected_mod = 1
350 if modmgr.hide_gamemods == nil then
351 modmgr.hide_gamemods = true
354 if modmgr.hide_modpackcontents == nil then
355 modmgr.hide_modpackcontents = true
359 --------------------------------------------------------------------------------
360 function modmgr.render_modlist(render_list)
363 if render_list == nil then
364 if modmgr.global_mods == nil then
365 modmgr.refresh_globals()
367 render_list = modmgr.global_mods
370 local list = filterlist.get_list(render_list)
371 local last_modpack = nil
373 for i,v in ipairs(list) do
375 retval = retval ..","
381 local rawlist = filterlist.get_raw_list(render_list)
383 local all_enabled = true
384 for j=1,#rawlist,1 do
385 if rawlist[j].modpack == list[i].name and
386 rawlist[j].enabled ~= true then
392 if all_enabled == false then
393 color = mt_color_grey
395 color = mt_color_dark_green
399 if v.typ == "game_mod" then
400 color = mt_color_blue
403 color = mt_color_green
407 retval = retval .. color
408 if v.modpack ~= nil then
409 retval = retval .. " "
411 retval = retval .. v.name
417 --------------------------------------------------------------------------------
418 function modmgr.dialog_configure_world()
421 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
422 local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
426 "label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
427 "label[1.75,-0.25;" .. worldspec.name .. "]"
429 if modmgr.hide_gamemods then
430 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
432 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
435 if modmgr.hide_modpackcontents then
436 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
438 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
445 "label[0,0.45;" .. fgettext("Mod:") .. "]" ..
446 "label[0.75,0.45;" .. mod.name .. "]" ..
447 "label[0,1;" .. fgettext("Depends:") .. "]" ..
448 "textlist[0,1.5;5,4.25;world_config_depends;" ..
449 modmgr.get_dependencies(mod.path) .. ";0]" ..
450 "button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
451 "button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
453 if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
454 if mod.is_modpack then
455 local rawlist = filterlist.get_raw_list(modmgr.modlist)
457 local all_enabled = true
458 for j=1,#rawlist,1 do
459 if rawlist[j].modpack == mod.name and
460 rawlist[j].enabled ~= true then
466 if all_enabled == false then
467 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
469 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
473 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
475 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
481 "button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
482 "textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
484 retval = retval .. modmgr.render_modlist(modmgr.modlist)
486 retval = retval .. ";" .. modmgr.world_config_selected_mod .."]"
491 --------------------------------------------------------------------------------
492 function modmgr.handle_buttons(tab,fields)
496 if tab == "mod_mgr" then
497 retval = modmgr.handle_modmgr_buttons(fields)
500 if tab == "dialog_rename_modpack" then
501 retval = modmgr.handle_rename_modpack_buttons(fields)
504 if tab == "dialog_delete_mod" then
505 retval = modmgr.handle_delete_mod_buttons(fields)
508 if tab == "dialog_configure_world" then
509 retval = modmgr.handle_configure_world_buttons(fields)
515 --------------------------------------------------------------------------------
516 function modmgr.get_dependencies(modfolder)
518 if modfolder ~= nil then
519 local filename = modfolder ..
520 DIR_DELIM .. "depends.txt"
522 local dependencyfile = io.open(filename,"r")
524 if dependencyfile then
525 local dependency = dependencyfile:read("*l")
530 toadd = toadd .. dependency
531 dependency = dependencyfile:read()
533 dependencyfile:close()
541 --------------------------------------------------------------------------------
542 function modmgr.get_worldconfig(worldpath)
543 local filename = worldpath ..
544 DIR_DELIM .. "world.mt"
546 local worldfile = Settings(filename)
548 local worldconfig = {}
549 worldconfig.global_mods = {}
550 worldconfig.game_mods = {}
552 for key,value in pairs(worldfile:to_table()) do
553 if key == "gameid" then
554 worldconfig.id = value
556 worldconfig.global_mods[key] = engine.is_yes(value)
561 local gamespec = gamemgr.find_by_gameid(worldconfig.id)
562 gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
566 --------------------------------------------------------------------------------
567 function modmgr.handle_modmgr_buttons(fields)
574 if fields["modlist"] ~= nil then
575 local event = explode_textlist_event(fields["modlist"])
576 modmgr.selected_mod = event.index
579 if fields["btn_mod_mgr_install_local"] ~= nil then
580 engine.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
583 if fields["btn_mod_mgr_download"] ~= nil then
584 modstore.update_modlist()
585 retval.current_tab = "dialog_modstore_unsorted"
586 retval.is_dialog = true
587 retval.show_buttons = false
591 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
592 retval.current_tab = "dialog_rename_modpack"
593 retval.is_dialog = true
594 retval.show_buttons = false
598 if fields["btn_mod_mgr_delete_mod"] ~= nil then
599 retval.current_tab = "dialog_delete_mod"
600 retval.is_dialog = true
601 retval.show_buttons = false
605 if fields["mod_mgt_open_dlg_accepted"] ~= nil and
606 fields["mod_mgt_open_dlg_accepted"] ~= "" then
607 modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
613 --------------------------------------------------------------------------------
614 function modmgr.installmod(modfilename,basename)
615 local modfile = modmgr.identify_filetype(modfilename)
616 local modpath = modmgr.extract(modfile)
618 if modpath == nil then
619 gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
620 fgettext("\nInstall Mod: unsupported filetype \"$1\" or broken archive", modfile.type)
625 local basefolder = modmgr.getbasefolder(modpath)
627 if basefolder.type == "modpack" then
628 local clean_path = nil
630 if basename ~= nil then
631 clean_path = "mp_" .. basename
634 if clean_path == nil then
635 clean_path = get_last_folder(cleanup_path(basefolder.path))
638 if clean_path ~= nil then
639 local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
640 if not engine.copy_dir(basefolder.path,targetpath) then
641 gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
644 gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
648 if basefolder.type == "mod" then
649 local targetfolder = basename
651 if targetfolder == nil then
652 targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
655 --if heuristic failed try to use current foldername
656 if targetfolder == nil then
657 targetfolder = get_last_folder(basefolder.path)
660 if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
661 local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder
662 engine.copy_dir(basefolder.path,targetpath)
664 gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
668 engine.delete_dir(modpath)
670 modmgr.refresh_globals()
674 --------------------------------------------------------------------------------
675 function modmgr.handle_rename_modpack_buttons(fields)
677 if fields["dlg_rename_modpack_confirm"] ~= nil then
678 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
679 local oldpath = engine.get_modpath() .. DIR_DELIM .. mod.name
680 local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
681 engine.copy_dir(oldpath,targetpath,false)
682 modmgr.refresh_globals()
683 modmgr.selected_mod = filterlist.get_current_index(modmgr.global_mods,
684 filterlist.raw_index_by_uid(modmgr.global_mods, fields["te_modpack_name"]))
690 current_tab = engine.setting_get("main_menu_tab")
693 --------------------------------------------------------------------------------
694 function modmgr.handle_configure_world_buttons(fields)
695 if fields["world_config_modlist"] ~= nil then
696 local event = explode_textlist_event(fields["world_config_modlist"])
697 modmgr.world_config_selected_mod = event.index
699 if event.typ == "DCL" then
700 modmgr.world_config_enable_mod(nil)
704 if fields["key_enter"] ~= nil then
705 modmgr.world_config_enable_mod(nil)
708 if fields["cb_mod_enable"] ~= nil then
709 local toset = engine.is_yes(fields["cb_mod_enable"])
710 modmgr.world_config_enable_mod(toset)
713 if fields["btn_mp_enable"] ~= nil or
714 fields["btn_mp_disable"] then
715 local toset = (fields["btn_mp_enable"] ~= nil)
716 modmgr.world_config_enable_mod(toset)
719 if fields["cb_hide_gamemods"] ~= nil then
720 local current = filterlist.get_filtercriteria(modmgr.modlist)
722 if current == nil then
726 if engine.is_yes(fields["cb_hide_gamemods"]) then
727 current.hide_game = true
728 modmgr.hide_gamemods = true
730 current.hide_game = false
731 modmgr.hide_gamemods = false
734 filterlist.set_filtercriteria(modmgr.modlist,current)
737 if fields["cb_hide_mpcontent"] ~= nil then
738 local current = filterlist.get_filtercriteria(modmgr.modlist)
740 if current == nil then
744 if engine.is_yes(fields["cb_hide_mpcontent"]) then
745 current.hide_modpackcontents = true
746 modmgr.hide_modpackcontents = true
748 current.hide_modpackcontents = false
749 modmgr.hide_modpackcontents = false
752 filterlist.set_filtercriteria(modmgr.modlist,current)
755 if fields["btn_config_world_save"] then
756 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
758 local filename = worldspec.path ..
759 DIR_DELIM .. "world.mt"
761 local worldfile = Settings(filename)
762 local mods = worldfile:to_table()
764 local rawlist = filterlist.get_raw_list(modmgr.modlist)
767 for i,mod in ipairs(rawlist) do
768 if not mod.is_modpack and
769 mod.typ ~= "game_mod" then
771 worldfile:set("load_mod_"..mod.name, "true")
773 worldfile:set("load_mod_"..mod.name, "false")
775 mods["load_mod_"..mod.name] = nil
779 -- Remove mods that are not present anymore
780 for key,value in pairs(mods) do
781 if key:sub(1,9) == "load_mod_" then
782 worldfile:remove(key)
786 if not worldfile:write() then
787 engine.log("error", "Failed to write world config file")
791 modmgr.worldconfig = nil
796 current_tab = engine.setting_get("main_menu_tab")
800 if fields["btn_config_world_cancel"] then
802 modmgr.worldconfig = nil
807 current_tab = engine.setting_get("main_menu_tab")
811 if fields["btn_all_mods"] then
812 local list = filterlist.get_raw_list(modmgr.modlist)
815 if list[i].typ ~= "game_mod" and
816 not list[i].is_modpack then
817 list[i].enabled = true
826 --------------------------------------------------------------------------------
827 function modmgr.world_config_enable_mod(toset)
828 local mod = filterlist.get_list(modmgr.modlist)
829 [engine.get_textlist_index("world_config_modlist")]
831 if mod.typ == "game_mod" then
832 -- game mods can't be enabled or disabled
833 elseif not mod.is_modpack then
835 mod.enabled = not mod.enabled
840 local list = filterlist.get_raw_list(modmgr.modlist)
842 if list[i].modpack == mod.name then
844 toset = not list[i].enabled
846 list[i].enabled = toset
851 --------------------------------------------------------------------------------
852 function modmgr.handle_delete_mod_buttons(fields)
853 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
855 if fields["dlg_delete_mod_confirm"] ~= nil then
857 if mod.path ~= nil and
859 mod.path ~= engine.get_modpath() then
860 if not engine.delete_dir(mod.path) then
861 gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", mod.path)
863 modmgr.refresh_globals()
865 gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", mod.path)
872 current_tab = engine.setting_get("main_menu_tab")
876 --------------------------------------------------------------------------------
877 function modmgr.dialog_delete_mod()
879 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
882 "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", mod.name) .. ";]"..
883 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
884 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
889 --------------------------------------------------------------------------------
890 function modmgr.preparemodlist(data)
893 local global_mods = {}
897 local modpath = engine.get_modpath()
899 if modpath ~= nil and
901 get_mods(modpath,global_mods)
904 for i=1,#global_mods,1 do
905 global_mods[i].typ = "global_mod"
906 table.insert(retval,global_mods[i])
910 local gamespec = gamemgr.find_by_gameid(data.gameid)
911 gamemgr.get_game_mods(gamespec, game_mods)
913 for i=1,#game_mods,1 do
914 game_mods[i].typ = "game_mod"
915 table.insert(retval,game_mods[i])
918 if data.worldpath == nil then
922 --read world mod configuration
923 local filename = data.worldpath ..
924 DIR_DELIM .. "world.mt"
926 local worldfile = Settings(filename)
928 for key,value in pairs(worldfile:to_table()) do
929 if key:sub(1, 9) == "load_mod_" then
933 if retval[i].name == key then
938 if element ~= nil then
939 element.enabled = engine.is_yes(value)
941 engine.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
949 --------------------------------------------------------------------------------
950 function modmgr.init_worldconfig()
952 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
954 if worldspec ~= nil then
956 modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path)
958 if modmgr.worldconfig.id == nil or
959 modmgr.worldconfig.id == "" then
960 modmgr.worldconfig = nil
964 modmgr.modlist = filterlist.create(
965 modmgr.preparemodlist, --refresh
966 modmgr.comparemod, --compare
967 function(element,uid) --uid match
968 if element.name == uid then
972 function(element,criteria)
973 if criteria.hide_game and
974 element.typ == "game_mod" then
978 if criteria.hide_modpackcontents and
979 element.modpack ~= nil then
984 { worldpath= worldspec.path,
985 gameid = worldspec.gameid }
988 filterlist.set_filtercriteria(modmgr.modlist, {
989 hide_game=modmgr.hide_gamemods,
990 hide_modpackcontents= modmgr.hide_modpackcontents
992 filterlist.add_sort_mechanism(modmgr.modlist, "alphabetic", sort_mod_list)
993 filterlist.set_sortmode(modmgr.modlist, "alphabetic")
1001 --------------------------------------------------------------------------------
1002 function modmgr.comparemod(elem1,elem2)
1003 if elem1 == nil or elem2 == nil then
1006 if elem1.name ~= elem2.name then
1009 if elem1.is_modpack ~= elem2.is_modpack then
1012 if elem1.typ ~= elem2.typ then
1015 if elem1.modpack ~= elem2.modpack then
1019 if elem1.path ~= elem2.path then
1026 --------------------------------------------------------------------------------
1027 function modmgr.gettab(name)
1030 if name == "mod_mgr" then
1031 retval = retval .. modmgr.tab()
1034 if name == "dialog_rename_modpack" then
1035 retval = retval .. modmgr.dialog_rename_modpack()
1038 if name == "dialog_delete_mod" then
1039 retval = retval .. modmgr.dialog_delete_mod()
1042 if name == "dialog_configure_world" then
1043 retval = retval .. modmgr.dialog_configure_world()
1049 --------------------------------------------------------------------------------
1050 function modmgr.mod_exists(basename)
1052 if modmgr.global_mods == nil then
1053 modmgr.refresh_globals()
1056 if filterlist.raw_index_by_uid(modmgr.global_mods,basename) > 0 then
1063 --------------------------------------------------------------------------------
1064 function modmgr.get_global_mod(idx)
1066 if modmgr.global_mods == nil then
1070 if idx < 1 or idx > filterlist.size(modmgr.global_mods) then
1074 return filterlist.get_list(modmgr.global_mods)[idx]
1077 --------------------------------------------------------------------------------
1078 function modmgr.refresh_globals()
1079 modmgr.global_mods = filterlist.create(
1080 modmgr.preparemodlist, --refresh
1081 modmgr.comparemod, --compare
1082 function(element,uid) --uid match
1083 if element.name == uid then
1090 filterlist.add_sort_mechanism(modmgr.global_mods, "alphabetic", sort_mod_list)
1091 filterlist.set_sortmode(modmgr.global_mods, "alphabetic")
1094 --------------------------------------------------------------------------------
1095 function modmgr.identify_filetype(name)
1097 if name:sub(-3):lower() == "zip" then
1104 if name:sub(-6):lower() == "tar.gz" or
1105 name:sub(-3):lower() == "tgz"then
1112 if name:sub(-6):lower() == "tar.bz2" then
1119 if name:sub(-2):lower() == "7z" then