mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Fix unnecessary content refreshing (#14705)
This commit is contained in:
parent
9ab447843b
commit
157d129e30
9 changed files with 193 additions and 181 deletions
|
@ -133,6 +133,8 @@ local function start_install(package, reason)
|
|||
conf:set("release", package.release)
|
||||
conf:write()
|
||||
end
|
||||
|
||||
pkgmgr.reload_by_type(package.type)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,7 +148,6 @@ local function start_install(package, reason)
|
|||
|
||||
start_install(next.package, next.reason)
|
||||
end
|
||||
|
||||
ui.update()
|
||||
end
|
||||
|
||||
|
@ -427,8 +428,9 @@ end
|
|||
|
||||
|
||||
function contentdb.update_paths()
|
||||
pkgmgr.load_all()
|
||||
|
||||
local mod_hash = {}
|
||||
pkgmgr.refresh_globals()
|
||||
for _, mod in pairs(pkgmgr.global_mods:get_list()) do
|
||||
local cdb_id = pkgmgr.get_contentdb_id(mod)
|
||||
if cdb_id then
|
||||
|
@ -437,7 +439,6 @@ function contentdb.update_paths()
|
|||
end
|
||||
|
||||
local game_hash = {}
|
||||
pkgmgr.update_gamelist()
|
||||
for _, game in pairs(pkgmgr.games) do
|
||||
local cdb_id = pkgmgr.get_contentdb_id(game)
|
||||
if cdb_id then
|
||||
|
@ -446,7 +447,7 @@ function contentdb.update_paths()
|
|||
end
|
||||
|
||||
local txp_hash = {}
|
||||
for _, txp in pairs(pkgmgr.get_texture_packs()) do
|
||||
for _, txp in pairs(pkgmgr.texture_packs) do
|
||||
local cdb_id = pkgmgr.get_contentdb_id(txp)
|
||||
if cdb_id then
|
||||
txp_hash[contentdb.aliases[cdb_id] or cdb_id] = txp
|
||||
|
|
|
@ -110,7 +110,7 @@ pkgmgr = {}
|
|||
-- @param modpack Currently processing modpack or nil/"" if none (recursion)
|
||||
function pkgmgr.get_mods(path, virtual_path, listing, modpack)
|
||||
local mods = core.get_dir_list(path, true)
|
||||
|
||||
local added = {}
|
||||
for _, name in ipairs(mods) do
|
||||
if name:sub(1, 1) ~= "." then
|
||||
local mod_path = path .. DIR_DELIM .. name
|
||||
|
@ -120,6 +120,7 @@ function pkgmgr.get_mods(path, virtual_path, listing, modpack)
|
|||
parent_dir = path,
|
||||
}
|
||||
listing[#listing + 1] = toadd
|
||||
added[#added + 1] = toadd
|
||||
|
||||
-- Get config file
|
||||
local mod_conf
|
||||
|
@ -150,8 +151,6 @@ function pkgmgr.get_mods(path, virtual_path, listing, modpack)
|
|||
toadd.virtual_path = mod_virtual_path
|
||||
toadd.type = "mod"
|
||||
|
||||
pkgmgr.update_translations({ toadd })
|
||||
|
||||
-- Check modpack.txt
|
||||
-- Note: modpack.conf is already checked above
|
||||
local modpackfile = io.open(mod_path .. DIR_DELIM .. "modpack.txt")
|
||||
|
@ -171,6 +170,8 @@ function pkgmgr.get_mods(path, virtual_path, listing, modpack)
|
|||
end
|
||||
end
|
||||
|
||||
pkgmgr.update_translations(added)
|
||||
|
||||
if not modpack then
|
||||
-- Sort all when the recursion is done
|
||||
table.sort(listing, function(a, b)
|
||||
|
@ -180,12 +181,13 @@ function pkgmgr.get_mods(path, virtual_path, listing, modpack)
|
|||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.get_texture_packs()
|
||||
function pkgmgr.reload_texture_packs()
|
||||
local txtpath = core.get_texturepath()
|
||||
local txtpath_system = core.get_texturepath_share()
|
||||
local retval = {}
|
||||
|
||||
load_texture_packs(txtpath, retval)
|
||||
|
||||
-- on portable versions these two paths coincide. It avoids loading the path twice
|
||||
if txtpath ~= txtpath_system then
|
||||
load_texture_packs(txtpath_system, retval)
|
||||
|
@ -197,11 +199,13 @@ function pkgmgr.get_texture_packs()
|
|||
return a.title:lower() < b.title:lower()
|
||||
end)
|
||||
|
||||
return retval
|
||||
pkgmgr.texture_packs = retval
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.get_all()
|
||||
pkgmgr.load_all()
|
||||
|
||||
local result = {}
|
||||
|
||||
for _, mod in pairs(pkgmgr.global_mods:get_list()) do
|
||||
|
@ -210,7 +214,7 @@ function pkgmgr.get_all()
|
|||
for _, game in pairs(pkgmgr.games) do
|
||||
result[#result + 1] = game
|
||||
end
|
||||
for _, txp in pairs(pkgmgr.get_texture_packs()) do
|
||||
for _, txp in pairs(pkgmgr.texture_packs) do
|
||||
result[#result + 1] = txp
|
||||
end
|
||||
|
||||
|
@ -288,7 +292,7 @@ end
|
|||
function pkgmgr.render_packagelist(render_list, use_technical_names, with_icon)
|
||||
if not render_list then
|
||||
if not pkgmgr.global_mods then
|
||||
pkgmgr.refresh_globals()
|
||||
pkgmgr.reload_global_mods()
|
||||
end
|
||||
render_list = pkgmgr.global_mods
|
||||
end
|
||||
|
@ -549,6 +553,7 @@ function pkgmgr.get_worldconfig(worldpath)
|
|||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Caller is responsible for reloading content types (see reload_by_type)
|
||||
function pkgmgr.install_dir(expected_type, path, basename, targetpath)
|
||||
assert(type(expected_type) == "string")
|
||||
assert(type(path) == "string")
|
||||
|
@ -615,12 +620,6 @@ function pkgmgr.install_dir(expected_type, path, basename, targetpath)
|
|||
fgettext_ne("Failed to install $1 to $2", basename, targetpath)
|
||||
end
|
||||
|
||||
if basefolder.type == "game" then
|
||||
pkgmgr.update_gamelist()
|
||||
else
|
||||
pkgmgr.refresh_globals()
|
||||
end
|
||||
|
||||
return targetpath, nil
|
||||
end
|
||||
|
||||
|
@ -742,7 +741,7 @@ function pkgmgr.comparemod(elem1,elem2)
|
|||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.refresh_globals()
|
||||
function pkgmgr.reload_global_mods()
|
||||
local function is_equal(element,uid) --uid match
|
||||
if element.name == uid then
|
||||
return true
|
||||
|
@ -774,7 +773,7 @@ function pkgmgr.get_game_mods(gamespec, retval)
|
|||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.update_gamelist()
|
||||
function pkgmgr.reload_games()
|
||||
pkgmgr.games = core.get_games()
|
||||
table.sort(pkgmgr.games, function(a, b)
|
||||
return a.title:lower() < b.title:lower()
|
||||
|
@ -782,6 +781,32 @@ function pkgmgr.update_gamelist()
|
|||
pkgmgr.update_translations(pkgmgr.games)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.reload_by_type(type)
|
||||
if type == "game" then
|
||||
pkgmgr.reload_games()
|
||||
elseif type == "txp" then
|
||||
pkgmgr.reload_texture_packs()
|
||||
elseif type == "mod" or type == "modpack" then
|
||||
pkgmgr.reload_global_mods()
|
||||
else
|
||||
error("Unknown package type: " .. type)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.load_all()
|
||||
if not pkgmgr.global_mods then
|
||||
pkgmgr.reload_global_mods()
|
||||
end
|
||||
if not pkgmgr.games then
|
||||
pkgmgr.reload_games()
|
||||
end
|
||||
if not pkgmgr.texture_packs then
|
||||
pkgmgr.reload_texture_packs()
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function pkgmgr.update_translations(list)
|
||||
for _, item in ipairs(list) do
|
||||
|
@ -831,4 +856,4 @@ end
|
|||
--------------------------------------------------------------------------------
|
||||
-- read initial data
|
||||
--------------------------------------------------------------------------------
|
||||
pkgmgr.update_gamelist()
|
||||
pkgmgr.reload_games()
|
||||
|
|
|
@ -46,6 +46,9 @@ local function reset()
|
|||
function core.get_texturepath()
|
||||
return txp_dir
|
||||
end
|
||||
function core.get_texturepath_share()
|
||||
return txp_dir
|
||||
end
|
||||
function core.get_modpath()
|
||||
return mods_dir
|
||||
end
|
||||
|
@ -59,13 +62,6 @@ local function reset()
|
|||
setfenv(loadfile("builtin/common/misc_helpers.lua"), env)()
|
||||
setfenv(loadfile("builtin/mainmenu/content/pkgmgr.lua"), env)()
|
||||
|
||||
function env.pkgmgr.update_gamelist()
|
||||
table.insert(calls, { "update_gamelist" })
|
||||
end
|
||||
function env.pkgmgr.refresh_globals()
|
||||
table.insert(calls, { "refresh_globals" })
|
||||
end
|
||||
|
||||
function env.assert_calls(list)
|
||||
assert.are.same(list, calls)
|
||||
end
|
||||
|
@ -113,7 +109,6 @@ describe("install_dir", function()
|
|||
env.assert_calls({
|
||||
{ "delete_dir", mods_dir .. "/mymod" },
|
||||
{ "copy_dir", "/tmp/123", mods_dir .. "/mymod", false },
|
||||
{ "refresh_globals" },
|
||||
})
|
||||
end)
|
||||
|
||||
|
@ -129,7 +124,6 @@ describe("install_dir", function()
|
|||
env.assert_calls({
|
||||
{ "delete_dir", mods_dir .. "/mymod" },
|
||||
{ "copy_dir", "/tmp/123", mods_dir .. "/mymod", false },
|
||||
{ "refresh_globals" },
|
||||
})
|
||||
end)
|
||||
|
||||
|
@ -145,7 +139,6 @@ describe("install_dir", function()
|
|||
env.assert_calls({
|
||||
{ "delete_dir", games_dir .. "/mygame" },
|
||||
{ "copy_dir", "/tmp/123", games_dir .. "/mygame", false },
|
||||
{ "update_gamelist" },
|
||||
})
|
||||
end)
|
||||
|
||||
|
@ -161,7 +154,6 @@ describe("install_dir", function()
|
|||
env.assert_calls({
|
||||
{ "delete_dir", mods_dir .. "/123" },
|
||||
{ "copy_dir", "/tmp/123", mods_dir .. "/123", false },
|
||||
{ "refresh_globals" },
|
||||
})
|
||||
end)
|
||||
|
||||
|
@ -188,7 +180,6 @@ describe("install_dir", function()
|
|||
env.assert_calls({
|
||||
{ "delete_dir", "/tmp/alt-target" },
|
||||
{ "copy_dir", "/tmp/123", "/tmp/alt-target", false },
|
||||
{ "refresh_globals" },
|
||||
})
|
||||
end)
|
||||
|
||||
|
@ -238,6 +229,5 @@ describe("install_dir", function()
|
|||
path, message = env.pkgmgr.install_dir("txp", "/tmp/123", "name", nil)
|
||||
assert.is._not._nil(path)
|
||||
assert.is._nil(message)
|
||||
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -72,9 +72,6 @@ end
|
|||
|
||||
|
||||
local function has_packages_from_cdb()
|
||||
pkgmgr.refresh_globals()
|
||||
pkgmgr.update_gamelist()
|
||||
|
||||
for _, content in pairs(pkgmgr.get_all()) do
|
||||
if pkgmgr.get_contentdb_id(content) then
|
||||
return true
|
||||
|
@ -127,9 +124,6 @@ function update_detector.get_all()
|
|||
return {}
|
||||
end
|
||||
|
||||
pkgmgr.refresh_globals()
|
||||
pkgmgr.update_gamelist()
|
||||
|
||||
local ret = {}
|
||||
local all_content = pkgmgr.get_all()
|
||||
for _, content in ipairs(all_content) do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue