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 engine.extract_zip(modfile.name,tempfolder)
65 -------------------------------------------------------------------------------
66 function modmgr.getbasefolder(temppath)
68 if temppath == nil then
75 local testfile = io.open(temppath .. DIR_DELIM .. "init.lua","r")
76 if testfile ~= nil then
84 testfile = io.open(temppath .. DIR_DELIM .. "modpack.txt","r")
85 if testfile ~= nil then
93 local subdirs = engine.get_dirlist(temppath,true)
95 --only single mod or modpack allowed
104 io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."init.lua","r")
105 if testfile ~= nil then
109 path= temppath .. DIR_DELIM .. subdirs[1]
114 io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."modpack.txt","r")
115 if testfile ~= nil then
119 path=temppath .. DIR_DELIM .. subdirs[1]
129 --------------------------------------------------------------------------------
130 function modmgr.isValidModname(modpath)
131 if modpath:find("-") ~= nil then
138 --------------------------------------------------------------------------------
139 function modmgr.parse_register_line(line)
140 local pos1 = line:find("\"")
143 pos2 = line:find("\"",pos1+1)
146 if pos1 ~= nil and pos2 ~= nil then
147 local item = line:sub(pos1+1,pos2-1)
151 local pos3 = item:find(":")
154 local retval = item:sub(1,pos3-1)
165 --------------------------------------------------------------------------------
166 function modmgr.parse_dofile_line(modpath,line)
167 local pos1 = line:find("\"")
170 pos2 = line:find("\"",pos1+1)
173 if pos1 ~= nil and pos2 ~= nil then
174 local filename = line:sub(pos1+1,pos2-1)
176 if filename ~= nil and
178 filename:find(".lua") then
179 return modmgr.identify_modname(modpath,filename)
185 --------------------------------------------------------------------------------
186 function modmgr.identify_modname(modpath,filename)
187 local testfile = io.open(modpath .. DIR_DELIM .. filename,"r")
188 if testfile ~= nil then
189 local line = testfile:read()
194 if line:find("minetest.register_tool") then
195 modname = modmgr.parse_register_line(line)
198 if line:find("minetest.register_craftitem") then
199 modname = modmgr.parse_register_line(line)
203 if line:find("minetest.register_node") then
204 modname = modmgr.parse_register_line(line)
207 if line:find("dofile") then
208 modname = modmgr.parse_dofile_line(modpath,line)
211 if modname ~= nil then
216 line = testfile:read()
224 --------------------------------------------------------------------------------
225 function modmgr.tab()
227 if modmgr.global_mods == nil then
228 modmgr.refresh_globals()
231 if modmgr.selected_mod == nil then
232 modmgr.selected_mod = 1
236 "vertlabel[0,-0.25;".. fgettext("MODS") .. "]" ..
237 "label[0.8,-0.25;".. fgettext("Installed Mods:") .. "]" ..
238 "textlist[0.75,0.25;4.5,4;modlist;" ..
239 modmgr.render_modlist(modmgr.global_mods) ..
240 ";" .. modmgr.selected_mod .. "]"
243 "label[0.8,4.2;" .. fgettext("Add mod:") .. "]" ..
244 -- TODO Disabled due to upcoming release 0.4.8 and irrlicht messing up localization
245 -- "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
246 "button[2.45,4.85;3.05,0.5;btn_mod_mgr_download;".. fgettext("Online mod repository") .. "]"
248 local selected_mod = nil
250 if filterlist.size(modmgr.global_mods) >= modmgr.selected_mod then
251 selected_mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
254 if selected_mod ~= nil then
255 local modscreenshot = nil
257 --check for screenshot beeing available
258 local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
260 screenshotfile,error = io.open(screenshotfilename,"r")
262 screenshotfile:close()
263 modscreenshot = screenshotfilename
266 if modscreenshot == nil then
267 modscreenshot = modstore.basetexturedir .. "no_screenshot.png"
271 .. "image[5.5,0;3,2;" .. engine.formspec_escape(modscreenshot) .. "]"
272 .. "label[8.25,0.6;" .. selected_mod.name .. "]"
274 local descriptionlines = nil
276 local descriptionfilename = selected_mod.path .. "description.txt"
277 descriptionfile,error = io.open(descriptionfilename,"r")
279 descriptiontext = descriptionfile:read("*all")
281 descriptionlines = engine.splittext(descriptiontext,42)
282 descriptionfile:close()
284 descriptionlines = {}
285 table.insert(descriptionlines,fgettext("No mod description available"))
289 "label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
290 "textlist[5.5,2.2;6.2,2.4;description;"
292 for i=1,#descriptionlines,1 do
293 retval = retval .. engine.formspec_escape(descriptionlines[i]) .. ","
297 if selected_mod.is_modpack then
298 retval = retval .. ";0]" ..
299 "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
300 fgettext("Rename") .. "]"
301 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
302 .. fgettext("Uninstall selected modpack") .. "]"
306 retval = retval .. ",Depends:,"
308 toadd = modmgr.get_dependencies(selected_mod.path)
310 retval = retval .. toadd .. ";0]"
312 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
313 .. fgettext("Uninstall selected mod") .. "]"
319 --------------------------------------------------------------------------------
320 function modmgr.dialog_rename_modpack()
322 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
325 "label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
326 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
329 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
330 fgettext("Accept") .. "]" ..
331 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
332 fgettext("Cancel") .. "]"
337 --------------------------------------------------------------------------------
338 function modmgr.precheck()
340 if modmgr.world_config_selected_world == nil then
341 modmgr.world_config_selected_world = 1
344 if modmgr.world_config_selected_mod == nil then
345 modmgr.world_config_selected_mod = 1
348 if modmgr.hide_gamemods == nil then
349 modmgr.hide_gamemods = true
352 if modmgr.hide_modpackcontents == nil then
353 modmgr.hide_modpackcontents = true
357 --------------------------------------------------------------------------------
358 function modmgr.render_modlist(render_list)
361 if render_list == nil then
362 if modmgr.global_mods == nil then
363 modmgr.refresh_globals()
365 render_list = modmgr.global_mods
368 local list = filterlist.get_list(render_list)
369 local last_modpack = nil
371 for i,v in ipairs(list) do
373 retval = retval ..","
379 local rawlist = filterlist.get_raw_list(render_list)
381 local all_enabled = true
382 for j=1,#rawlist,1 do
383 if rawlist[j].modpack == list[i].name and
384 rawlist[j].enabled ~= true then
390 if all_enabled == false then
391 color = mt_color_grey
393 color = mt_color_dark_green
397 if v.typ == "game_mod" then
398 color = mt_color_blue
401 color = mt_color_green
405 retval = retval .. color
406 if v.modpack ~= nil then
407 retval = retval .. " "
409 retval = retval .. v.name
415 --------------------------------------------------------------------------------
416 function modmgr.dialog_configure_world()
419 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
420 local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
424 "label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
425 "label[1.75,-0.25;" .. worldspec.name .. "]"
427 if modmgr.hide_gamemods then
428 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
430 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
433 if modmgr.hide_modpackcontents then
434 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
436 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
443 "label[0,0.45;" .. fgettext("Mod:") .. "]" ..
444 "label[0.75,0.45;" .. mod.name .. "]" ..
445 "label[0,1;" .. fgettext("Depends:") .. "]" ..
446 "textlist[0,1.5;5,4.25;world_config_depends;" ..
447 modmgr.get_dependencies(mod.path) .. ";0]" ..
448 "button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
449 "button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
451 if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
452 if mod.is_modpack then
453 local rawlist = filterlist.get_raw_list(modmgr.modlist)
455 local all_enabled = true
456 for j=1,#rawlist,1 do
457 if rawlist[j].modpack == mod.name and
458 rawlist[j].enabled ~= true then
464 if all_enabled == false then
465 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
467 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
471 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
473 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
479 "button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
480 "textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
482 retval = retval .. modmgr.render_modlist(modmgr.modlist)
484 retval = retval .. ";" .. modmgr.world_config_selected_mod .."]"
489 --------------------------------------------------------------------------------
490 function modmgr.handle_buttons(tab,fields)
494 if tab == "mod_mgr" then
495 retval = modmgr.handle_modmgr_buttons(fields)
498 if tab == "dialog_rename_modpack" then
499 retval = modmgr.handle_rename_modpack_buttons(fields)
502 if tab == "dialog_delete_mod" then
503 retval = modmgr.handle_delete_mod_buttons(fields)
506 if tab == "dialog_configure_world" then
507 retval = modmgr.handle_configure_world_buttons(fields)
513 --------------------------------------------------------------------------------
514 function modmgr.get_dependencies(modfolder)
516 if modfolder ~= nil then
517 local filename = modfolder ..
518 DIR_DELIM .. "depends.txt"
520 local dependencyfile = io.open(filename,"r")
522 if dependencyfile then
523 local dependency = dependencyfile:read("*l")
528 toadd = toadd .. dependency
529 dependency = dependencyfile:read()
531 dependencyfile:close()
539 --------------------------------------------------------------------------------
540 function modmgr.get_worldconfig(worldpath)
541 local filename = worldpath ..
542 DIR_DELIM .. "world.mt"
544 local worldfile = Settings(filename)
546 local worldconfig = {}
547 worldconfig.global_mods = {}
548 worldconfig.game_mods = {}
550 for key,value in pairs(worldfile:to_table()) do
551 if key == "gameid" then
552 worldconfig.id = value
554 worldconfig.global_mods[key] = engine.is_yes(value)
559 local gamespec = gamemgr.find_by_gameid(worldconfig.id)
560 gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
564 --------------------------------------------------------------------------------
565 function modmgr.handle_modmgr_buttons(fields)
572 if fields["modlist"] ~= nil then
573 local event = explode_textlist_event(fields["modlist"])
574 modmgr.selected_mod = event.index
577 if fields["btn_mod_mgr_install_local"] ~= nil then
578 engine.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
581 if fields["btn_mod_mgr_download"] ~= nil then
582 modstore.update_modlist()
583 retval.current_tab = "dialog_modstore_unsorted"
584 retval.is_dialog = true
585 retval.show_buttons = false
589 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
590 retval.current_tab = "dialog_rename_modpack"
591 retval.is_dialog = true
592 retval.show_buttons = false
596 if fields["btn_mod_mgr_delete_mod"] ~= nil then
597 retval.current_tab = "dialog_delete_mod"
598 retval.is_dialog = true
599 retval.show_buttons = false
603 if fields["mod_mgt_open_dlg_accepted"] ~= nil and
604 fields["mod_mgt_open_dlg_accepted"] ~= "" then
605 modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
611 --------------------------------------------------------------------------------
612 function modmgr.installmod(modfilename,basename)
613 local modfile = modmgr.identify_filetype(modfilename)
614 local modpath = modmgr.extract(modfile)
616 if modpath == nil then
617 gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
618 fgettext("\nInstall Mod: unsupported filetype \"$1\"", modfile.type)
623 local basefolder = modmgr.getbasefolder(modpath)
625 if basefolder.type == "modpack" then
626 local clean_path = nil
628 if basename ~= nil then
629 clean_path = "mp_" .. basename
632 if clean_path == nil then
633 clean_path = get_last_folder(cleanup_path(basefolder.path))
636 if clean_path ~= nil then
637 local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
638 if not engine.copy_dir(basefolder.path,targetpath) then
639 gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
642 gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
646 if basefolder.type == "mod" then
647 local targetfolder = basename
649 if targetfolder == nil then
650 targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
653 --if heuristic failed try to use current foldername
654 if targetfolder == nil then
655 targetfolder = get_last_folder(basefolder.path)
658 if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
659 local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder
660 engine.copy_dir(basefolder.path,targetpath)
662 gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
666 engine.delete_dir(modpath)
668 modmgr.refresh_globals()
672 --------------------------------------------------------------------------------
673 function modmgr.handle_rename_modpack_buttons(fields)
675 if fields["dlg_rename_modpack_confirm"] ~= nil then
676 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
677 local oldpath = engine.get_modpath() .. DIR_DELIM .. mod.name
678 local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
679 engine.copy_dir(oldpath,targetpath,false)
680 modmgr.refresh_globals()
681 modmgr.selected_mod = filterlist.get_current_index(modmgr.global_mods,
682 filterlist.raw_index_by_uid(modmgr.global_mods, fields["te_modpack_name"]))
688 current_tab = engine.setting_get("main_menu_tab")
691 --------------------------------------------------------------------------------
692 function modmgr.handle_configure_world_buttons(fields)
693 if fields["world_config_modlist"] ~= nil then
694 local event = explode_textlist_event(fields["world_config_modlist"])
695 modmgr.world_config_selected_mod = event.index
697 if event.typ == "DCL" then
698 modmgr.world_config_enable_mod(nil)
702 if fields["key_enter"] ~= nil then
703 modmgr.world_config_enable_mod(nil)
706 if fields["cb_mod_enable"] ~= nil then
707 local toset = engine.is_yes(fields["cb_mod_enable"])
708 modmgr.world_config_enable_mod(toset)
711 if fields["btn_mp_enable"] ~= nil or
712 fields["btn_mp_disable"] then
713 local toset = (fields["btn_mp_enable"] ~= nil)
714 modmgr.world_config_enable_mod(toset)
717 if fields["cb_hide_gamemods"] ~= nil then
718 local current = filterlist.get_filtercriteria(modmgr.modlist)
720 if current == nil then
724 if engine.is_yes(fields["cb_hide_gamemods"]) then
725 current.hide_game = true
726 modmgr.hide_gamemods = true
728 current.hide_game = false
729 modmgr.hide_gamemods = false
732 filterlist.set_filtercriteria(modmgr.modlist,current)
735 if fields["cb_hide_mpcontent"] ~= nil then
736 local current = filterlist.get_filtercriteria(modmgr.modlist)
738 if current == nil then
742 if engine.is_yes(fields["cb_hide_mpcontent"]) then
743 current.hide_modpackcontents = true
744 modmgr.hide_modpackcontents = true
746 current.hide_modpackcontents = false
747 modmgr.hide_modpackcontents = false
750 filterlist.set_filtercriteria(modmgr.modlist,current)
753 if fields["btn_config_world_save"] then
754 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
756 local filename = worldspec.path ..
757 DIR_DELIM .. "world.mt"
759 local worldfile = Settings(filename)
760 local mods = worldfile:to_table()
762 local rawlist = filterlist.get_raw_list(modmgr.modlist)
765 for i,mod in ipairs(rawlist) do
766 if not mod.is_modpack and
767 mod.typ ~= "game_mod" then
769 worldfile:set("load_mod_"..mod.name, "true")
771 worldfile:set("load_mod_"..mod.name, "false")
773 mods["load_mod_"..mod.name] = nil
777 -- Remove mods that are not present anymore
778 for key,value in pairs(mods) do
779 if key:sub(1,9) == "load_mod_" then
780 worldfile:remove(key)
784 if not worldfile:write() then
785 engine.log("error", "Failed to write world config file")
789 modmgr.worldconfig = nil
794 current_tab = engine.setting_get("main_menu_tab")
798 if fields["btn_config_world_cancel"] then
800 modmgr.worldconfig = nil
805 current_tab = engine.setting_get("main_menu_tab")
809 if fields["btn_all_mods"] then
810 local list = filterlist.get_raw_list(modmgr.modlist)
813 if list[i].typ ~= "game_mod" and
814 not list[i].is_modpack then
815 list[i].enabled = true
824 --------------------------------------------------------------------------------
825 function modmgr.world_config_enable_mod(toset)
826 local mod = filterlist.get_list(modmgr.modlist)
827 [engine.get_textlist_index("world_config_modlist")]
829 if mod.typ == "game_mod" then
830 -- game mods can't be enabled or disabled
831 elseif not mod.is_modpack then
833 mod.enabled = not mod.enabled
838 local list = filterlist.get_raw_list(modmgr.modlist)
840 if list[i].modpack == mod.name then
842 toset = not list[i].enabled
844 list[i].enabled = toset
849 --------------------------------------------------------------------------------
850 function modmgr.handle_delete_mod_buttons(fields)
851 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
853 if fields["dlg_delete_mod_confirm"] ~= nil then
855 if mod.path ~= nil and
857 mod.path ~= engine.get_modpath() then
858 if not engine.delete_dir(mod.path) then
859 gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", mod.path)
861 modmgr.refresh_globals()
863 gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", mod.path)
870 current_tab = engine.setting_get("main_menu_tab")
874 --------------------------------------------------------------------------------
875 function modmgr.dialog_delete_mod()
877 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
880 "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", mod.name) .. ";]"..
881 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
882 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
887 --------------------------------------------------------------------------------
888 function modmgr.preparemodlist(data)
891 local global_mods = {}
895 local modpath = engine.get_modpath()
897 if modpath ~= nil and
899 get_mods(modpath,global_mods)
902 for i=1,#global_mods,1 do
903 global_mods[i].typ = "global_mod"
904 table.insert(retval,global_mods[i])
908 local gamespec = gamemgr.find_by_gameid(data.gameid)
909 gamemgr.get_game_mods(gamespec, game_mods)
911 for i=1,#game_mods,1 do
912 game_mods[i].typ = "game_mod"
913 table.insert(retval,game_mods[i])
916 if data.worldpath == nil then
920 --read world mod configuration
921 local filename = data.worldpath ..
922 DIR_DELIM .. "world.mt"
924 local worldfile = Settings(filename)
926 for key,value in pairs(worldfile:to_table()) do
927 if key:sub(1, 9) == "load_mod_" then
931 if retval[i].name == key then
936 if element ~= nil then
937 element.enabled = engine.is_yes(value)
939 engine.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
947 --------------------------------------------------------------------------------
948 function modmgr.init_worldconfig()
950 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
952 if worldspec ~= nil then
954 modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path)
956 if modmgr.worldconfig.id == nil or
957 modmgr.worldconfig.id == "" then
958 modmgr.worldconfig = nil
962 modmgr.modlist = filterlist.create(
963 modmgr.preparemodlist, --refresh
964 modmgr.comparemod, --compare
965 function(element,uid) --uid match
966 if element.name == uid then
970 function(element,criteria)
971 if criteria.hide_game and
972 element.typ == "game_mod" then
976 if criteria.hide_modpackcontents and
977 element.modpack ~= nil then
982 { worldpath= worldspec.path,
983 gameid = worldspec.gameid }
986 filterlist.set_filtercriteria(modmgr.modlist, {
987 hide_game=modmgr.hide_gamemods,
988 hide_modpackcontents= modmgr.hide_modpackcontents
990 filterlist.add_sort_mechanism(modmgr.modlist, "alphabetic", sort_mod_list)
991 filterlist.set_sortmode(modmgr.modlist, "alphabetic")
999 --------------------------------------------------------------------------------
1000 function modmgr.comparemod(elem1,elem2)
1001 if elem1 == nil or elem2 == nil then
1004 if elem1.name ~= elem2.name then
1007 if elem1.is_modpack ~= elem2.is_modpack then
1010 if elem1.typ ~= elem2.typ then
1013 if elem1.modpack ~= elem2.modpack then
1017 if elem1.path ~= elem2.path then
1024 --------------------------------------------------------------------------------
1025 function modmgr.gettab(name)
1028 if name == "mod_mgr" then
1029 retval = retval .. modmgr.tab()
1032 if name == "dialog_rename_modpack" then
1033 retval = retval .. modmgr.dialog_rename_modpack()
1036 if name == "dialog_delete_mod" then
1037 retval = retval .. modmgr.dialog_delete_mod()
1040 if name == "dialog_configure_world" then
1041 retval = retval .. modmgr.dialog_configure_world()
1047 --------------------------------------------------------------------------------
1048 function modmgr.mod_exists(basename)
1050 if modmgr.global_mods == nil then
1051 modmgr.refresh_globals()
1054 if filterlist.raw_index_by_uid(modmgr.global_mods,basename) > 0 then
1061 --------------------------------------------------------------------------------
1062 function modmgr.get_global_mod(idx)
1064 if modmgr.global_mods == nil then
1068 if idx < 1 or idx > filterlist.size(modmgr.global_mods) then
1072 return filterlist.get_list(modmgr.global_mods)[idx]
1075 --------------------------------------------------------------------------------
1076 function modmgr.refresh_globals()
1077 modmgr.global_mods = filterlist.create(
1078 modmgr.preparemodlist, --refresh
1079 modmgr.comparemod, --compare
1080 function(element,uid) --uid match
1081 if element.name == uid then
1088 filterlist.add_sort_mechanism(modmgr.global_mods, "alphabetic", sort_mod_list)
1089 filterlist.set_sortmode(modmgr.global_mods, "alphabetic")
1092 --------------------------------------------------------------------------------
1093 function modmgr.identify_filetype(name)
1095 if name:sub(-3):lower() == "zip" then
1102 if name:sub(-6):lower() == "tar.gz" or
1103 name:sub(-3):lower() == "tgz"then
1110 if name:sub(-6):lower() == "tar.bz2" then
1117 if name:sub(-2):lower() == "7z" then