2018-04-17 15:54:50 +02:00
|
|
|
--Minetest
|
2020-06-06 18:17:08 +02:00
|
|
|
--Copyright (C) 2018-20 rubenwardy
|
2018-04-17 15:54:50 +02:00
|
|
|
--
|
|
|
|
--This program is free software; you can redistribute it and/or modify
|
|
|
|
--it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
--the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
--(at your option) any later version.
|
|
|
|
--
|
|
|
|
--This program is distributed in the hope that it will be useful,
|
|
|
|
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
--GNU Lesser General Public License for more details.
|
|
|
|
--
|
|
|
|
--You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
if not minetest.get_http_api then
|
|
|
|
function create_store_dlg()
|
|
|
|
return messagebox("store",
|
|
|
|
fgettext("ContentDB is not available when Minetest was compiled without cURL"))
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-02-03 20:54:43 +01:00
|
|
|
local store = { packages = {}, packages_full = {} }
|
2018-05-16 22:52:12 +02:00
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
local http = minetest.get_http_api()
|
|
|
|
|
2018-05-20 01:25:17 +02:00
|
|
|
-- Screenshot
|
2019-01-31 17:35:55 +01:00
|
|
|
local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb"
|
2018-05-20 01:25:17 +02:00
|
|
|
assert(core.create_dir(screenshot_dir))
|
|
|
|
local screenshot_downloading = {}
|
|
|
|
local screenshot_downloaded = {}
|
|
|
|
|
|
|
|
-- Filter
|
2018-05-16 22:52:12 +02:00
|
|
|
local search_string = ""
|
|
|
|
local cur_page = 1
|
|
|
|
local num_per_page = 5
|
|
|
|
local filter_type = 1
|
|
|
|
local filter_types_titles = {
|
|
|
|
fgettext("All packages"),
|
|
|
|
fgettext("Games"),
|
|
|
|
fgettext("Mods"),
|
|
|
|
fgettext("Texture packs"),
|
|
|
|
}
|
|
|
|
|
|
|
|
local filter_types_type = {
|
|
|
|
nil,
|
|
|
|
"game",
|
|
|
|
"mod",
|
|
|
|
"txp",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
local function download_package(param)
|
|
|
|
if core.download_file(param.package.url, param.filename) then
|
|
|
|
return {
|
|
|
|
filename = param.filename,
|
|
|
|
successful = true,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
core.log("error", "downloading " .. dump(param.package.url) .. " failed")
|
|
|
|
return {
|
|
|
|
successful = false,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function start_install(calling_dialog, package)
|
|
|
|
local params = {
|
|
|
|
package = package,
|
|
|
|
filename = os.tempfolder() .. "_MODNAME_" .. package.name .. ".zip",
|
|
|
|
}
|
|
|
|
|
|
|
|
local function callback(result)
|
|
|
|
if result.successful then
|
2020-05-27 18:02:09 +02:00
|
|
|
local path, msg = pkgmgr.install(package.type,
|
|
|
|
result.filename, package.name,
|
|
|
|
package.path)
|
2018-04-17 15:54:50 +02:00
|
|
|
if not path then
|
|
|
|
gamedata.errormessage = msg
|
|
|
|
else
|
2019-01-06 10:23:35 +01:00
|
|
|
core.log("action", "Installed package to " .. path)
|
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
local conf_path
|
|
|
|
local name_is_title = false
|
2020-05-27 18:02:09 +02:00
|
|
|
if package.type == "mod" then
|
2019-01-06 10:23:35 +01:00
|
|
|
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
|
2020-05-27 18:02:09 +02:00
|
|
|
elseif package.type == "game" then
|
2018-04-17 15:54:50 +02:00
|
|
|
conf_path = path .. DIR_DELIM .. "game.conf"
|
|
|
|
name_is_title = true
|
2020-05-27 18:02:09 +02:00
|
|
|
elseif package.type == "txp" then
|
2018-04-17 15:54:50 +02:00
|
|
|
conf_path = path .. DIR_DELIM .. "texture_pack.conf"
|
|
|
|
end
|
|
|
|
|
|
|
|
if conf_path then
|
|
|
|
local conf = Settings(conf_path)
|
|
|
|
if name_is_title then
|
2020-05-27 18:02:09 +02:00
|
|
|
conf:set("name", package.title)
|
2018-04-17 15:54:50 +02:00
|
|
|
else
|
2020-05-27 18:02:09 +02:00
|
|
|
conf:set("title", package.title)
|
|
|
|
conf:set("name", package.name)
|
2019-06-10 19:49:00 +02:00
|
|
|
end
|
|
|
|
if not conf:get("description") then
|
2020-05-27 18:02:09 +02:00
|
|
|
conf:set("description", package.short_description)
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
2020-05-27 18:02:09 +02:00
|
|
|
conf:set("author", package.author)
|
|
|
|
conf:set("release", package.release)
|
2018-04-17 15:54:50 +02:00
|
|
|
conf:write()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
os.remove(result.filename)
|
|
|
|
else
|
|
|
|
gamedata.errormessage = fgettext("Failed to download $1", package.name)
|
|
|
|
end
|
|
|
|
|
2020-05-27 18:02:09 +02:00
|
|
|
package.downloading = false
|
|
|
|
ui.update()
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
|
2020-05-27 18:02:09 +02:00
|
|
|
package.downloading = true
|
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
if not core.handle_async(download_package, params, callback) then
|
2018-05-16 22:52:12 +02:00
|
|
|
core.log("error", "ERROR: async event failed")
|
2018-04-17 15:54:50 +02:00
|
|
|
gamedata.errormessage = fgettext("Failed to download $1", package.name)
|
2020-05-27 18:02:09 +02:00
|
|
|
return
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-06 18:59:39 +02:00
|
|
|
local function get_file_extension(path)
|
|
|
|
local parts = path:split(".")
|
|
|
|
return parts[#parts]
|
|
|
|
end
|
|
|
|
|
2018-05-20 01:25:17 +02:00
|
|
|
local function get_screenshot(package)
|
2018-06-18 21:47:38 +02:00
|
|
|
if not package.thumbnail then
|
2018-05-20 01:25:17 +02:00
|
|
|
return defaulttexturedir .. "no_screenshot.png"
|
2018-06-18 21:47:38 +02:00
|
|
|
elseif screenshot_downloading[package.thumbnail] then
|
2018-05-20 01:25:17 +02:00
|
|
|
return defaulttexturedir .. "loading_screenshot.png"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Get tmp screenshot path
|
2020-06-06 18:59:39 +02:00
|
|
|
local ext = get_file_extension(package.thumbnail)
|
2018-05-20 01:25:17 +02:00
|
|
|
local filepath = screenshot_dir .. DIR_DELIM ..
|
2020-06-06 18:59:39 +02:00
|
|
|
("%s-%s-%s.%s"):format(package.type, package.author, package.name, ext)
|
2018-05-20 01:25:17 +02:00
|
|
|
|
|
|
|
-- Return if already downloaded
|
|
|
|
local file = io.open(filepath, "r")
|
|
|
|
if file then
|
|
|
|
file:close()
|
|
|
|
return filepath
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Show error if we've failed to download before
|
2018-06-18 21:47:38 +02:00
|
|
|
if screenshot_downloaded[package.thumbnail] then
|
2018-05-20 01:25:17 +02:00
|
|
|
return defaulttexturedir .. "error_screenshot.png"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Download
|
|
|
|
|
|
|
|
local function download_screenshot(params)
|
|
|
|
return core.download_file(params.url, params.dest)
|
|
|
|
end
|
|
|
|
local function callback(success)
|
2018-06-18 21:47:38 +02:00
|
|
|
screenshot_downloading[package.thumbnail] = nil
|
|
|
|
screenshot_downloaded[package.thumbnail] = true
|
2018-05-20 01:25:17 +02:00
|
|
|
if not success then
|
|
|
|
core.log("warning", "Screenshot download failed for some reason")
|
|
|
|
end
|
2019-02-18 12:46:55 +01:00
|
|
|
ui.update()
|
2018-05-20 01:25:17 +02:00
|
|
|
end
|
|
|
|
if core.handle_async(download_screenshot,
|
2018-06-18 21:47:38 +02:00
|
|
|
{ dest = filepath, url = package.thumbnail }, callback) then
|
|
|
|
screenshot_downloading[package.thumbnail] = true
|
2018-05-20 01:25:17 +02:00
|
|
|
else
|
|
|
|
core.log("error", "ERROR: async event failed")
|
|
|
|
return defaulttexturedir .. "error_screenshot.png"
|
|
|
|
end
|
|
|
|
|
|
|
|
return defaulttexturedir .. "loading_screenshot.png"
|
|
|
|
end
|
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
function store.load()
|
2020-05-24 15:46:50 +02:00
|
|
|
local version = core.get_version()
|
|
|
|
local base_url = core.settings:get("contentdb_url")
|
2018-12-11 05:43:14 +01:00
|
|
|
local url = base_url ..
|
|
|
|
"/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
|
2020-05-24 15:46:50 +02:00
|
|
|
core.get_max_supp_proto() .. "&engine_version=" .. version.string
|
2019-02-03 18:54:56 +01:00
|
|
|
|
|
|
|
for _, item in pairs(core.settings:get("contentdb_flag_blacklist"):split(",")) do
|
|
|
|
item = item:trim()
|
|
|
|
if item ~= "" then
|
|
|
|
url = url .. "&hide=" .. item
|
|
|
|
end
|
|
|
|
end
|
2018-12-11 05:43:14 +01:00
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
local timeout = tonumber(minetest.settings:get("curl_file_download_timeout"))
|
|
|
|
local response = http.fetch_sync({ url = url, timeout = timeout })
|
|
|
|
if not response.succeeded then
|
|
|
|
return
|
|
|
|
end
|
2018-12-11 05:43:14 +01:00
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
store.packages_full = core.parse_json(response.data) or {}
|
2018-12-11 05:43:14 +01:00
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
for _, package in pairs(store.packages_full) do
|
|
|
|
package.url = base_url .. "/packages/" ..
|
2018-12-11 05:43:14 +01:00
|
|
|
package.author .. "/" .. package.name ..
|
|
|
|
"/releases/" .. package.release .. "/download/"
|
2019-01-30 17:43:28 +01:00
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
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
|
2018-12-11 05:43:14 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-06 18:17:08 +02:00
|
|
|
store.packages = store.packages_full
|
|
|
|
store.loaded = true
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function store.update_paths()
|
|
|
|
local mod_hash = {}
|
|
|
|
pkgmgr.refresh_globals()
|
|
|
|
for _, mod in pairs(pkgmgr.global_mods:get_list()) do
|
2018-12-26 13:39:28 +01:00
|
|
|
if mod.author then
|
2019-06-10 19:49:00 +02:00
|
|
|
mod_hash[mod.author:lower() .. "/" .. mod.name] = mod
|
2018-12-26 13:39:28 +01:00
|
|
|
end
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local game_hash = {}
|
|
|
|
pkgmgr.update_gamelist()
|
|
|
|
for _, game in pairs(pkgmgr.games) do
|
2019-06-10 19:49:00 +02:00
|
|
|
if game.author ~= "" then
|
|
|
|
game_hash[game.author:lower() .. "/" .. game.id] = game
|
2018-12-26 13:39:28 +01:00
|
|
|
end
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local txp_hash = {}
|
|
|
|
for _, txp in pairs(pkgmgr.get_texture_packs()) do
|
2018-12-26 13:39:28 +01:00
|
|
|
if txp.author then
|
2019-06-10 19:49:00 +02:00
|
|
|
txp_hash[txp.author:lower() .. "/" .. txp.name] = txp
|
2018-12-26 13:39:28 +01:00
|
|
|
end
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
for _, package in pairs(store.packages_full) do
|
|
|
|
local content
|
|
|
|
if package.type == "mod" then
|
2019-01-30 17:43:28 +01:00
|
|
|
content = mod_hash[package.id]
|
2018-04-17 15:54:50 +02:00
|
|
|
elseif package.type == "game" then
|
2019-01-30 17:43:28 +01:00
|
|
|
content = game_hash[package.id]
|
2018-04-17 15:54:50 +02:00
|
|
|
elseif package.type == "txp" then
|
2019-01-30 17:43:28 +01:00
|
|
|
content = txp_hash[package.id]
|
2018-04-17 15:54:50 +02:00
|
|
|
end
|
|
|
|
|
2019-01-30 17:43:28 +01:00
|
|
|
if content then
|
2018-04-17 15:54:50 +02:00
|
|
|
package.path = content.path
|
2019-01-30 17:43:28 +01:00
|
|
|
package.installed_release = content.release or 0
|
2018-04-17 15:54:50 +02:00
|
|
|
else
|
|
|
|
package.path = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function store.filter_packages(query)
|
|
|
|
if query == "" and filter_type == 1 then
|
|
|
|
store.packages = store.packages_full
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local keywords = {}
|
|
|
|
for word in query:lower():gmatch("%S+") do
|
|
|
|
table.insert(keywords, word)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function matches_keywords(package, keywords)
|
|
|
|
for k = 1, #keywords do
|
|
|
|
local keyword = keywords[k]
|
|
|
|
|
|
|
|
if string.find(package.name:lower(), keyword, 1, true) or
|
|
|
|
string.find(package.title:lower(), keyword, 1, true) or
|
|
|
|
string.find(package.author:lower(), keyword, 1, true) or
|
|
|
|
string.find(package.short_description:lower(), keyword, 1, true) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
store.packages = {}
|
|
|
|
for _, package in pairs(store.packages_full) do
|
|
|
|
if (query == "" or matches_keywords(package, keywords)) and
|
|
|
|
(filter_type == 1 or package.type == filter_types_type[filter_type]) then
|
|
|
|
store.packages[#store.packages + 1] = package
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2019-02-18 12:46:55 +01:00
|
|
|
function store.get_formspec(dlgdata)
|
2018-04-17 15:54:50 +02:00
|
|
|
store.update_paths()
|
|
|
|
|
2019-02-18 12:46:55 +01:00
|
|
|
dlgdata.pagemax = math.max(math.ceil(#store.packages / num_per_page), 1)
|
|
|
|
if cur_page > dlgdata.pagemax then
|
2018-04-17 15:54:50 +02:00
|
|
|
cur_page = 1
|
|
|
|
end
|
|
|
|
|
2020-05-29 01:52:48 +02:00
|
|
|
local W = 15.75
|
|
|
|
local H = 9.5
|
|
|
|
|
2018-11-13 03:26:59 +01:00
|
|
|
local formspec
|
2018-12-26 13:47:32 +01:00
|
|
|
if #store.packages_full > 0 then
|
2018-11-13 03:26:59 +01:00
|
|
|
formspec = {
|
2020-05-29 01:52:48 +02:00
|
|
|
"formspec_version[3]",
|
|
|
|
"size[15.75,9.5]",
|
2018-11-13 03:26:59 +01:00
|
|
|
"position[0.5,0.55]",
|
2020-05-29 01:52:48 +02:00
|
|
|
"container[0.375,0.375]",
|
|
|
|
"field[0,0;10.225,0.8;search_string;;", core.formspec_escape(search_string), "]",
|
2018-11-13 03:26:59 +01:00
|
|
|
"field_close_on_enter[search_string;false]",
|
2020-05-29 01:52:48 +02:00
|
|
|
"button[10.225,0;2,0.8;search;", fgettext("Search"), "]",
|
|
|
|
"dropdown[12.6,0;2.4,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]",
|
|
|
|
"container_end[]",
|
2018-11-26 19:47:33 +01:00
|
|
|
|
|
|
|
-- Page nav buttons
|
2020-05-29 01:52:48 +02:00
|
|
|
"container[0,", H - 0.8 - 0.375, "]",
|
|
|
|
"button[0.375,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
|
|
|
|
|
|
|
|
"container[", W - 0.375 - 0.8*4 - 2, ",0]",
|
2020-07-08 23:37:14 +02:00
|
|
|
"image_button[0,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "start_icon.png;pstart;]",
|
|
|
|
"image_button[0.8,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "prev_icon.png;pback;]",
|
2020-05-29 01:52:48 +02:00
|
|
|
"style[pagenum;border=false]",
|
|
|
|
"button[1.6,0;2,0.8;pagenum;", tonumber(cur_page), " / ", tonumber(dlgdata.pagemax), "]",
|
2020-07-08 23:37:14 +02:00
|
|
|
"image_button[3.6,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "next_icon.png;pnext;]",
|
|
|
|
"image_button[4.4,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "end_icon.png;pend;]",
|
2020-05-29 01:52:48 +02:00
|
|
|
"container_end[]",
|
|
|
|
|
2018-11-26 19:47:33 +01:00
|
|
|
"container_end[]",
|
2018-11-13 03:26:59 +01:00
|
|
|
}
|
2019-02-03 02:14:15 +01:00
|
|
|
|
|
|
|
if #store.packages == 0 then
|
|
|
|
formspec[#formspec + 1] = "label[4,3;"
|
|
|
|
formspec[#formspec + 1] = fgettext("No results")
|
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
end
|
2018-11-13 03:26:59 +01:00
|
|
|
else
|
|
|
|
formspec = {
|
2020-05-29 01:52:48 +02:00
|
|
|
"size[12,7]",
|
2018-11-13 03:26:59 +01:00
|
|
|
"position[0.5,0.55]",
|
2019-02-03 02:14:15 +01:00
|
|
|
"label[4,3;", fgettext("No packages could be retrieved"), "]",
|
2020-05-29 01:52:48 +02:00
|
|
|
"container[0,", H - 0.8 - 0.375, "]",
|
|
|
|
"button[0,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
|
|
|
|
"container_end[]",
|
2018-11-13 03:26:59 +01:00
|
|
|
}
|
|
|
|
end
|
2018-04-17 15:54:50 +02:00
|
|
|
|
|
|
|
local start_idx = (cur_page - 1) * num_per_page + 1
|
|
|
|
for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
|
|
|
|
local package = store.packages[i]
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "container[0.375,"
|
|
|
|
formspec[#formspec + 1] = (i - start_idx) * 1.375 + (2*0.375 + 0.8)
|
2018-04-17 15:54:50 +02:00
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
|
|
|
|
-- image
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "image[0,0;1.5,1;"
|
2018-11-13 03:26:59 +01:00
|
|
|
formspec[#formspec + 1] = core.formspec_escape(get_screenshot(package))
|
2018-04-17 15:54:50 +02:00
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
|
|
|
|
-- title
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "label[1.875,0.1;"
|
2018-11-08 22:55:38 +01:00
|
|
|
formspec[#formspec + 1] = core.formspec_escape(
|
|
|
|
minetest.colorize(mt_color_green, package.title) ..
|
|
|
|
minetest.colorize("#BFBFBF", " by " .. package.author))
|
2018-04-17 15:54:50 +02:00
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
|
2020-05-29 01:52:48 +02:00
|
|
|
-- buttons
|
|
|
|
local description_width = W - 0.375*5 - 1 - 2*1.5
|
|
|
|
formspec[#formspec + 1] = "container["
|
|
|
|
formspec[#formspec + 1] = W - 0.375*2
|
|
|
|
formspec[#formspec + 1] = ",0.1]"
|
|
|
|
|
2020-05-27 18:02:09 +02:00
|
|
|
if package.downloading then
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "style[download;border=false]"
|
|
|
|
|
|
|
|
formspec[#formspec + 1] = "button[-3.5,0;2,0.8;download;"
|
2020-05-27 18:02:09 +02:00
|
|
|
formspec[#formspec + 1] = fgettext("Downloading...")
|
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
elseif not package.path then
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "button[-3,0;1.5,0.8;install_"
|
2018-04-17 15:54:50 +02:00
|
|
|
formspec[#formspec + 1] = tostring(i)
|
|
|
|
formspec[#formspec + 1] = ";"
|
2018-05-16 22:52:12 +02:00
|
|
|
formspec[#formspec + 1] = fgettext("Install")
|
2018-04-17 15:54:50 +02:00
|
|
|
formspec[#formspec + 1] = "]"
|
2018-05-16 22:52:12 +02:00
|
|
|
else
|
2019-01-06 16:54:22 +01:00
|
|
|
if package.installed_release < package.release then
|
2020-05-29 01:52:48 +02:00
|
|
|
description_width = description_width - 1.5
|
2020-05-17 20:09:10 +02:00
|
|
|
|
2019-01-06 16:54:22 +01:00
|
|
|
-- The install_ action also handles updating
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "button[-4.5,0;1.5,0.8;install_"
|
2019-01-06 16:54:22 +01:00
|
|
|
formspec[#formspec + 1] = tostring(i)
|
|
|
|
formspec[#formspec + 1] = ";"
|
|
|
|
formspec[#formspec + 1] = fgettext("Update")
|
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
end
|
|
|
|
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "button[-3,0;1.5,0.8;uninstall_"
|
2018-05-16 22:52:12 +02:00
|
|
|
formspec[#formspec + 1] = tostring(i)
|
|
|
|
formspec[#formspec + 1] = ";"
|
|
|
|
formspec[#formspec + 1] = fgettext("Uninstall")
|
2018-04-17 15:54:50 +02:00
|
|
|
formspec[#formspec + 1] = "]"
|
|
|
|
end
|
2019-01-06 16:54:22 +01:00
|
|
|
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "button[-1.5,0;1.5,0.8;view_"
|
2020-05-17 20:09:10 +02:00
|
|
|
formspec[#formspec + 1] = tostring(i)
|
|
|
|
formspec[#formspec + 1] = ";"
|
|
|
|
formspec[#formspec + 1] = fgettext("View")
|
|
|
|
formspec[#formspec + 1] = "]"
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "container_end[]"
|
2020-05-17 20:09:10 +02:00
|
|
|
|
|
|
|
-- description
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = "textarea[1.855,0.3;"
|
2020-05-17 20:09:10 +02:00
|
|
|
formspec[#formspec + 1] = tostring(description_width)
|
2020-05-29 01:52:48 +02:00
|
|
|
formspec[#formspec + 1] = ",0.8;;;"
|
2020-05-17 20:09:10 +02:00
|
|
|
formspec[#formspec + 1] = core.formspec_escape(package.short_description)
|
|
|
|
formspec[#formspec + 1] = "]"
|
2018-04-17 15:54:50 +02:00
|
|
|
|
|
|
|
formspec[#formspec + 1] = "container_end[]"
|
|
|
|
end
|
|
|
|
|
|
|
|
return table.concat(formspec, "")
|
|
|
|
end
|
|
|
|
|
2019-02-18 12:46:55 +01:00
|
|
|
function store.handle_submit(this, fields)
|
2018-04-17 15:54:50 +02:00
|
|
|
if fields.search or fields.key_enter_field == "search_string" then
|
|
|
|
search_string = fields.search_string:trim()
|
|
|
|
cur_page = 1
|
|
|
|
store.filter_packages(search_string)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.back then
|
|
|
|
this:delete()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.pstart then
|
|
|
|
cur_page = 1
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.pend then
|
2019-02-18 12:46:55 +01:00
|
|
|
cur_page = this.data.pagemax
|
2018-04-17 15:54:50 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.pnext then
|
|
|
|
cur_page = cur_page + 1
|
2019-02-18 12:46:55 +01:00
|
|
|
if cur_page > this.data.pagemax then
|
2018-04-17 15:54:50 +02:00
|
|
|
cur_page = 1
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.pback then
|
|
|
|
if cur_page == 1 then
|
2019-02-18 12:46:55 +01:00
|
|
|
cur_page = this.data.pagemax
|
2018-04-17 15:54:50 +02:00
|
|
|
else
|
|
|
|
cur_page = cur_page - 1
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields.type then
|
|
|
|
local new_type = table.indexof(filter_types_titles, fields.type)
|
|
|
|
if new_type ~= filter_type then
|
|
|
|
filter_type = new_type
|
|
|
|
store.filter_packages(search_string)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local start_idx = (cur_page - 1) * num_per_page + 1
|
|
|
|
assert(start_idx ~= nil)
|
|
|
|
for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
|
|
|
|
local package = store.packages[i]
|
|
|
|
assert(package)
|
|
|
|
|
|
|
|
if fields["install_" .. i] then
|
|
|
|
start_install(this, package)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["uninstall_" .. i] then
|
|
|
|
local dlg_delmod = create_delete_content_dlg(package)
|
|
|
|
dlg_delmod:set_parent(this)
|
|
|
|
this:hide()
|
|
|
|
dlg_delmod:show()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["view_" .. i] then
|
2020-07-28 18:01:52 +02:00
|
|
|
local url = ("%s/packages/%s/%s?protocol_version=%d"):format(
|
|
|
|
core.settings:get("contentdb_url"),
|
|
|
|
package.author, package.name, core.get_max_supp_proto())
|
2020-05-17 20:09:10 +02:00
|
|
|
core.open_url(url)
|
2018-04-17 15:54:50 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function create_store_dlg(type)
|
2018-12-26 13:47:32 +01:00
|
|
|
if not store.loaded or #store.packages_full == 0 then
|
2018-04-17 15:54:50 +02:00
|
|
|
store.load()
|
|
|
|
end
|
|
|
|
|
|
|
|
search_string = ""
|
|
|
|
cur_page = 1
|
2020-06-04 22:53:26 +02:00
|
|
|
|
|
|
|
if type then
|
|
|
|
-- table.indexof does not work on tables that contain `nil`
|
|
|
|
for i, v in pairs(filter_types_type) do
|
|
|
|
if v == type then
|
|
|
|
filter_type = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-17 15:54:50 +02:00
|
|
|
store.filter_packages(search_string)
|
|
|
|
|
|
|
|
return dialog_create("store",
|
|
|
|
store.get_formspec,
|
|
|
|
store.handle_submit,
|
|
|
|
nil)
|
|
|
|
end
|