Load system-wide texture packs too (#10791)

Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com>
This commit is contained in:
Zughy 2021-01-21 19:01:37 +00:00 committed by GitHub
parent 45ccfe26fb
commit 8ff209c412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,6 +72,34 @@ local function cleanup_path(temppath)
return temppath return temppath
end end
local function load_texture_packs(txtpath, retval)
local list = core.get_dir_list(txtpath, true)
local current_texture_path = core.settings:get("texture_path")
for _, item in ipairs(list) do
if item ~= "base" then
local name = item
local path = txtpath .. DIR_DELIM .. item .. DIR_DELIM
if path == current_texture_path then
name = fgettext("$1 (Enabled)", name)
end
local conf = Settings(path .. "texture_pack.conf")
retval[#retval + 1] = {
name = item,
author = conf:get("author"),
release = tonumber(conf:get("release") or "0"),
list_name = name,
type = "txp",
path = path,
enabled = path == current_texture_path,
}
end
end
end
function get_mods(path,retval,modpack) function get_mods(path,retval,modpack)
local mods = core.get_dir_list(path, true) local mods = core.get_dir_list(path, true)
@ -112,7 +140,7 @@ function get_mods(path,retval,modpack)
toadd.type = "mod" toadd.type = "mod"
-- Check modpack.txt -- Check modpack.txt
-- Note: modpack.conf is already checked above -- Note: modpack.conf is already checked above
local modpackfile = io.open(prefix .. DIR_DELIM .. "modpack.txt") local modpackfile = io.open(prefix .. DIR_DELIM .. "modpack.txt")
if modpackfile then if modpackfile then
modpackfile:close() modpackfile:close()
@ -136,32 +164,13 @@ pkgmgr = {}
function pkgmgr.get_texture_packs() function pkgmgr.get_texture_packs()
local txtpath = core.get_texturepath() local txtpath = core.get_texturepath()
local list = core.get_dir_list(txtpath, true) local txtpath_system = core.get_texturepath_share()
local retval = {} local retval = {}
local current_texture_path = core.settings:get("texture_path") load_texture_packs(txtpath, retval)
-- on portable versions these two paths coincide. It avoids loading the path twice
for _, item in ipairs(list) do if txtpath ~= txtpath_system then
if item ~= "base" then load_texture_packs(txtpath_system, retval)
local name = item
local path = txtpath .. DIR_DELIM .. item .. DIR_DELIM
if path == current_texture_path then
name = fgettext("$1 (Enabled)", name)
end
local conf = Settings(path .. "texture_pack.conf")
retval[#retval + 1] = {
name = item,
author = conf:get("author"),
release = tonumber(conf:get("release") or "0"),
list_name = name,
type = "txp",
path = path,
enabled = path == current_texture_path,
}
end
end end
table.sort(retval, function(a, b) table.sort(retval, function(a, b)