forked from Mirrorlandia_minetest/minetest
Make ContentDB downloads not block the UI (#9948)
This commit is contained in:
parent
58f523e363
commit
f90ca96c73
@ -46,14 +46,12 @@ local filter_types_type = {
|
|||||||
local function download_package(param)
|
local function download_package(param)
|
||||||
if core.download_file(param.package.url, param.filename) then
|
if core.download_file(param.package.url, param.filename) then
|
||||||
return {
|
return {
|
||||||
package = param.package,
|
|
||||||
filename = param.filename,
|
filename = param.filename,
|
||||||
successful = true,
|
successful = true,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
core.log("error", "downloading " .. dump(param.package.url) .. " failed")
|
core.log("error", "downloading " .. dump(param.package.url) .. " failed")
|
||||||
return {
|
return {
|
||||||
package = param.package,
|
|
||||||
successful = false,
|
successful = false,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -67,9 +65,9 @@ local function start_install(calling_dialog, package)
|
|||||||
|
|
||||||
local function callback(result)
|
local function callback(result)
|
||||||
if result.successful then
|
if result.successful then
|
||||||
local path, msg = pkgmgr.install(result.package.type,
|
local path, msg = pkgmgr.install(package.type,
|
||||||
result.filename, result.package.name,
|
result.filename, package.name,
|
||||||
result.package.path)
|
package.path)
|
||||||
if not path then
|
if not path then
|
||||||
gamedata.errormessage = msg
|
gamedata.errormessage = msg
|
||||||
else
|
else
|
||||||
@ -77,33 +75,33 @@ local function start_install(calling_dialog, package)
|
|||||||
|
|
||||||
local conf_path
|
local conf_path
|
||||||
local name_is_title = false
|
local name_is_title = false
|
||||||
if result.package.type == "mod" then
|
if package.type == "mod" then
|
||||||
local actual_type = pkgmgr.get_folder_type(path)
|
local actual_type = pkgmgr.get_folder_type(path)
|
||||||
if actual_type.type == "modpack" then
|
if actual_type.type == "modpack" then
|
||||||
conf_path = path .. DIR_DELIM .. "modpack.conf"
|
conf_path = path .. DIR_DELIM .. "modpack.conf"
|
||||||
else
|
else
|
||||||
conf_path = path .. DIR_DELIM .. "mod.conf"
|
conf_path = path .. DIR_DELIM .. "mod.conf"
|
||||||
end
|
end
|
||||||
elseif result.package.type == "game" then
|
elseif package.type == "game" then
|
||||||
conf_path = path .. DIR_DELIM .. "game.conf"
|
conf_path = path .. DIR_DELIM .. "game.conf"
|
||||||
name_is_title = true
|
name_is_title = true
|
||||||
elseif result.package.type == "txp" then
|
elseif package.type == "txp" then
|
||||||
conf_path = path .. DIR_DELIM .. "texture_pack.conf"
|
conf_path = path .. DIR_DELIM .. "texture_pack.conf"
|
||||||
end
|
end
|
||||||
|
|
||||||
if conf_path then
|
if conf_path then
|
||||||
local conf = Settings(conf_path)
|
local conf = Settings(conf_path)
|
||||||
if name_is_title then
|
if name_is_title then
|
||||||
conf:set("name", result.package.title)
|
conf:set("name", package.title)
|
||||||
else
|
else
|
||||||
conf:set("title", result.package.title)
|
conf:set("title", package.title)
|
||||||
conf:set("name", result.package.name)
|
conf:set("name", package.name)
|
||||||
end
|
end
|
||||||
if not conf:get("description") then
|
if not conf:get("description") then
|
||||||
conf:set("description", result.package.short_description)
|
conf:set("description", package.short_description)
|
||||||
end
|
end
|
||||||
conf:set("author", result.package.author)
|
conf:set("author", package.author)
|
||||||
conf:set("release", result.package.release)
|
conf:set("release", package.release)
|
||||||
conf:write()
|
conf:write()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -112,37 +110,17 @@ local function start_install(calling_dialog, package)
|
|||||||
gamedata.errormessage = fgettext("Failed to download $1", package.name)
|
gamedata.errormessage = fgettext("Failed to download $1", package.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if gamedata.errormessage == nil then
|
package.downloading = false
|
||||||
core.button_handler({btn_hidden_close_download=result})
|
ui.update()
|
||||||
else
|
|
||||||
core.button_handler({btn_hidden_close_download={successful=false}})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
package.downloading = true
|
||||||
|
|
||||||
if not core.handle_async(download_package, params, callback) then
|
if not core.handle_async(download_package, params, callback) then
|
||||||
core.log("error", "ERROR: async event failed")
|
core.log("error", "ERROR: async event failed")
|
||||||
gamedata.errormessage = fgettext("Failed to download $1", package.name)
|
gamedata.errormessage = fgettext("Failed to download $1", package.name)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local new_dlg = dialog_create("store_downloading",
|
|
||||||
function(data)
|
|
||||||
return "size[7,2]label[0.25,0.75;" ..
|
|
||||||
fgettext("Downloading and installing $1, please wait...", data.title) .. "]"
|
|
||||||
end,
|
|
||||||
function(this,fields)
|
|
||||||
if fields["btn_hidden_close_download"] ~= nil then
|
|
||||||
this:delete()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end,
|
|
||||||
nil)
|
|
||||||
|
|
||||||
new_dlg:set_parent(calling_dialog)
|
|
||||||
new_dlg.data.title = package.title
|
|
||||||
calling_dialog:hide()
|
|
||||||
new_dlg:show()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_screenshot(package)
|
local function get_screenshot(package)
|
||||||
@ -392,9 +370,12 @@ function store.get_formspec(dlgdata)
|
|||||||
minetest.colorize("#BFBFBF", " by " .. package.author))
|
minetest.colorize("#BFBFBF", " by " .. package.author))
|
||||||
formspec[#formspec + 1] = "]"
|
formspec[#formspec + 1] = "]"
|
||||||
|
|
||||||
-- buttons
|
|
||||||
local description_width = 7.5
|
local description_width = 7.5
|
||||||
if not package.path then
|
if package.downloading then
|
||||||
|
formspec[#formspec + 1] = "label[8.4,0.2;"
|
||||||
|
formspec[#formspec + 1] = fgettext("Downloading...")
|
||||||
|
formspec[#formspec + 1] = "]"
|
||||||
|
elseif not package.path then
|
||||||
formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_"
|
formspec[#formspec + 1] = "button[8.4,0;1.5,1;install_"
|
||||||
formspec[#formspec + 1] = tostring(i)
|
formspec[#formspec + 1] = tostring(i)
|
||||||
formspec[#formspec + 1] = ";"
|
formspec[#formspec + 1] = ";"
|
||||||
|
Loading…
Reference in New Issue
Block a user