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.3;modlist;" ..
239 modmgr.render_modlist(modmgr.global_mods) ..
240 ";" .. modmgr.selected_mod .. "]"
243 "button[1,4.85;2,0.5;btn_mod_mgr_install_local;".. fgettext("Install") .. "]" ..
244 "button[3,4.85;2,0.5;btn_mod_mgr_download;".. fgettext("Download") .. "]"
246 local selected_mod = nil
248 if filterlist.size(modmgr.global_mods) >= modmgr.selected_mod then
249 selected_mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
252 if selected_mod ~= nil then
253 if selected_mod.is_modpack then
255 .. "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
256 fgettext("Rename") .. "]"
260 "label[6,1.9;".. fgettext("Depends:") .. "]" ..
261 "textlist[6,2.4;5.7,2;deplist;"
263 toadd = modmgr.get_dependencies(selected_mod.path)
265 retval = retval .. toadd .. ";0;true,false]"
270 retval = retval .. "button[8,4.85;2,0.5;btn_mod_mgr_delete_mod;"
271 .. fgettext("Delete") .. "]"
276 --------------------------------------------------------------------------------
277 function modmgr.dialog_rename_modpack()
279 local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
282 "label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
283 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
286 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
287 fgettext("Accept") .. "]" ..
288 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
289 fgettext("Cancel") .. "]"
294 --------------------------------------------------------------------------------
295 function modmgr.precheck()
297 if modmgr.world_config_selected_world == nil then
298 modmgr.world_config_selected_world = 1
301 if modmgr.world_config_selected_mod == nil then
302 modmgr.world_config_selected_mod = 1
305 if modmgr.hide_gamemods == nil then
306 modmgr.hide_gamemods = true
309 if modmgr.hide_modpackcontents == nil then
310 modmgr.hide_modpackcontents = true
314 --------------------------------------------------------------------------------
315 function modmgr.render_modlist(render_list)
318 if render_list == nil then
319 if modmgr.global_mods == nil then
320 modmgr.refresh_globals()
322 render_list = modmgr.global_mods
325 local list = filterlist.get_list(render_list)
326 local last_modpack = nil
328 for i,v in ipairs(list) do
330 retval = retval ..","
336 local rawlist = filterlist.get_raw_list(render_list)
338 local all_enabled = true
339 for j=1,#rawlist,1 do
340 if rawlist[j].modpack == list[i].name and
341 rawlist[j].enabled ~= true then
347 if all_enabled == false then
348 color = mt_color_grey
350 color = mt_color_dark_green
354 if v.typ == "game_mod" then
355 color = mt_color_blue
358 color = mt_color_green
362 retval = retval .. color
363 if v.modpack ~= nil then
364 retval = retval .. " "
366 retval = retval .. v.name
372 --------------------------------------------------------------------------------
373 function modmgr.dialog_configure_world()
376 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
377 local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
381 "label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
382 "label[1.75,-0.25;" .. worldspec.name .. "]"
384 if modmgr.hide_gamemods then
385 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
387 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
390 if modmgr.hide_modpackcontents then
391 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
393 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
400 "label[0,0.45;" .. fgettext("Mod:") .. "]" ..
401 "label[0.75,0.45;" .. mod.name .. "]" ..
402 "label[0,1;" .. fgettext("Depends:") .. "]" ..
403 "textlist[0,1.5;5,4.25;world_config_depends;" ..
404 modmgr.get_dependencies(mod.path) .. ";0]" ..
405 "button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
406 "button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
408 if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
409 if mod.is_modpack then
410 local rawlist = filterlist.get_raw_list(modmgr.modlist)
412 local all_enabled = true
413 for j=1,#rawlist,1 do
414 if rawlist[j].modpack == mod.name and
415 rawlist[j].enabled ~= true then
421 if all_enabled == false then
422 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
424 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
428 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
430 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
436 "button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
437 "textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
439 retval = retval .. modmgr.render_modlist(modmgr.modlist)
441 retval = retval .. ";" .. modmgr.world_config_selected_mod .."]"
446 --------------------------------------------------------------------------------
447 function modmgr.handle_buttons(tab,fields)
451 if tab == "mod_mgr" then
452 retval = modmgr.handle_modmgr_buttons(fields)
455 if tab == "dialog_rename_modpack" then
456 retval = modmgr.handle_rename_modpack_buttons(fields)
459 if tab == "dialog_delete_mod" then
460 retval = modmgr.handle_delete_mod_buttons(fields)
463 if tab == "dialog_configure_world" then
464 retval = modmgr.handle_configure_world_buttons(fields)
470 --------------------------------------------------------------------------------
471 function modmgr.get_dependencies(modfolder)
473 if modfolder ~= nil then
474 local filename = modfolder ..
475 DIR_DELIM .. "depends.txt"
477 local dependencyfile = io.open(filename,"r")
479 if dependencyfile then
480 local dependency = dependencyfile:read("*l")
485 toadd = toadd .. dependency
486 dependency = dependencyfile:read()
488 dependencyfile:close()
496 --------------------------------------------------------------------------------
497 function modmgr.get_worldconfig(worldpath)
498 local filename = worldpath ..
499 DIR_DELIM .. "world.mt"
501 local worldfile = io.open(filename,"r")
503 local worldconfig = {}
504 worldconfig.global_mods = {}
505 worldconfig.game_mods = {}
508 local dependency = worldfile:read("*l")
510 local parts = dependency:split("=")
512 local key = parts[1]:trim()
514 if key == "gameid" then
515 worldconfig.id = parts[2]:trim()
516 elseif key == "backend" then
517 worldconfig.backend = parts[2]:trim()
519 local key = parts[1]:trim():sub(10)
520 if parts[2]:trim() == "true" then
521 worldconfig.global_mods[key] = true
523 worldconfig.global_mods[key] = false
526 dependency = worldfile:read("*l")
530 print("Modmgr: " .. filename .. " not found")
534 local gamespec = gamemgr.find_by_gameid(worldconfig.id)
535 gamemgr.get_game_mods(gamespec, worldconfig.game_mods)
539 --------------------------------------------------------------------------------
540 function modmgr.handle_modmgr_buttons(fields)
547 if fields["modlist"] ~= nil then
548 local event = explode_textlist_event(fields["modlist"])
549 modmgr.selected_mod = event.index
552 if fields["btn_mod_mgr_install_local"] ~= nil then
553 engine.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
556 if fields["btn_mod_mgr_download"] ~= nil then
557 modstore.update_modlist()
558 retval.current_tab = "dialog_modstore_unsorted"
559 retval.is_dialog = true
560 retval.show_buttons = false
564 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
565 retval.current_tab = "dialog_rename_modpack"
566 retval.is_dialog = true
567 retval.show_buttons = false
571 if fields["btn_mod_mgr_delete_mod"] ~= nil then
572 retval.current_tab = "dialog_delete_mod"
573 retval.is_dialog = true
574 retval.show_buttons = false
578 if fields["mod_mgt_open_dlg_accepted"] ~= nil and
579 fields["mod_mgt_open_dlg_accepted"] ~= "" then
580 modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
586 --------------------------------------------------------------------------------
587 function modmgr.installmod(modfilename,basename)
588 local modfile = modmgr.identify_filetype(modfilename)
589 local modpath = modmgr.extract(modfile)
591 if modpath == nil then
592 gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
593 fgettext("\nInstall Mod: unsupported filetype \"$1\"", modfile.type)
598 local basefolder = modmgr.getbasefolder(modpath)
600 if basefolder.type == "modpack" then
601 local clean_path = nil
603 if basename ~= nil then
604 clean_path = "mp_" .. basename
607 if clean_path == nil then
608 clean_path = get_last_folder(cleanup_path(basefolder.path))
611 if clean_path ~= nil then
612 local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
613 if not engine.copy_dir(basefolder.path,targetpath) then
614 gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
617 gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
621 if basefolder.type == "mod" then
622 local targetfolder = basename
624 if targetfolder == nil then
625 targetfolder = modmgr.identify_modname(basefolder.path,"init.lua")
628 --if heuristic failed try to use current foldername
629 if targetfolder == nil then
630 targetfolder = get_last_folder(basefolder.path)
633 if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then
634 local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder
635 engine.copy_dir(basefolder.path,targetpath)
637 gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
641 engine.delete_dir(modpath)
643 modmgr.refresh_globals()
647 --------------------------------------------------------------------------------
648 function modmgr.handle_rename_modpack_buttons(fields)
650 if fields["dlg_rename_modpack_confirm"] ~= nil then
651 local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
652 local oldpath = engine.get_modpath() .. DIR_DELIM .. mod.name
653 local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
654 engine.copy_dir(oldpath,targetpath,false)
660 current_tab = engine.setting_get("main_menu_tab")
663 --------------------------------------------------------------------------------
664 function modmgr.handle_configure_world_buttons(fields)
665 if fields["world_config_modlist"] ~= nil then
666 local event = explode_textlist_event(fields["world_config_modlist"])
667 modmgr.world_config_selected_mod = event.index
669 if event.typ == "DCL" then
670 modmgr.world_config_enable_mod(nil)
674 if fields["key_enter"] ~= nil then
675 modmgr.world_config_enable_mod(nil)
678 if fields["cb_mod_enable"] ~= nil then
679 local toset = (fields["cb_mod_enable"] == "true")
680 modmgr.world_config_enable_mod(toset)
683 if fields["btn_mp_enable"] ~= nil or
684 fields["btn_mp_disable"] then
685 local toset = (fields["btn_mp_enable"] ~= nil)
686 modmgr.world_config_enable_mod(toset)
689 if fields["cb_hide_gamemods"] ~= nil then
690 local current = filterlist.get_filtercriteria(modmgr.modlist)
692 if current == nil then
696 if fields["cb_hide_gamemods"] == "true" then
697 current.hide_game = true
698 modmgr.hide_gamemods = true
700 current.hide_game = false
701 modmgr.hide_gamemods = false
704 filterlist.set_filtercriteria(modmgr.modlist,current)
707 if fields["cb_hide_mpcontent"] ~= nil then
708 local current = filterlist.get_filtercriteria(modmgr.modlist)
710 if current == nil then
714 if fields["cb_hide_mpcontent"] == "true" then
715 current.hide_modpackcontents = true
716 modmgr.hide_modpackcontents = true
718 current.hide_modpackcontents = false
719 modmgr.hide_modpackcontents = false
722 filterlist.set_filtercriteria(modmgr.modlist,current)
725 if fields["btn_config_world_save"] then
726 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
728 local filename = worldspec.path ..
729 DIR_DELIM .. "world.mt"
731 local worldfile = io.open(filename,"w")
734 worldfile:write("gameid = " .. modmgr.worldconfig.id .. "\nbackend = " .. modmgr.worldconfig.backend .. "\n")
736 local rawlist = filterlist.get_raw_list(modmgr.modlist)
738 for i=1,#rawlist,1 do
740 if not rawlist[i].is_modpack and
741 rawlist[i].typ ~= "game_mod" then
742 if rawlist[i].enabled then
743 worldfile:write("load_mod_" .. rawlist[i].name .. " = true" .. "\n")
745 worldfile:write("load_mod_" .. rawlist[i].name .. " = false" .. "\n")
752 print("failed to open world config file")
756 modmgr.worldconfig = nil
761 current_tab = engine.setting_get("main_menu_tab")
765 if fields["btn_config_world_cancel"] then
767 modmgr.worldconfig = nil
772 current_tab = engine.setting_get("main_menu_tab")
776 if fields["btn_all_mods"] then
777 local list = filterlist.get_raw_list(modmgr.modlist)
780 if list[i].typ ~= "game_mod" and
781 not list[i].is_modpack then
782 list[i].enabled = true
791 --------------------------------------------------------------------------------
792 function modmgr.world_config_enable_mod(toset)
793 local mod = filterlist.get_list(modmgr.modlist)
794 [engine.get_textlist_index("world_config_modlist")]
796 if mod.typ == "game_mod" then
797 -- game mods can't be enabled or disabled
798 elseif not mod.is_modpack then
800 mod.enabled = not mod.enabled
805 local list = filterlist.get_raw_list(modmgr.modlist)
807 if list[i].modpack == mod.name then
809 toset = not list[i].enabled
811 list[i].enabled = toset
816 --------------------------------------------------------------------------------
817 function modmgr.handle_delete_mod_buttons(fields)
818 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
820 if fields["dlg_delete_mod_confirm"] ~= nil then
822 if mod.path ~= nil and
824 mod.path ~= engine.get_modpath() then
825 if not engine.delete_dir(mod.path) then
826 gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", mod.path)
828 modmgr.refresh_globals()
830 gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", mod.path)
837 current_tab = engine.setting_get("main_menu_tab")
841 --------------------------------------------------------------------------------
842 function modmgr.dialog_delete_mod()
844 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
847 "field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", mod.name) .. ";]"..
848 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
849 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
854 --------------------------------------------------------------------------------
855 function modmgr.preparemodlist(data)
858 local global_mods = {}
862 local modpath = engine.get_modpath()
864 if modpath ~= nil and
866 get_mods(modpath,global_mods)
869 for i=1,#global_mods,1 do
870 global_mods[i].typ = "global_mod"
871 table.insert(retval,global_mods[i])
875 local gamespec = gamemgr.find_by_gameid(data.gameid)
876 gamemgr.get_game_mods(gamespec, game_mods)
878 for i=1,#game_mods,1 do
879 game_mods[i].typ = "game_mod"
880 table.insert(retval,game_mods[i])
883 if data.worldpath == nil then
887 --read world mod configuration
888 local filename = data.worldpath ..
889 DIR_DELIM .. "world.mt"
891 local worldfile = io.open(filename,"r")
893 local dependency = worldfile:read("*l")
895 local parts = dependency:split("=")
897 local key = parts[1]:trim()
899 if key ~= "gameid" then
900 local key = parts[1]:trim():sub(10)
903 if retval[i].name == key then
908 if element ~= nil then
909 if parts[2]:trim() == "true" then
910 element.enabled = true
912 element.enabled = false
915 print("Mod: " .. key .. " " .. dump(parts[2]) .. " but not found")
918 dependency = worldfile:read("*l")
927 --------------------------------------------------------------------------------
928 function modmgr.init_worldconfig()
930 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
932 if worldspec ~= nil then
934 modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path)
936 if modmgr.worldconfig.id == nil or
937 modmgr.worldconfig.id == "" then
938 modmgr.worldconfig = nil
942 modmgr.modlist = filterlist.create(
943 modmgr.preparemodlist, --refresh
944 modmgr.comparemod, --compare
945 function(element,uid) --uid match
946 if element.name == uid then
950 function(element,criteria)
951 if criteria.hide_game and
952 element.typ == "game_mod" then
956 if criteria.hide_modpackcontents and
957 element.modpack ~= nil then
962 { worldpath= worldspec.path,
963 gameid = worldspec.gameid }
966 filterlist.set_filtercriteria(modmgr.modlist, {
967 hide_game=modmgr.hide_gamemods,
968 hide_modpackcontents= modmgr.hide_modpackcontents
970 filterlist.add_sort_mechanism(modmgr.modlist, "alphabetic", sort_mod_list)
971 filterlist.set_sortmode(modmgr.modlist, "alphabetic")
979 --------------------------------------------------------------------------------
980 function modmgr.comparemod(elem1,elem2)
981 if elem1 == nil or elem2 == nil then
984 if elem1.name ~= elem2.name then
987 if elem1.is_modpack ~= elem2.is_modpack then
990 if elem1.typ ~= elem2.typ then
993 if elem1.modpack ~= elem2.modpack then
997 if elem1.path ~= elem2.path then
1004 --------------------------------------------------------------------------------
1005 function modmgr.gettab(name)
1008 if name == "mod_mgr" then
1009 retval = retval .. modmgr.tab()
1012 if name == "dialog_rename_modpack" then
1013 retval = retval .. modmgr.dialog_rename_modpack()
1016 if name == "dialog_delete_mod" then
1017 retval = retval .. modmgr.dialog_delete_mod()
1020 if name == "dialog_configure_world" then
1021 retval = retval .. modmgr.dialog_configure_world()
1027 --------------------------------------------------------------------------------
1028 function modmgr.mod_exists(basename)
1030 if modmgr.global_mods == nil then
1031 modmgr.refresh_globals()
1034 if filterlist.raw_index_by_uid(modmgr.global_mods,basename) > 0 then
1041 --------------------------------------------------------------------------------
1042 function modmgr.get_global_mod(idx)
1044 if modmgr.global_mods == nil then
1048 if idx < 1 or idx > filterlist.size(modmgr.global_mods) then
1052 return filterlist.get_list(modmgr.global_mods)[idx]
1055 --------------------------------------------------------------------------------
1056 function modmgr.refresh_globals()
1057 modmgr.global_mods = filterlist.create(
1058 modmgr.preparemodlist, --refresh
1059 modmgr.comparemod, --compare
1060 function(element,uid) --uid match
1061 if element.name == uid then
1068 filterlist.add_sort_mechanism(modmgr.global_mods, "alphabetic", sort_mod_list)
1069 filterlist.set_sortmode(modmgr.global_mods, "alphabetic")
1072 --------------------------------------------------------------------------------
1073 function modmgr.identify_filetype(name)
1075 if name:sub(-3):lower() == "zip" then
1082 if name:sub(-6):lower() == "tar.gz" or
1083 name:sub(-3):lower() == "tgz"then
1090 if name:sub(-6):lower() == "tar.bz2" then
1097 if name:sub(-2):lower() == "7z" then