X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=builtin%2Fmainmenu%2Fdlg_contentstore.lua;h=ab55e3848783b52e8f4cf5c7dd5b92a9199dc89c;hb=3c7e92049d233053a659e5665b121bea67baa69e;hp=8cd78f4935bda64938676303be9f25c619a50d49;hpb=8ba64e43fe69ecdf31ded0b5aeee625fcc08168a;p=minetest.git diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 8cd78f493..ab55e3848 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -19,7 +19,7 @@ local store = {} local package_dialog = {} -- Screenshot -local screenshot_dir = os.tempfolder() +local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb" assert(core.create_dir(screenshot_dir)) local screenshot_downloading = {} local screenshot_downloaded = {} @@ -76,10 +76,17 @@ local function start_install(calling_dialog, package) if not path then gamedata.errormessage = msg else + core.log("action", "Installed package to " .. path) + local conf_path local name_is_title = false if result.package.type == "mod" then - conf_path = path .. DIR_DELIM .. "mod.conf" + local actual_type = pkgmgr.get_folder_type(path) + if actual_type.type == "modpack" then + conf_path = path .. DIR_DELIM .. "modpack.conf" + else + conf_path = path .. DIR_DELIM .. "mod.conf" + end elseif result.package.type == "game" then conf_path = path .. DIR_DELIM .. "game.conf" name_is_title = true @@ -209,7 +216,7 @@ function package_dialog.get_formspec() local formspec = { "size[9,4;true]", - "image[0,1;4.5,3;", get_screenshot(package), ']', + "image[0,1;4.5,3;", core.formspec_escape(get_screenshot(package)), ']', "label[3.8,1;", minetest.colorize(mt_color_green, core.formspec_escape(package.title)), "\n", minetest.colorize('#BFBFBF', "by " .. core.formspec_escape(package.author)), "]", @@ -222,6 +229,7 @@ function package_dialog.get_formspec() formspec[#formspec + 1] = fgettext("Install") formspec[#formspec + 1] = "]" elseif package.installed_release < package.release then + -- The install_ action also handles updating formspec[#formspec + 1] = "button[7,0;2,1;install;" formspec[#formspec + 1] = fgettext("Update") formspec[#formspec + 1] = "]" @@ -268,42 +276,78 @@ function package_dialog.create(package) end function store.load() - store.packages_full = core.get_package_list() - store.packages = store.packages_full - store.loaded = true + local tmpdir = os.tempfolder() + local target = tmpdir .. DIR_DELIM .. "packages.json" + + assert(core.create_dir(tmpdir)) + + local base_url = core.settings:get("contentdb_url") + local show_nonfree = core.settings:get_bool("show_nonfree_packages") + local url = base_url .. + "/api/packages/?type=mod&type=game&type=txp&protocol_version=" .. + core.get_max_supp_proto() .. + "&nonfree=" .. + (show_nonfree and "true" or "false") + + core.download_file(url, target) + + local file = io.open(target, "r") + if file then + store.packages_full = core.parse_json(file:read("*all")) or {} + file:close() + + for _, package in pairs(store.packages_full) do + package.url = base_url .. "/packages/" .. + package.author .. "/" .. package.name .. + "/releases/" .. package.release .. "/download/" + + package.id = package.author .. "/" .. package.name + end + + store.packages = store.packages_full + store.loaded = true + end + + core.delete_dir(tmpdir) end function store.update_paths() local mod_hash = {} pkgmgr.refresh_globals() for _, mod in pairs(pkgmgr.global_mods:get_list()) do - mod_hash[mod.name] = mod + if mod.author then + mod_hash[mod.author .. "/" .. mod.name] = mod + end end local game_hash = {} pkgmgr.update_gamelist() for _, game in pairs(pkgmgr.games) do - game_hash[game.id] = game + if game.author then + game_hash[game.author .. "/" .. game.id] = game + end end local txp_hash = {} for _, txp in pairs(pkgmgr.get_texture_packs()) do - txp_hash[txp.name] = txp + if txp.author then + txp_hash[txp.author .. "/" .. txp.name] = txp + end end for _, package in pairs(store.packages_full) do local content if package.type == "mod" then - content = mod_hash[package.name] + content = mod_hash[package.id] elseif package.type == "game" then - content = game_hash[package.name] + content = game_hash[package.id] elseif package.type == "txp" then - content = txp_hash[package.name] + content = txp_hash[package.id] end - if content and content.author == package.author then + if content then package.path = content.path - package.installed_release = content.release + package.installed_release = content.release or 0 else package.path = nil end @@ -357,7 +401,7 @@ function store.get_formspec() end local formspec - if #store.packages > 0 then + if #store.packages_full > 0 then formspec = { "size[12,7;true]", "position[0.5,0.55]", @@ -386,11 +430,17 @@ function store.get_formspec() "button[11.1,0;1,1;pend;>>]", "container_end[]", } + + if #store.packages == 0 then + formspec[#formspec + 1] = "label[4,3;" + formspec[#formspec + 1] = fgettext("No results") + formspec[#formspec + 1] = "]" + end else formspec = { "size[12,7;true]", "position[0.5,0.55]", - "label[4,3;No packages could be retrieved]", + "label[4,3;", fgettext("No packages could be retrieved"), "]", "button[-0.1,", num_per_page + 1.5, ";3,1;back;", @@ -418,35 +468,43 @@ function store.get_formspec() formspec[#formspec + 1] = "]" -- description - formspec[#formspec + 1] = "textarea[1.25,0.3;7.5,1;;;" + if package.path and package.installed_release < package.release then + formspec[#formspec + 1] = "textarea[1.25,0.3;7.5,1;;;" + else + formspec[#formspec + 1] = "textarea[1.25,0.3;9,1;;;" + end formspec[#formspec + 1] = core.formspec_escape(package.short_description) formspec[#formspec + 1] = "]" -- buttons if not package.path then - formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_" + formspec[#formspec + 1] = "button[9.9,0;1.5,1;install_" formspec[#formspec + 1] = tostring(i) formspec[#formspec + 1] = ";" formspec[#formspec + 1] = fgettext("Install") formspec[#formspec + 1] = "]" - elseif package.installed_release < package.release then - formspec[#formspec + 1] = "button[8.4,0;1.5,1;update_" - formspec[#formspec + 1] = tostring(i) - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = fgettext("Update") - formspec[#formspec + 1] = "]" else - formspec[#formspec + 1] = "button[8.4,0;1.5,1;uninstall_" + if package.installed_release < package.release then + -- The install_ action also handles updating + formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_" + formspec[#formspec + 1] = tostring(i) + formspec[#formspec + 1] = ";" + formspec[#formspec + 1] = fgettext("Update") + formspec[#formspec + 1] = "]" + end + + formspec[#formspec + 1] = "button[9.9,0;1.5,1;uninstall_" formspec[#formspec + 1] = tostring(i) formspec[#formspec + 1] = ";" formspec[#formspec + 1] = fgettext("Uninstall") formspec[#formspec + 1] = "]" end - formspec[#formspec + 1] = "button[9.9,0;1.5,1;view_" - formspec[#formspec + 1] = tostring(i) - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = fgettext("View") - formspec[#formspec + 1] = "]" + + --formspec[#formspec + 1] = "button[9.9,0;1.5,1;view_" + --formspec[#formspec + 1] = tostring(i) + --formspec[#formspec + 1] = ";" + --formspec[#formspec + 1] = fgettext("View") + --formspec[#formspec + 1] = "]" formspec[#formspec + 1] = "container_end[]" end @@ -542,7 +600,7 @@ function store.handle_submit(this, fields, tabname, tabdata) end function create_store_dlg(type) - if not store.loaded then + if not store.loaded or #store.packages_full == 0 then store.load() end