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("register_tool") or
197 line:find("register_craftitem") or
198 line:find("register_node") then
199 modname = modmgr.parse_register_line(line)
202 if line:find("dofile") then
203 modname = modmgr.parse_dofile_line(modpath,line)
206 if modname ~= nil then
211 line = testfile:read()
219 --------------------------------------------------------------------------------
220 function modmgr.tab()
221 if modmgr.global_mods == nil then
222 modmgr.refresh_globals()
225 if modmgr.selected_mod == nil then
226 modmgr.selected_mod = 1
230 "vertlabel[0,-0.25;".. fgettext("MODS") .. "]" ..
231 "label[0.8,-0.25;".. fgettext("Installed Mods:") .. "]" ..
232 "textlist[0.75,0.25;4.5,4;modlist;" ..
233 modmgr.render_modlist(modmgr.global_mods) ..
234 ";" .. modmgr.selected_mod .. "]"
237 "label[0.8,4.2;" .. fgettext("Add mod:") .. "]" ..
238 -- TODO Disabled due to upcoming release 0.4.8 and irrlicht messing up localization
239 -- "button[0.75,4.85;1.8,0.5;btn_mod_mgr_install_local;".. fgettext("Local install") .. "]" ..
240 "button[2.45,4.85;3.05,0.5;btn_mod_mgr_download;".. fgettext("Online mod repository") .. "]"
242 local selected_mod = nil
244 if filterlist.size(modmgr.global_mods) >= modmgr.selected_mod then
245 selected_mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
248 if selected_mod ~= nil then
249 local modscreenshot = nil
251 --check for screenshot beeing available
252 local screenshotfilename = selected_mod.path .. DIR_DELIM .. "screenshot.png"
254 screenshotfile,error = io.open(screenshotfilename,"r")
256 screenshotfile:close()
257 modscreenshot = screenshotfilename
260 if modscreenshot == nil then
261 modscreenshot = modstore.basetexturedir .. "no_screenshot.png"
265 .. "image[5.5,0;3,2;" .. engine.formspec_escape(modscreenshot) .. "]"
266 .. "label[8.25,0.6;" .. selected_mod.name .. "]"
268 local descriptionlines = nil
270 local descriptionfilename = selected_mod.path .. "description.txt"
271 descriptionfile,error = io.open(descriptionfilename,"r")
273 descriptiontext = descriptionfile:read("*all")
275 descriptionlines = engine.splittext(descriptiontext,42)
276 descriptionfile:close()
278 descriptionlines = {}
279 table.insert(descriptionlines,fgettext("No mod description available"))
283 "label[5.5,1.7;".. fgettext("Mod information:") .. "]" ..
284 "textlist[5.5,2.2;6.2,2.4;description;"
286 for i=1,#descriptionlines,1 do
287 retval = retval .. engine.formspec_escape(descriptionlines[i]) .. ","
291 if selected_mod.is_modpack then
292 retval = retval .. ";0]" ..
293 "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
294 fgettext("Rename") .. "]"
295 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
296 .. fgettext("Uninstall selected modpack") .. "]"
300 retval = retval .. ",Depends:,"
302 toadd = modmgr.get_dependencies(selected_mod.path)
304 retval = retval .. toadd .. ";0]"
306 retval = retval .. "button[5.5,4.85;4.5,0.5;btn_mod_mgr_delete_mod;"
307 .. fgettext("Uninstall selected mod") .. "]"
313 --------------------------------------------------------------------------------
314 function modmgr.dialog_rename_modpack()
316 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
319 "label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
320 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
323 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
324 fgettext("Accept") .. "]" ..
325 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
326 fgettext("Cancel") .. "]"
331 --------------------------------------------------------------------------------
332 function modmgr.precheck()
334 if modmgr.world_config_selected_world == nil then
335 modmgr.world_config_selected_world = 1
338 if modmgr.world_config_selected_mod == nil then
339 modmgr.world_config_selected_mod = 1
342 if modmgr.hide_gamemods == nil then
343 modmgr.hide_gamemods = true
346 if modmgr.hide_modpackcontents == nil then
347 modmgr.hide_modpackcontents = true
351 --------------------------------------------------------------------------------
352 function modmgr.render_modlist(render_list)
355 if render_list == nil then
356 if modmgr.global_mods == nil then
357 modmgr.refresh_globals()
359 render_list = modmgr.global_mods
362 local list = filterlist.get_list(render_list)
363 local last_modpack = nil
365 for i,v in ipairs(list) do
367 retval = retval ..","
373 local rawlist = filterlist.get_raw_list(render_list)
375 local all_enabled = true
376 for j=1,#rawlist,1 do
377 if rawlist[j].modpack == list[i].name and
378 rawlist[j].enabled ~= true then
384 if all_enabled == false then
385 color = mt_color_grey
387 color = mt_color_dark_green
391 if v.typ == "game_mod" then
392 color = mt_color_blue
395 color = mt_color_green
399 retval = retval .. color
400 if v.modpack ~= nil then
401 retval = retval .. " "
403 retval = retval .. v.name
409 --------------------------------------------------------------------------------
410 function modmgr.dialog_configure_world()
413 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
414 local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
417 "size[11,6.5,true]" ..
418 "label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
419 "label[1.75,-0.25;" .. worldspec.name .. "]"
421 if modmgr.hide_gamemods then
422 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
424 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
427 if modmgr.hide_modpackcontents then
428 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
430 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
437 "label[0,0.45;" .. fgettext("Mod:") .. "]" ..
438 "label[0.75,0.45;" .. mod.name .. "]" ..
439 "label[0,1;" .. fgettext("Depends:") .. "]" ..
440 "textlist[0,1.5;5,4.25;world_config_depends;" ..
441 modmgr.get_dependencies(mod.path) .. ";0]" ..
442 "button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
443 "button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
445 if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
446 if mod.is_modpack then
447 local rawlist = filterlist.get_raw_list(modmgr.modlist)
449 local all_enabled = true
450 for j=1,#rawlist,1 do
451 if rawlist[j].modpack == mod.name and
452 rawlist[j].enabled ~= true then
458 if all_enabled == false then
459 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
461 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
465 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
467 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
473 "button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
474 "textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
476 retval = retval .. modmgr.render_modlist(modmgr.modlist)
478 retval = retval .. ";" .. modmgr.world_config_selected_mod .."]"
483 --------------------------------------------------------------------------------
484 function modmgr.handle_buttons(tab,fields)
488 if tab == "mod_mgr" then
489 retval = modmgr.handle_modmgr_buttons(fields)
492 if tab == "dialog_rename_modpack" then
493 retval = modmgr.handle_rename_modpack_buttons(fields)
496 if tab == "dialog_delete_mod" then
497 retval = modmgr.handle_delete_mod_buttons(fields)
500 if tab == "dialog_configure_world" then
501 retval = modmgr.handle_configure_world_buttons(fields)
507 --------------------------------------------------------------------------------
508 function modmgr.get_dependencies(modfolder)
510 if modfolder ~= nil then
511 local filename = modfolder ..
512 DIR_DELIM .. "depends.txt"
514 local dependencyfile = io.open(filename,"r")
516 if dependencyfile then
517 local dependency = dependencyfile:read("*l")
522 toadd = toadd .. dependency
523 dependency = dependencyfile:read()
525 dependencyfile:close()
533 --------------------------------------------------------------------------------
534 function modmgr.get_worldconfig(worldpath)
535 local filename = worldpath ..
536 DIR_DELIM .. "world.mt"
538 local worldfile = Settings(filename)
540 local worldconfig = {}
541 worldconfig.global_mods = {}
542 worldconfig.game_mods = {}
544 for key,value in pairs(worldfile:to_table()) do
545 if key == "gameid" then
546 worldconfig.id = value
548 worldconfig.global_mods[key] = engine.is_yes(value)
553 local gamespec = gamemgr.find_by_gameid(worldconfig.id)
554 gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
558 --------------------------------------------------------------------------------
559 function modmgr.handle_modmgr_buttons(fields)
566 if fields["modlist"] ~= nil then
567 local event = engine.explode_textlist_event(fields["modlist"])
568 modmgr.selected_mod = event.index
571 if fields["btn_mod_mgr_install_local"] ~= nil then
572 engine.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
575 if fields["btn_mod_mgr_download"] ~= nil then
576 modstore.update_modlist()
577 retval.current_tab = "dialog_modstore_unsorted"
578 retval.is_dialog = true
579 retval.show_buttons = false
583 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
584 retval.current_tab = "dialog_rename_modpack"
585 retval.is_dialog = true
586 retval.show_buttons = false
590 if fields["btn_mod_mgr_delete_mod"] ~= nil then
591 retval.current_tab = "dialog_delete_mod"
592 retval.is_dialog = true
593 retval.show_buttons = false
597 if fields["mod_mgt_open_dlg_accepted"] ~= nil and
598 fields["mod_mgt_open_dlg_accepted"] ~= "" then
599 modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
605 --------------------------------------------------------------------------------
606 function modmgr.installmod(modfilename,basename)
607 local modfile = modmgr.identify_filetype(modfilename)
608 local modpath = modmgr.extract(modfile)
610 if modpath == nil then
611 gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
612 fgettext("\nInstall Mod: unsupported filetype \"$1\" or broken archive", modfile.type)
617 local basefolder = modmgr.getbasefolder(modpath)
619 if basefolder.type == "modpack" then
620 local clean_path = nil
622 if basename ~= nil then
623 clean_path = "mp_" .. basename
626 if clean_path == nil then
627 clean_path = get_last_folder(cleanup_path(basefolder.path))
630 if clean_path ~= nil then
631 local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
632 if not engine.copy_dir(basefolder.path,targetpath) then
633 gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
636 gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
640 if basefolder.type == "mod" then
641 local targetfolder = basename
643 if targetfolder == nil then
644 targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
647 --if heuristic failed try to use current foldername
648 if targetfolder == nil then
649 targetfolder = get_last_folder(basefolder.path)
652 if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
653 local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder
654 engine.copy_dir(basefolder.path,targetpath)
656 gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
660 engine.delete_dir(modpath)
662 modmgr.refresh_globals()
666 --------------------------------------------------------------------------------
667 function modmgr.handle_rename_modpack_buttons(fields)
669 if fields["dlg_rename_modpack_confirm"] ~= nil then
670 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
671 local oldpath = engine.get_modpath() .. DIR_DELIM .. mod.name
672 local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
673 engine.copy_dir(oldpath,targetpath,false)
674 modmgr.refresh_globals()
675 modmgr.selected_mod = filterlist.get_current_index(modmgr.global_mods,
676 filterlist.raw_index_by_uid(modmgr.global_mods, fields["te_modpack_name"]))
682 current_tab = engine.setting_get("main_menu_tab")
685 --------------------------------------------------------------------------------
686 function modmgr.handle_configure_world_buttons(fields)
687 if fields["world_config_modlist"] ~= nil then
688 local event = engine.explode_textlist_event(fields["world_config_modlist"])
689 modmgr.world_config_selected_mod = event.index
691 if event.type == "DCL" then
692 modmgr.world_config_enable_mod(nil)
696 if fields["key_enter"] ~= nil then
697 modmgr.world_config_enable_mod(nil)
700 if fields["cb_mod_enable"] ~= nil then
701 local toset = engine.is_yes(fields["cb_mod_enable"])
702 modmgr.world_config_enable_mod(toset)
705 if fields["btn_mp_enable"] ~= nil or
706 fields["btn_mp_disable"] then
707 local toset = (fields["btn_mp_enable"] ~= nil)
708 modmgr.world_config_enable_mod(toset)
711 if fields["cb_hide_gamemods"] ~= nil then
712 local current = filterlist.get_filtercriteria(modmgr.modlist)
714 if current == nil then
718 if engine.is_yes(fields["cb_hide_gamemods"]) then
719 current.hide_game = true
720 modmgr.hide_gamemods = true
722 current.hide_game = false
723 modmgr.hide_gamemods = false
726 filterlist.set_filtercriteria(modmgr.modlist,current)
729 if fields["cb_hide_mpcontent"] ~= nil then
730 local current = filterlist.get_filtercriteria(modmgr.modlist)
732 if current == nil then
736 if engine.is_yes(fields["cb_hide_mpcontent"]) then
737 current.hide_modpackcontents = true
738 modmgr.hide_modpackcontents = true
740 current.hide_modpackcontents = false
741 modmgr.hide_modpackcontents = false
744 filterlist.set_filtercriteria(modmgr.modlist,current)
747 if fields["btn_config_world_save"] then
748 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
750 local filename = worldspec.path ..
751 DIR_DELIM .. "world.mt"
753 local worldfile = Settings(filename)
754 local mods = worldfile:to_table()
756 local rawlist = filterlist.get_raw_list(modmgr.modlist)
759 for i,mod in ipairs(rawlist) do
760 if not mod.is_modpack and
761 mod.typ ~= "game_mod" then
763 worldfile:set("load_mod_"..mod.name, "true")
765 worldfile:set("load_mod_"..mod.name, "false")
767 mods["load_mod_"..mod.name] = nil
771 -- Remove mods that are not present anymore
772 for key,value in pairs(mods) do
773 if key:sub(1,9) == "load_mod_" then
774 worldfile:remove(key)
778 if not worldfile:write() then
779 engine.log("error", "Failed to write world config file")
783 modmgr.worldconfig = nil
788 current_tab = engine.setting_get("main_menu_tab")
792 if fields["btn_config_world_cancel"] then
794 modmgr.worldconfig = nil
799 current_tab = engine.setting_get("main_menu_tab")
803 if fields["btn_all_mods"] then
804 local list = filterlist.get_raw_list(modmgr.modlist)
807 if list[i].typ ~= "game_mod" and
808 not list[i].is_modpack then
809 list[i].enabled = true
818 --------------------------------------------------------------------------------
819 function modmgr.world_config_enable_mod(toset)
820 local mod = filterlist.get_list(modmgr.modlist)
821 [engine.get_textlist_index("world_config_modlist")]
823 if mod.typ == "game_mod" then
824 -- game mods can't be enabled or disabled
825 elseif not mod.is_modpack then
827 mod.enabled = not mod.enabled
832 local list = filterlist.get_raw_list(modmgr.modlist)
834 if list[i].modpack == mod.name then
836 toset = not list[i].enabled
838 list[i].enabled = toset
843 --------------------------------------------------------------------------------
844 function modmgr.handle_delete_mod_buttons(fields)
845 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
847 if fields["dlg_delete_mod_confirm"] ~= nil then
849 if mod.path ~= nil and
851 mod.path ~= engine.get_modpath() then
852 if not engine.delete_dir(mod.path) then
853 gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", mod.path)
855 modmgr.refresh_globals()
857 gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", mod.path)
864 current_tab = engine.setting_get("main_menu_tab")
868 --------------------------------------------------------------------------------
869 function modmgr.dialog_delete_mod()
871 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
874 "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", mod.name) .. ";]"..
875 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
876 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
881 --------------------------------------------------------------------------------
882 function modmgr.preparemodlist(data)
885 local global_mods = {}
889 local modpath = engine.get_modpath()
891 if modpath ~= nil and
893 get_mods(modpath,global_mods)
896 for i=1,#global_mods,1 do
897 global_mods[i].typ = "global_mod"
898 table.insert(retval,global_mods[i])
902 local gamespec = gamemgr.find_by_gameid(data.gameid)
903 gamemgr.get_game_mods(gamespec, game_mods)
905 for i=1,#game_mods,1 do
906 game_mods[i].typ = "game_mod"
907 table.insert(retval,game_mods[i])
910 if data.worldpath == nil then
914 --read world mod configuration
915 local filename = data.worldpath ..
916 DIR_DELIM .. "world.mt"
918 local worldfile = Settings(filename)
920 for key,value in pairs(worldfile:to_table()) do
921 if key:sub(1, 9) == "load_mod_" then
925 if retval[i].name == key then
930 if element ~= nil then
931 element.enabled = engine.is_yes(value)
933 engine.log("info", "Mod: " .. key .. " " .. dump(value) .. " but not found")
941 --------------------------------------------------------------------------------
942 function modmgr.init_worldconfig()
944 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
946 if worldspec ~= nil then
948 modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path)
950 if modmgr.worldconfig.id == nil or
951 modmgr.worldconfig.id == "" then
952 modmgr.worldconfig = nil
956 modmgr.modlist = filterlist.create(
957 modmgr.preparemodlist, --refresh
958 modmgr.comparemod, --compare
959 function(element,uid) --uid match
960 if element.name == uid then
964 function(element,criteria)
965 if criteria.hide_game and
966 element.typ == "game_mod" then
970 if criteria.hide_modpackcontents and
971 element.modpack ~= nil then
976 { worldpath= worldspec.path,
977 gameid = worldspec.gameid }
980 filterlist.set_filtercriteria(modmgr.modlist, {
981 hide_game=modmgr.hide_gamemods,
982 hide_modpackcontents= modmgr.hide_modpackcontents
984 filterlist.add_sort_mechanism(modmgr.modlist, "alphabetic", sort_mod_list)
985 filterlist.set_sortmode(modmgr.modlist, "alphabetic")
993 --------------------------------------------------------------------------------
994 function modmgr.comparemod(elem1,elem2)
995 if elem1 == nil or elem2 == nil then
998 if elem1.name ~= elem2.name then
1001 if elem1.is_modpack ~= elem2.is_modpack then
1004 if elem1.typ ~= elem2.typ then
1007 if elem1.modpack ~= elem2.modpack then
1011 if elem1.path ~= elem2.path then
1018 --------------------------------------------------------------------------------
1019 function modmgr.gettab(name)
1022 if name == "mod_mgr" then
1023 retval = retval .. modmgr.tab()
1026 if name == "dialog_rename_modpack" then
1027 retval = retval .. modmgr.dialog_rename_modpack()
1030 if name == "dialog_delete_mod" then
1031 retval = retval .. modmgr.dialog_delete_mod()
1034 if name == "dialog_configure_world" then
1035 retval = retval .. modmgr.dialog_configure_world()
1041 --------------------------------------------------------------------------------
1042 function modmgr.mod_exists(basename)
1044 if modmgr.global_mods == nil then
1045 modmgr.refresh_globals()
1048 if filterlist.raw_index_by_uid(modmgr.global_mods,basename) > 0 then
1055 --------------------------------------------------------------------------------
1056 function modmgr.get_global_mod(idx)
1058 if modmgr.global_mods == nil then
1062 if idx == nil or idx < 1 or idx > filterlist.size(modmgr.global_mods) then
1066 return filterlist.get_list(modmgr.global_mods)[idx]
1069 --------------------------------------------------------------------------------
1070 function modmgr.refresh_globals()
1071 modmgr.global_mods = filterlist.create(
1072 modmgr.preparemodlist, --refresh
1073 modmgr.comparemod, --compare
1074 function(element,uid) --uid match
1075 if element.name == uid then
1082 filterlist.add_sort_mechanism(modmgr.global_mods, "alphabetic", sort_mod_list)
1083 filterlist.set_sortmode(modmgr.global_mods, "alphabetic")
1086 --------------------------------------------------------------------------------
1087 function modmgr.identify_filetype(name)
1089 if name:sub(-3):lower() == "zip" then
1096 if name:sub(-6):lower() == "tar.gz" or
1097 name:sub(-3):lower() == "tgz"then
1104 if name:sub(-6):lower() == "tar.bz2" then
1111 if name:sub(-2):lower() == "7z" then