aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu/dlg_contentstore.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-09-19 20:56:13 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-09-19 20:56:13 +0200
commitc8900e169a1ddceec07a449f1ae7c4322ff02036 (patch)
tree5156605fb473d25786426eb6876ba2e7d3b7507b /builtin/mainmenu/dlg_contentstore.lua
parent950d2c9b3e10cbace9236e820c8119d1abb9e01f (diff)
parente0529da5c84f224c380e6d5e063392cb01f85683 (diff)
downloaddragonfireclient-c8900e169a1ddceec07a449f1ae7c4322ff02036.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'builtin/mainmenu/dlg_contentstore.lua')
-rw-r--r--builtin/mainmenu/dlg_contentstore.lua61
1 files changed, 43 insertions, 18 deletions
diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua
index 20a446d5d..790da03ba 100644
--- a/builtin/mainmenu/dlg_contentstore.lua
+++ b/builtin/mainmenu/dlg_contentstore.lua
@@ -57,24 +57,39 @@ local filter_types_type = {
"txp",
}
+local REASON_NEW = "new"
+local REASON_UPDATE = "update"
+local REASON_DEPENDENCY = "dependency"
+
+
+local function get_download_url(package, reason)
+ local base_url = core.settings:get("contentdb_url")
+ local ret = base_url .. ("/packages/%s/%s/releases/%d/download/"):format(package.author, package.name, package.release)
+ if reason then
+ ret = ret .. "?reason=" .. reason
+ end
+ return ret
+end
+
local function download_package(param)
- if core.download_file(param.package.url, param.filename) then
+ if core.download_file(param.url, param.filename) then
return {
filename = param.filename,
successful = true,
}
else
- core.log("error", "downloading " .. dump(param.package.url) .. " failed")
+ core.log("error", "downloading " .. dump(param.url) .. " failed")
return {
successful = false,
}
end
end
-local function start_install(package)
+local function start_install(package, reason)
local params = {
package = package,
+ url = get_download_url(package, reason),
filename = os.tempfolder() .. "_MODNAME_" .. package.name .. ".zip",
}
@@ -135,7 +150,7 @@ local function start_install(package)
if next then
table.remove(download_queue, 1)
- start_install(next)
+ start_install(next.package, next.reason)
end
ui.update()
@@ -151,12 +166,12 @@ local function start_install(package)
end
end
-local function queue_download(package)
+local function queue_download(package, reason)
local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads"))
if number_downloading < max_concurrent_downloads then
- start_install(package)
+ start_install(package, reason)
else
- table.insert(download_queue, package)
+ table.insert(download_queue, { package = package, reason = reason })
package.queued = true
end
end
@@ -407,12 +422,12 @@ function install_dialog.handle_submit(this, fields)
end
if fields.install_all then
- queue_download(install_dialog.package)
+ queue_download(install_dialog.package, REASON_NEW)
if install_dialog.will_install_deps then
for _, dep in pairs(install_dialog.dependencies) do
if not dep.is_optional and not dep.installed and dep.package then
- queue_download(dep.package)
+ queue_download(dep.package, REASON_DEPENDENCY)
end
end
end
@@ -560,18 +575,25 @@ function store.load()
end
store.packages_full = core.parse_json(response.data) or {}
+ store.aliases = {}
for _, package in pairs(store.packages_full) do
- package.url = base_url .. "/packages/" ..
- package.author .. "/" .. package.name ..
- "/releases/" .. package.release .. "/download/"
-
local name_len = #package.name
if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then
package.id = package.author:lower() .. "/" .. package.name:sub(1, name_len - 5)
else
package.id = package.author:lower() .. "/" .. package.name
end
+
+ if package.aliases then
+ for _, alias in ipairs(package.aliases) do
+ -- We currently don't support name changing
+ local suffix = "/" .. package.name
+ if alias:sub(-#suffix) == suffix then
+ store.aliases[alias:lower()] = package.id
+ end
+ end
+ end
end
store.packages_full_unordered = store.packages_full
@@ -584,7 +606,8 @@ function store.update_paths()
pkgmgr.refresh_globals()
for _, mod in pairs(pkgmgr.clientmods:get_list()) do
if mod.author and mod.release > 0 then
- mod_hash[mod.author:lower() .. "/" .. mod.name] = mod
+ local id = mod.author:lower() .. "/" .. mod.name
+ mod_hash[store.aliases[id] or id] = mod
end
end
@@ -592,14 +615,16 @@ function store.update_paths()
pkgmgr.update_gamelist()
for _, game in pairs(pkgmgr.games) do
if game.author ~= "" and game.release > 0 then
- game_hash[game.author:lower() .. "/" .. game.id] = game
+ local id = game.author:lower() .. "/" .. game.id
+ game_hash[store.aliases[id] or id] = game
end
end
local txp_hash = {}
for _, txp in pairs(pkgmgr.get_texture_packs()) do
if txp.author and txp.release > 0 then
- txp_hash[txp.author:lower() .. "/" .. txp.name] = txp
+ local id = txp.author:lower() .. "/" .. txp.name
+ txp_hash[store.aliases[id] or id] = txp
end
end
@@ -915,7 +940,7 @@ function store.handle_submit(this, fields)
local package = store.packages_full[i]
if package.path and package.installed_release < package.release and
not (package.downloading or package.queued) then
- queue_download(package)
+ queue_download(package, REASON_UPDATE)
end
end
return true
@@ -948,7 +973,7 @@ function store.handle_submit(this, fields)
this:hide()
dlg:show()
else
- queue_download(package)
+ queue_download(package, package.path and REASON_UPDATE or REASON_NEW)
end
end