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;MODS]" ..
237 "label[0.8,-0.25;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;Install]" ..
244 "button[3,4.85;2,0.5;btn_mod_mgr_download;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
254 retval = retval .. "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;Rename]"
258 "label[6,1.9;Depends:]" ..
259 "textlist[6,2.4;5.7,2;deplist;"
261 toadd = modmgr.get_dependencies(selected_mod.path)
263 retval = retval .. toadd .. ";0;true,false]"
268 retval = retval .. "button[8,4.85;2,0.5;btn_mod_mgr_delete_mod;Delete]"
273 --------------------------------------------------------------------------------
274 function modmgr.dialog_rename_modpack()
276 local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
279 "label[1.75,1;Rename Modpack:]"..
280 "field[4.5,1.4;6,0.5;te_modpack_name;;" ..
283 "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;Accept]" ..
284 "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;Cancel]"
289 --------------------------------------------------------------------------------
290 function modmgr.precheck()
292 if modmgr.world_config_selected_world == nil then
293 modmgr.world_config_selected_world = 1
296 if modmgr.world_config_selected_mod == nil then
297 modmgr.world_config_selected_mod = 1
300 if modmgr.hide_gamemods == nil then
301 modmgr.hide_gamemods = true
304 if modmgr.hide_modpackcontents == nil then
305 modmgr.hide_modpackcontents = true
309 --------------------------------------------------------------------------------
310 function modmgr.render_modlist(render_list)
313 if render_list == nil then
314 if modmgr.global_mods == nil then
315 modmgr.refresh_globals()
317 render_list = modmgr.global_mods
320 local list = filterlist.get_list(render_list)
321 local last_modpack = nil
323 for i,v in ipairs(list) do
325 retval = retval ..","
329 local rawlist = filterlist.get_raw_list(render_list)
331 local all_enabled = true
332 for j=1,#rawlist,1 do
333 if rawlist[j].modpack == list[i].name and
334 rawlist[j].enabled ~= true then
340 if all_enabled == false then
341 retval = retval .. mt_color_grey
343 retval = retval .. mt_color_dark_green
347 if v.typ == "game_mod" then
348 retval = retval .. mt_color_blue
351 retval = retval .. mt_color_green
354 if v.modpack ~= nil then
355 retval = retval .. " "
357 retval = retval .. v.name
363 --------------------------------------------------------------------------------
364 function modmgr.dialog_configure_world()
367 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
368 local mod = filterlist.get_list(modmgr.modlist)[modmgr.world_config_selected_mod]
372 "label[1.5,-0.25;World: " .. worldspec.name .. "]"
374 if modmgr.hide_gamemods then
375 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;Hide Game;true]"
377 retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;Hide Game;false]"
380 if modmgr.hide_modpackcontents then
381 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;Hide mp content;true]"
383 retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;Hide mp content;false]"
390 "label[0,0.45;Mod:]" ..
391 "label[0.75,0.45;" .. mod.name .. "]" ..
392 "label[0,1;Depends:]" ..
393 "textlist[0,1.5;5,4.25;world_config_depends;" ..
394 modmgr.get_dependencies(mod.path) .. ";0]" ..
395 "button[9.25,6.35;2,0.5;btn_config_world_save;Save]" ..
396 "button[7.4,6.35;2,0.5;btn_config_world_cancel;Cancel]"
398 if engine.setting_get("old_style_mod_selection") == "true" then
399 local selected = engine.get_textlist_index("world_config_modlist")
400 local mod = filterlist.get_list(modmgr.modlist)[selected]
403 if mod.is_modpack then
404 local rawlist = filterlist.get_raw_list(modmgr.modlist)
406 local all_enabled = true
407 for j=1,#rawlist,1 do
408 if rawlist[j].modpack == mod.name and
409 rawlist[j].enabled ~= true then
415 if all_enabled == false then
416 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;Enable MP]"
418 retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;Disable MP]"
422 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;enabled;true]"
424 retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;enabled;false]"
431 "button[8.5,-0.125;2.5,0.5;btn_all_mods;Enable all]"
434 "button[5.5,-0.125;5.75,0.5;btn_all_mods;Enable all Mods]"
437 "textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
440 retval = retval .. modmgr.render_modlist(modmgr.modlist)
442 retval = retval .. ";" .. modmgr.world_config_selected_mod .."]"
447 --------------------------------------------------------------------------------
448 function modmgr.handle_buttons(tab,fields)
452 if tab == "mod_mgr" then
453 retval = modmgr.handle_modmgr_buttons(fields)
456 if tab == "dialog_rename_modpack" then
457 retval = modmgr.handle_rename_modpack_buttons(fields)
460 if tab == "dialog_delete_mod" then
461 retval = modmgr.handle_delete_mod_buttons(fields)
464 if tab == "dialog_configure_world" then
465 retval = modmgr.handle_configure_world_buttons(fields)
471 --------------------------------------------------------------------------------
472 function modmgr.get_dependencies(modfolder)
474 if modfolder ~= nil then
475 local filename = modfolder ..
476 DIR_DELIM .. "depends.txt"
478 local dependencyfile = io.open(filename,"r")
480 if dependencyfile then
481 local dependency = dependencyfile:read("*l")
486 toadd = toadd .. dependency
487 dependency = dependencyfile:read()
489 dependencyfile:close()
497 --------------------------------------------------------------------------------
498 function modmgr.get_worldconfig(worldpath)
499 local filename = worldpath ..
500 DIR_DELIM .. "world.mt"
502 local worldfile = io.open(filename,"r")
504 local worldconfig = {}
505 worldconfig.global_mods = {}
506 worldconfig.game_mods = {}
509 local dependency = worldfile:read("*l")
511 local parts = dependency:split("=")
513 local key = parts[1]:trim()
515 if key == "gameid" then
516 worldconfig.id = parts[2]:trim()
518 local key = parts[1]:trim():sub(10)
519 if parts[2]:trim() == "true" then
520 worldconfig.global_mods[key] = true
522 worldconfig.global_mods[key] = false
525 dependency = worldfile:read("*l")
529 print("Modmgr: " .. filename .. " not found")
533 local gamemodpath = engine.get_gamepath() .. DIR_DELIM .. worldconfig.id .. DIR_DELIM .. "mods"
535 get_mods(gamemodpath,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","Select Mod File:")
556 if fields["btn_mod_mgr_download"] ~= nil then
557 retval.current_tab = "dialog_modstore_unsorted"
558 retval.is_dialog = true
559 retval.show_buttons = false
563 if fields["btn_mod_mgr_rename_modpack"] ~= nil then
564 retval.current_tab = "dialog_rename_modpack"
565 retval.is_dialog = true
566 retval.show_buttons = false
570 if fields["btn_mod_mgr_delete_mod"] ~= nil then
571 retval.current_tab = "dialog_delete_mod"
572 retval.is_dialog = true
573 retval.show_buttons = false
577 if fields["mod_mgt_open_dlg_accepted"] ~= nil and
578 fields["mod_mgt_open_dlg_accepted"] ~= "" then
579 modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil)
585 --------------------------------------------------------------------------------
586 function modmgr.installmod(modfilename,basename)
587 local modfile = modmgr.identify_filetype(modfilename)
588 local modpath = modmgr.extract(modfile)
590 if modpath == nil then
591 gamedata.errormessage = "Install Mod: file: " .. modfile.name ..
592 "\nInstall Mod: unsupported filetype \"" .. modfile.type .. "\""
597 local basefolder = modmgr.getbasefolder(modpath)
599 if basefolder.type == "modpack" then
600 local clean_path = nil
602 if basename ~= nil then
603 clean_path = "mp_" .. basename
606 if clean_path == nil then
607 clean_path = get_last_folder(cleanup_path(basefolder.path))
610 if clean_path ~= nil then
611 local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
612 if not engine.copy_dir(basefolder.path,targetpath) then
613 gamedata.errormessage = "Failed to install " .. basename .. " to " .. targetpath
616 gamedata.errormessage = "Install Mod: unable to find suitable foldername for modpack "
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 = "Install Mod: unable to find real modname for: "
642 engine.delete_dir(modpath)
644 modmgr.refresh_globals()
648 --------------------------------------------------------------------------------
649 function modmgr.handle_rename_modpack_buttons(fields)
651 if fields["dlg_rename_modpack_confirm"] ~= nil then
652 local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
653 local oldpath = engine.get_modpath() .. DIR_DELIM .. mod.name
654 local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"]
655 engine.copy_dir(oldpath,targetpath,false)
661 current_tab = engine.setting_get("main_menu_tab")
664 --------------------------------------------------------------------------------
665 function modmgr.handle_configure_world_buttons(fields)
666 if fields["world_config_modlist"] ~= nil then
667 local event = explode_textlist_event(fields["world_config_modlist"])
668 modmgr.world_config_selected_mod = event.index
670 if engine.setting_get("old_style_mod_selection") ~= "true" then
671 if event.typ == "DCL" then
672 local mod = filterlist.get_list(modmgr.modlist)[event.index]
674 if mod.typ == "game_mod" then
678 if not mod.is_modpack then
679 mod.enabled = not mod.enabled
681 local list = filterlist.get_raw_list(modmgr.modlist)
685 if list[i].modpack == mod.name then
687 toset = not list[i].enabled
690 list[i].enabled = toset
698 if engine.setting_get("old_style_mod_selection") == "true" then
699 if fields["cb_mod_enable"] ~= nil then
700 local mod = filterlist.get_list(modmgr.modlist)
701 [engine.get_textlist_index("world_config_modlist")]
702 if fields["cb_mod_enable"] == "true" then
709 if fields["btn_mp_enable"] ~= nil or
710 fields["btn_mp_disable"] then
711 local mod = filterlist.get_list(modmgr.modlist)
712 [engine.get_textlist_index("world_config_modlist")]
715 if fields["btn_mp_enable"] ~= nil then
718 local list = filterlist.get_raw_list(modmgr.modlist)
721 if list[i].modpack == mod.name then
722 list[i].enabled = toset
728 if fields["cb_hide_gamemods"] ~= nil then
729 local current = filterlist.get_filtercriteria(modmgr.modlist)
731 if current == nil then
735 if fields["cb_hide_gamemods"] == "true" then
736 current.hide_game = true
737 modmgr.hide_gamemods = true
739 current.hide_game = false
740 modmgr.hide_gamemods = false
743 filterlist.set_filtercriteria(modmgr.modlist,current)
746 if fields["cb_hide_mpcontent"] ~= nil then
747 local current = filterlist.get_filtercriteria(modmgr.modlist)
749 if current == nil then
753 if fields["cb_hide_mpcontent"] == "true" then
754 current.hide_modpackcontents = true
755 modmgr.hide_modpackcontents = true
757 current.hide_modpackcontents = false
758 modmgr.hide_modpackcontents = false
761 filterlist.set_filtercriteria(modmgr.modlist,current)
764 if fields["btn_config_world_save"] then
765 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
767 local filename = worldspec.path ..
768 DIR_DELIM .. "world.mt"
770 local worldfile = io.open(filename,"w")
773 worldfile:write("gameid = " .. modmgr.worldconfig.id .. "\n")
775 local rawlist = filterlist.get_raw_list(modmgr.modlist)
777 for i=1,#rawlist,1 do
779 if not rawlist[i].is_modpack and
780 rawlist[i].typ ~= "game_mod" then
781 if rawlist[i].enabled then
782 worldfile:write("load_mod_" .. rawlist[i].name .. " = true" .. "\n")
784 worldfile:write("load_mod_" .. rawlist[i].name .. " = false" .. "\n")
791 print("failed to open world config file")
795 modmgr.worldconfig = nil
800 current_tab = engine.setting_get("main_menu_tab")
804 if fields["btn_config_world_cancel"] then
806 modmgr.worldconfig = nil
811 current_tab = engine.setting_get("main_menu_tab")
815 if fields["btn_all_mods"] then
816 local list = filterlist.get_raw_list(modmgr.modlist)
819 if list[i].typ ~= "game_mod" and
820 not list[i].is_modpack then
821 list[i].enabled = true
830 --------------------------------------------------------------------------------
831 function modmgr.handle_delete_mod_buttons(fields)
832 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
834 if fields["dlg_delete_mod_confirm"] ~= nil then
836 if mod.path ~= nil and
838 mod.path ~= engine.get_modpath() then
839 if not engine.delete_dir(mod.path) then
840 gamedata.errormessage ="Modmgr: failed to delete >" .. mod.path .. "<"
842 modmgr.refresh_globals()
844 gamedata.errormessage ="Modmgr: invalid modpath >" .. mod.path .. "<"
851 current_tab = engine.setting_get("main_menu_tab")
855 --------------------------------------------------------------------------------
856 function modmgr.dialog_delete_mod()
858 local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
861 "field[1.75,1;10,3;;Are you sure you want to delete ".. mod.name .. "?;]"..
862 "button[4,4.2;1,0.5;dlg_delete_mod_confirm;Yes]" ..
863 "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;No of course not!]"
868 --------------------------------------------------------------------------------
869 function modmgr.preparemodlist(data)
872 local global_mods = {}
876 local modpath = engine.get_modpath()
878 if modpath ~= nil and
880 get_mods(modpath,global_mods)
883 for i=1,#global_mods,1 do
884 global_mods[i].typ = "global_mod"
885 table.insert(retval,global_mods[i])
889 if data.gameid ~= nil and
890 data.gameid ~= "" then
891 local gamemodpath = engine.get_gamepath() .. DIR_DELIM .. data.gameid .. DIR_DELIM .. "mods"
893 get_mods(gamemodpath,game_mods)
896 for i=1,#game_mods,1 do
897 game_mods[i].typ = "game_mod"
898 table.insert(retval,game_mods[i])
901 if data.worldpath == nil then
905 --read world mod configuration
906 local filename = data.worldpath ..
907 DIR_DELIM .. "world.mt"
909 local worldfile = io.open(filename,"r")
911 local dependency = worldfile:read("*l")
913 local parts = dependency:split("=")
915 local key = parts[1]:trim()
917 if key ~= "gameid" then
918 local key = parts[1]:trim():sub(10)
921 if retval[i].name == key then
926 if element ~= nil then
927 if parts[2]:trim() == "true" then
928 element.enabled = true
930 element.enabled = false
933 print("Mod: " .. key .. " " .. dump(parts[2]) .. " but not found")
936 dependency = worldfile:read("*l")
945 --------------------------------------------------------------------------------
946 function modmgr.init_worldconfig()
948 local worldspec = engine.get_worlds()[modmgr.world_config_selected_world]
950 if worldspec ~= nil then
952 modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path)
954 if modmgr.worldconfig.id == nil or
955 modmgr.worldconfig.id == "" then
956 modmgr.worldconfig = nil
960 modmgr.modlist = filterlist.create(
961 modmgr.preparemodlist, --refresh
962 modmgr.comparemod, --compare
963 function(element,uid) --uid match
964 if element.name == uid then
968 function(element,criteria)
969 if criteria.hide_game and
970 element.typ == "game_mod" then
974 if criteria.hide_modpackcontents and
975 element.modpack ~= nil then
980 { worldpath= worldspec.path,
981 gameid = worldspec.gameid }
984 filterlist.set_filtercriteria(modmgr.modlist, {
985 hide_game=modmgr.hide_gamemods,
986 hide_modpackcontents= modmgr.hide_modpackcontents
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
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