From adec16790b80ccc844571ff0d0c5ce7908d8405b Mon Sep 17 00:00:00 2001 From: Gregor Parzefall <82708541+grorp@users.noreply.github.com> Date: Sun, 5 Nov 2023 19:01:19 +0100 Subject: [PATCH] Offer ContentDB updates for leftover bundled Minetest Game (#13906) --- builtin/mainmenu/content/dlg_contentstore.lua | 25 +++++++++---------- builtin/mainmenu/content/pkgmgr.lua | 24 ++++++++++++++++++ builtin/mainmenu/content/update_detector.lua | 17 +++++-------- builtin/mainmenu/dlg_reinstall_mtg.lua | 2 +- builtin/mainmenu/tab_content.lua | 2 +- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/builtin/mainmenu/content/dlg_contentstore.lua b/builtin/mainmenu/content/dlg_contentstore.lua index 4f1400206b8e..92ab8319fcc8 100644 --- a/builtin/mainmenu/content/dlg_contentstore.lua +++ b/builtin/mainmenu/content/dlg_contentstore.lua @@ -698,9 +698,7 @@ local function resolve_auto_install_spec() local resolved = nil for _, pkg in ipairs(store.packages_full_unordered) do - if pkg.author == auto_install_spec.author and - (pkg.name == auto_install_spec.name or - (pkg.type == "game" and pkg.name == auto_install_spec.name .. "_game")) then + if pkg.id == auto_install_spec then resolved = pkg break end @@ -777,26 +775,26 @@ function store.update_paths() local mod_hash = {} pkgmgr.refresh_globals() for _, mod in pairs(pkgmgr.global_mods:get_list()) do - if mod.author and mod.release > 0 then - local id = mod.author:lower() .. "/" .. mod.name - mod_hash[store.aliases[id] or id] = mod + local cdb_id = pkgmgr.get_contentdb_id(mod) + if cdb_id then + mod_hash[store.aliases[cdb_id] or cdb_id] = mod end end local game_hash = {} pkgmgr.update_gamelist() for _, game in pairs(pkgmgr.games) do - if game.author ~= "" and game.release > 0 then - local id = game.author:lower() .. "/" .. game.id - game_hash[store.aliases[id] or id] = game + local cdb_id = pkgmgr.get_contentdb_id(game) + if cdb_id then + game_hash[store.aliases[cdb_id] or cdb_id] = game end end local txp_hash = {} for _, txp in pairs(pkgmgr.get_texture_packs()) do - if txp.author and txp.release > 0 then - local id = txp.author:lower() .. "/" .. txp.name - txp_hash[store.aliases[id] or id] = txp + local cdb_id = pkgmgr.get_contentdb_id(txp) + if cdb_id then + txp_hash[store.aliases[cdb_id] or cdb_id] = txp end end @@ -815,6 +813,7 @@ function store.update_paths() package.installed_release = content.release or 0 else package.path = nil + package.installed_release = nil end end end @@ -1193,7 +1192,7 @@ end --- @param type string | nil --- Sets initial package filter. "game", "mod", "txp" or nil (no filter). --- @param install_spec table | nil ---- Package specification of the form { author = string, name = string }. +--- ContentDB ID of package as returned by pkgmgr.get_contentdb_id(). --- Sets package to install or update automatically. function create_store_dlg(type, install_spec) search_string = "" diff --git a/builtin/mainmenu/content/pkgmgr.lua b/builtin/mainmenu/content/pkgmgr.lua index 687812a5daf2..9408eb994ef2 100644 --- a/builtin/mainmenu/content/pkgmgr.lua +++ b/builtin/mainmenu/content/pkgmgr.lua @@ -777,6 +777,30 @@ function pkgmgr.update_gamelist() end) end +-------------------------------------------------------------------------------- +-- Returns the ContentDB ID for an installed piece of content. +function pkgmgr.get_contentdb_id(content) + -- core.get_games() will return "" instead of nil if there is no "author" field. + if content.author and content.author ~= "" and content.release > 0 then + if content.type == "game" then + return content.author:lower() .. "/" .. content.id + end + return content.author:lower() .. "/" .. content.name + end + + -- Until Minetest 5.8.0, Minetest Game was bundled with Minetest. + -- Unfortunately, the bundled MTG was not versioned (missing "release" + -- field in game.conf). + -- Therefore, we consider any installation of MTG that is not versioned, + -- has not been cloned from Git, and is not system-wide to be updatable. + if content.type == "game" and content.id == "minetest" and content.release == 0 and + not core.is_dir(content.path .. "/.git") and core.may_modify_path(content.path) then + return "minetest/minetest" + end + + return nil +end + -------------------------------------------------------------------------------- -- read initial data -------------------------------------------------------------------------------- diff --git a/builtin/mainmenu/content/update_detector.lua b/builtin/mainmenu/content/update_detector.lua index 532966fd009e..d184272e418d 100644 --- a/builtin/mainmenu/content/update_detector.lua +++ b/builtin/mainmenu/content/update_detector.lua @@ -59,7 +59,7 @@ local function has_packages_from_cdb() pkgmgr.update_gamelist() for _, content in pairs(pkgmgr.get_all()) do - if content.author and content.release > 0 then + if pkgmgr.get_contentdb_id(content) then return true end end @@ -114,18 +114,13 @@ function update_detector.get_all() local ret = {} local all_content = pkgmgr.get_all() for _, content in ipairs(all_content) do - if content.author and content.release > 0 then - -- The backend will account for aliases in `latest_releases` - local id = content.author:lower() .. "/" - if content.type == "game" then - id = id .. content.id - else - id = id .. content.name - end + local cdb_id = pkgmgr.get_contentdb_id(content) - local latest_release = latest_releases[id] + if cdb_id then + -- The backend will account for aliases in `latest_releases` + local latest_release = latest_releases[cdb_id] if not latest_release and content.type == "game" then - latest_release = latest_releases[id .. "_game"] + latest_release = latest_releases[cdb_id .. "_game"] end if latest_release and latest_release > content.release then diff --git a/builtin/mainmenu/dlg_reinstall_mtg.lua b/builtin/mainmenu/dlg_reinstall_mtg.lua index 87d494a90064..77652e968eaa 100644 --- a/builtin/mainmenu/dlg_reinstall_mtg.lua +++ b/builtin/mainmenu/dlg_reinstall_mtg.lua @@ -78,7 +78,7 @@ local function buttonhandler(this, fields) local maintab = ui.find_by_name("maintab") - local dlg = create_store_dlg(nil, { author = "Minetest", name = "minetest_game" }) + local dlg = create_store_dlg(nil, "minetest/minetest") dlg:set_parent(maintab) maintab:hide() dlg:show() diff --git a/builtin/mainmenu/tab_content.lua b/builtin/mainmenu/tab_content.lua index 83e2b1082adb..abe127a69349 100644 --- a/builtin/mainmenu/tab_content.lua +++ b/builtin/mainmenu/tab_content.lua @@ -254,7 +254,7 @@ local function handle_buttons(tabview, fields, tabname, tabdata) if fields.btn_mod_mgr_update then local pkg = packages:get_list()[tabdata.selected_pkg] - local dlg = create_store_dlg(nil, { author = pkg.author, name = pkg.id or pkg.name }) + local dlg = create_store_dlg(nil, pkgmgr.get_contentdb_id(pkg)) dlg:set_parent(tabview) tabview:hide() dlg:show()