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 "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
245 "button[2.45,4.85;3.05,0.5;btn_mod_mgr_download;".. fgettext("Online mod repository") .. "]"
247 local selected_mod = nil
249 if filterlist.size(modmgr.global_mods) >= modmgr.selected_mod then
250 selected_mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
253 if selected_mod ~= nil then
254 local modscreenshot = nil
256 --check for screenshot beeing available
257 local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
259 screenshotfile,error = io.open(screenshotfilename,"r")
261 screenshotfile:close()
262 modscreenshot = screenshotfilename
265 if modscreenshot == nil then
266 modscreenshot = modstore.basetexturedir .. "no_screenshot.png"
270 .. "image[5.5,0;3,2;" .. engine.formspec_escape(modscreenshot) .. "]"
271 .. "label[8.25,0.6;" .. selected_mod.name .. "]"
273 local descriptionlines = nil
275 local descriptionfilename = selected_mod.path .. "description.txt"
276 descriptionfile,error = io.open(descriptionfilename,"r")
278 descriptiontext = descriptionfile:read("*all")
280 descriptionlines = engine.splittext(descriptiontext,42)
281 descriptionfile:close()
283 descriptionlines = {}
284 table.insert(descriptionlines,fgettext("No mod description available"))
288 "label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
289 "textlist[5.5,2.2;6.2,2.4;description;"
291 for i=1,#descriptionlines,1 do
292 retval = retval .. engine.formspec_escape(descriptionlines[i]) .. ","
296 if selected_mod.is_modpack then
297 retval = retval .. ";0]" ..
298 "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
299 fgettext("Rename") .. "]"
300 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
301 .. fgettext("Uninstall selected modpack") .. "]"
305 retval = retval .. ",Depends:,"
307 toadd = modmgr.get_dependencies(selected_mod.path)
309 retval = retval .. toadd .. ";0]"
311 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
312 .. fgettext("Uninstall selected mod") .. "]"
318 --------------------------------------------------------------------------------
319 function modmgr.dialog_rename_modpack()
321 local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
324 "label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
325 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
328 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
329 fgettext("Accept") .. "]" ..
330 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
331 fgettext("Cancel") .. "]"
336 --------------------------------------------------------------------------------
337 function modmgr.precheck()
339 if modmgr.world_config_selected_world == nil then
340 modmgr.world_config_selected_world = 1
343 if modmgr.world_config_selected_mod == nil then
344 modmgr.world_config_selected_mod = 1
347 if modmgr.hide_gamemods == nil then
348 modmgr.hide_gamemods = true
351 if modmgr.hide_modpackcontents == nil then
352 modmgr.hide_modpackcontents = true
356 --------------------------------------------------------------------------------
357 function modmgr.render_modlist(render_list)
360 if render_list == nil then
361 if modmgr.global_mods == nil then
362 modmgr.refresh_globals()
364 render_list = modmgr.global_mods
367 local list = filterlist.get_list(render_list)
368 local last_modpack = nil
370 for i,v in ipairs(list) do
372 retval = retval ..","
378 local rawlist = filterlist.get_raw_list(render_list)
380 local all_enabled = true
381 for j=1,#rawlist,1 do
382 if rawlist[j].modpack == list[i].name and
383 rawlist[j].enabled ~= true then
389 if all_enabled == false then
390 color = mt_color_grey
392 color = mt_color_dark_green
396 if v.typ == "game_mod" then
397 color = mt_color_blue
400 color = mt_color_green
404 retval = retval .. color
405 if v.modpack ~= nil then
406 retval = retval .. " "
408 retval = retval .. v.name
414 --------------------------------------------------------------------------------
415 function modmgr.dialog_configure_world()
418 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
419 local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
423 "label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
424 "label[1.75,-0.25;" .. worldspec.name .. "]"
426 if modmgr.hide_gamemods then
427 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
429 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
432 if modmgr.hide_modpackcontents then
433 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
435 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
442 "label[0,0.45;" .. fgettext("Mod:") .. "]" ..
443 "label[0.75,0.45;" .. mod.name .. "]" ..
444 "label[0,1;" .. fgettext("Depends:") .. "]" ..
445 "textlist[0,1.5;5,4.25;world_config_depends;" ..
446 modmgr.get_dependencies(mod.path) .. ";0]" ..
447 "button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
448 "button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
450 if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
451 if mod.is_modpack then
452 local rawlist = filterlist.get_raw_list(modmgr.modlist)
454 local all_enabled = true
455 for j=1,#rawlist,1 do
456 if rawlist[j].modpack == mod.name and
457 rawlist[j].enabled ~= true then
463 if all_enabled == false then
464 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
466 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
470 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
472 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
478 "button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
479 "textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
481 retval = retval .. modmgr.render_modlist(modmgr.modlist)
483 retval = retval .. ";" .. modmgr.world_config_selected_mod .."]"
488 --------------------------------------------------------------------------------
489 function modmgr.handle_buttons(tab,fields)
493 if tab == "mod_mgr" then
494 retval = modmgr.handle_modmgr_buttons(fields)
497 if tab == "dialog_rename_modpack" then
498 retval = modmgr.handle_rename_modpack_buttons(fields)
501 if tab == "dialog_delete_mod" then
502 retval = modmgr.handle_delete_mod_buttons(fields)
505 if tab == "dialog_configure_world" then
506 retval = modmgr.handle_configure_world_buttons(fields)
512 --------------------------------------------------------------------------------
513 function modmgr.get_dependencies(modfolder)
515 if modfolder ~= nil then
516 local filename = modfolder ..
517 DIR_DELIM .. "depends.txt"
519 local dependencyfile = io.open(filename,"r")
521 if dependencyfile then
522 local dependency = dependencyfile:read("*l")
527 toadd = toadd .. dependency
528 dependency = dependencyfile:read()
530 dependencyfile:close()
538 --------------------------------------------------------------------------------
539 function modmgr.get_worldconfig(worldpath)
540 local filename = worldpath ..
541 DIR_DELIM .. "world.mt"
543 local worldfile = Settings(filename)
545 local worldconfig = {}
546 worldconfig.global_mods = {}
547 worldconfig.game_mods = {}
549 for key,value in pairs(worldfile:to_table()) do
550 if key == "gameid" then
551 worldconfig.id = value
553 worldconfig.global_mods[key] = engine.is_yes(value)
558 local gamespec = gamemgr.find_by_gameid(worldconfig.id)
559 gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
563 --------------------------------------------------------------------------------
564 function modmgr.handle_modmgr_buttons(fields)
571 if fields["modlist"] ~= nil then
572 local event = explode_textlist_event(fields["modlist"])
573 modmgr.selected_mod = event.index
576 if fields["btn_mod_mgr_install_local"] ~= nil then
577 engine.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
580 if fields["btn_mod_mgr_download"] ~= nil then
581 modstore.update_modlist()
582 retval.current_tab = "dialog_modstore_unsorted"
583 retval.is_dialog = true
584 retval.show_buttons = false
588 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
589 retval.current_tab = "dialog_rename_modpack"
590 retval.is_dialog = true
591 retval.show_buttons = false
595 if fields["btn_mod_mgr_delete_mod"] ~= nil then
596 retval.current_tab = "dialog_delete_mod"
597 retval.is_dialog = true
598 retval.show_buttons = false
602 if fields["mod_mgt_open_dlg_accepted"] ~= nil and
603 fields["mod_mgt_open_dlg_accepted"] ~= "" then
604 modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
610 --------------------------------------------------------------------------------
611 function modmgr.installmod(modfilename,basename)
612 local modfile = modmgr.identify_filetype(modfilename)
613 local modpath = modmgr.extract(modfile)
615 if modpath == nil then
616 gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
617 fgettext("\nInstall Mod: unsupported filetype \"$1\"", modfile.type)
622 local basefolder = modmgr.getbasefolder(modpath)
624 if basefolder.type == "modpack" then
625 local clean_path = nil
627 if basename ~= nil then
628 clean_path = "mp_" .. basename
631 if clean_path == nil then
632 clean_path = get_last_folder(cleanup_path(basefolder.path))
635 if clean_path ~= nil then
636 local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
637 if not engine.copy_dir(basefolder.path,targetpath) then
638 gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
641 gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
645 if basefolder.type == "mod" then
646 local targetfolder = basename
648 if targetfolder == nil then
649 targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
652 --if heuristic failed try to use current foldername
653 if targetfolder == nil then
654 targetfolder = get_last_folder(basefolder.path)
657 if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
658 local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder
659 engine.copy_dir(basefolder.path,targetpath)
661 gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
665 engine.delete_dir(modpath)
667 modmgr.refresh_globals()
671 --------------------------------------------------------------------------------
672 function modmgr.handle_rename_modpack_buttons(fields)
674 if fields["dlg_rename_modpack_confirm"] ~= nil then
675 local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
676 local oldpath = engine.get_modpath() .. DIR_DELIM .. mod.name
677 local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
678 engine.copy_dir(oldpath,targetpath,false)
684 current_tab = engine.setting_get("main_menu_tab")
687 --------------------------------------------------------------------------------
688 function modmgr.handle_configure_world_buttons(fields)
689 if fields["world_config_modlist"] ~= nil then
690 local event = explode_textlist_event(fields["world_config_modlist"])
691 modmgr.world_config_selected_mod = event.index
693 if event.typ == "DCL" then
694 modmgr.world_config_enable_mod(nil)
698 if fields["key_enter"] ~= nil then
699 modmgr.world_config_enable_mod(nil)
702 if fields["cb_mod_enable"] ~= nil then
703 local toset = engine.is_yes(fields["cb_mod_enable"])
704 modmgr.world_config_enable_mod(toset)
707 if fields["btn_mp_enable"] ~= nil or
708 fields["btn_mp_disable"] then
709 local toset = (fields["btn_mp_enable"] ~= nil)
710 modmgr.world_config_enable_mod(toset)
713 if fields["cb_hide_gamemods"] ~= nil then
714 local current = filterlist.get_filtercriteria(modmgr.modlist)
716 if current == nil then
720 if engine.is_yes(fields["cb_hide_gamemods"]) then
721 current.hide_game = true
722 modmgr.hide_gamemods = true
724 current.hide_game = false
725 modmgr.hide_gamemods = false
728 filterlist.set_filtercriteria(modmgr.modlist,current)
731 if fields["cb_hide_mpcontent"] ~= nil then
732 local current = filterlist.get_filtercriteria(modmgr.modlist)
734 if current == nil then
738 if engine.is_yes(fields["cb_hide_mpcontent"]) then
739 current.hide_modpackcontents = true
740 modmgr.hide_modpackcontents = true
742 current.hide_modpackcontents = false
743 modmgr.hide_modpackcontents = false
746 filterlist.set_filtercriteria(modmgr.modlist,current)
749 if fields["btn_config_world_save"] then
750 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
752 local filename = worldspec.path ..
753 DIR_DELIM .. "world.mt"
755 local worldfile = Settings(filename)
756 local mods = worldfile:to_table()
758 local rawlist = filterlist.get_raw_list(modmgr.modlist)
761 for i,mod in ipairs(rawlist) do
762 if not mod.is_modpack and
763 mod.typ ~= "game_mod" then
765 worldfile:set("load_mod_"..mod.name, "true")
767 worldfile:set("load_mod_"..mod.name, "false")
769 mods["load_mod_"..mod.name] = nil
773 -- Remove mods that are not present anymore
774 for key,value in pairs(mods) do
775 if key:sub(1,9) == "load_mod_" then
776 worldfile:remove(key)
780 if not worldfile:write() then
781 engine.log("error", "Failed to write world config file")
785 modmgr.worldconfig = nil
790 current_tab = engine.setting_get("main_menu_tab")
794 if fields["btn_config_world_cancel"] then
796 modmgr.worldconfig = nil
801 current_tab = engine.setting_get("main_menu_tab")
805 if fields["btn_all_mods"] then
806 local list = filterlist.get_raw_list(modmgr.modlist)
809 if list[i].typ ~= "game_mod" and
810 not list[i].is_modpack then
811 list[i].enabled = true
820 --------------------------------------------------------------------------------
821 function modmgr.world_config_enable_mod(toset)
822 local mod = filterlist.get_list(modmgr.modlist)
823 [engine.get_textlist_index("world_config_modlist")]
825 if mod.typ == "game_mod" then
826 -- game mods can't be enabled or disabled
827 elseif not mod.is_modpack then
829 mod.enabled = not mod.enabled
834 local list = filterlist.get_raw_list(modmgr.modlist)
836 if list[i].modpack == mod.name then
838 toset = not list[i].enabled
840 list[i].enabled = toset
845 --------------------------------------------------------------------------------
846 function modmgr.handle_delete_mod_buttons(fields)
847 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
849 if fields["dlg_delete_mod_confirm"] ~= nil then
851 if mod.path ~= nil and
853 mod.path ~= engine.get_modpath() then
854 if not engine.delete_dir(mod.path) then
855 gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", mod.path)
857 modmgr.refresh_globals()
859 gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", mod.path)
866 current_tab = engine.setting_get("main_menu_tab")
870 --------------------------------------------------------------------------------
871 function modmgr.dialog_delete_mod()
873 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
876 "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", mod.name) .. ";]"..
877 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
878 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
883 --------------------------------------------------------------------------------
884 function modmgr.preparemodlist(data)
887 local global_mods = {}
891 local modpath = engine.get_modpath()
893 if modpath ~= nil and
895 get_mods(modpath,global_mods)
898 for i=1,#global_mods,1 do
899 global_mods[i].typ = "global_mod"
900 table.insert(retval,global_mods[i])
904 local gamespec = gamemgr.find_by_gameid(data.gameid)
905 gamemgr.get_game_mods(gamespec, game_mods)
907 for i=1,#game_mods,1 do
908 game_mods[i].typ = "game_mod"
909 table.insert(retval,game_mods[i])
912 if data.worldpath == nil then
916 --read world mod configuration
917 local filename = data.worldpath ..
918 DIR_DELIM .. "world.mt"
920 local worldfile = Settings(filename)
922 for key,value in pairs(worldfile:to_table()) do
923 if key:sub(1, 9) == "load_mod_" then
927 if retval[i].name == key then
932 if element ~= nil then
933 element.enabled = engine.is_yes(value)
935 engine.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
943 --------------------------------------------------------------------------------
944 function modmgr.init_worldconfig()
946 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
948 if worldspec ~= nil then
950 modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path)
952 if modmgr.worldconfig.id == nil or
953 modmgr.worldconfig.id == "" then
954 modmgr.worldconfig = nil
958 modmgr.modlist = filterlist.create(
959 modmgr.preparemodlist, --refresh
960 modmgr.comparemod, --compare
961 function(element,uid) --uid match
962 if element.name == uid then
966 function(element,criteria)
967 if criteria.hide_game and
968 element.typ == "game_mod" then
972 if criteria.hide_modpackcontents and
973 element.modpack ~= nil then
978 { worldpath= worldspec.path,
979 gameid = worldspec.gameid }
982 filterlist.set_filtercriteria(modmgr.modlist, {
983 hide_game=modmgr.hide_gamemods,
984 hide_modpackcontents= modmgr.hide_modpackcontents
986 filterlist.add_sort_mechanism(modmgr.modlist, "alphabetic", sort_mod_list)
987 filterlist.set_sortmode(modmgr.modlist, "alphabetic")
995 --------------------------------------------------------------------------------
996 function modmgr.comparemod(elem1,elem2)
997 if elem1 == nil or elem2 == nil then
1000 if elem1.name ~= elem2.name then
1003 if elem1.is_modpack ~= elem2.is_modpack then
1006 if elem1.typ ~= elem2.typ then
1009 if elem1.modpack ~= elem2.modpack then
1013 if elem1.path ~= elem2.path then
1020 --------------------------------------------------------------------------------
1021 function modmgr.gettab(name)
1024 if name == "mod_mgr" then
1025 retval = retval .. modmgr.tab()
1028 if name == "dialog_rename_modpack" then
1029 retval = retval .. modmgr.dialog_rename_modpack()
1032 if name == "dialog_delete_mod" then
1033 retval = retval .. modmgr.dialog_delete_mod()
1036 if name == "dialog_configure_world" then
1037 retval = retval .. modmgr.dialog_configure_world()
1043 --------------------------------------------------------------------------------
1044 function modmgr.mod_exists(basename)
1046 if modmgr.global_mods == nil then
1047 modmgr.refresh_globals()
1050 if filterlist.raw_index_by_uid(modmgr.global_mods,basename) > 0 then
1057 --------------------------------------------------------------------------------
1058 function modmgr.get_global_mod(idx)
1060 if modmgr.global_mods == nil then
1064 if idx < 1 or idx > filterlist.size(modmgr.global_mods) then
1068 return filterlist.get_list(modmgr.global_mods)[idx]
1071 --------------------------------------------------------------------------------
1072 function modmgr.refresh_globals()
1073 modmgr.global_mods = filterlist.create(
1074 modmgr.preparemodlist, --refresh
1075 modmgr.comparemod, --compare
1076 function(element,uid) --uid match
1077 if element.name == uid then
1084 filterlist.add_sort_mechanism(modmgr.global_mods, "alphabetic", sort_mod_list)
1085 filterlist.set_sortmode(modmgr.global_mods, "alphabetic")
1088 --------------------------------------------------------------------------------
1089 function modmgr.identify_filetype(name)
1091 if name:sub(-3):lower() == "zip" then
1098 if name:sub(-6):lower() == "tar.gz" or
1099 name:sub(-3):lower() == "tgz"then
1106 if name:sub(-6):lower() == "tar.bz2" then
1113 if name:sub(-2):lower() == "7z" then