2 --Copyright (C) 2018-20 rubenwardy
4 --This program is free software; you can redistribute it and/or modify
5 --it under the terms of the GNU Lesser General Public License as published by
6 --the Free Software Foundation; either version 2.1 of the License, or
7 --(at your option) any later version.
9 --This program is distributed in the hope that it will be useful,
10 --but WITHOUT ANY WARRANTY; without even the implied warranty of
11 --MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 --GNU Lesser General Public License for more details.
14 --You should have received a copy of the GNU Lesser General Public License along
15 --with this program; if not, write to the Free Software Foundation, Inc.,
16 --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 if not core.get_http_api then
19 function create_store_dlg()
20 return messagebox("store",
21 fgettext("ContentDB is not available when Minetest was compiled without cURL"))
26 -- Unordered preserves the original order of the ContentDB API,
27 -- before the package list is ordered based on installed state.
28 local store = { packages = {}, packages_full = {}, packages_full_unordered = {} }
30 local http = core.get_http_api()
33 local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb"
34 assert(core.create_dir(screenshot_dir))
35 local screenshot_downloading = {}
36 local screenshot_downloaded = {}
39 local search_string = ""
41 local num_per_page = 5
43 local filter_types_titles = {
44 fgettext("All packages"),
47 fgettext("Texture packs"),
50 local number_downloading = 0
51 local download_queue = {}
53 local filter_types_type = {
61 local function download_package(param)
62 if core.download_file(param.package.url, param.filename) then
64 filename = param.filename,
68 core.log("error", "downloading " .. dump(param.package.url) .. " failed")
75 local function start_install(package)
78 filename = os.tempfolder() .. "_MODNAME_" .. package.name .. ".zip",
81 number_downloading = number_downloading + 1
83 local function callback(result)
84 if result.successful then
85 local path, msg = pkgmgr.install(package.type,
86 result.filename, package.name,
89 gamedata.errormessage = msg
91 core.log("action", "Installed package to " .. path)
94 local name_is_title = false
95 if package.type == "mod" then
96 local actual_type = pkgmgr.get_folder_type(path)
97 if actual_type.type == "modpack" then
98 conf_path = path .. DIR_DELIM .. "modpack.conf"
100 conf_path = path .. DIR_DELIM .. "mod.conf"
102 elseif package.type == "game" then
103 conf_path = path .. DIR_DELIM .. "game.conf"
105 elseif package.type == "txp" then
106 conf_path = path .. DIR_DELIM .. "texture_pack.conf"
110 local conf = Settings(conf_path)
111 if name_is_title then
112 conf:set("name", package.title)
114 conf:set("title", package.title)
115 conf:set("name", package.name)
117 if not conf:get("description") then
118 conf:set("description", package.short_description)
120 conf:set("author", package.author)
121 conf:set("release", package.release)
125 os.remove(result.filename)
127 gamedata.errormessage = fgettext("Failed to download $1", package.name)
130 package.downloading = false
132 number_downloading = number_downloading - 1
134 local next = download_queue[1]
136 table.remove(download_queue, 1)
144 package.queued = false
145 package.downloading = true
147 if not core.handle_async(download_package, params, callback) then
148 core.log("error", "ERROR: async event failed")
149 gamedata.errormessage = fgettext("Failed to download $1", package.name)
154 local function queue_download(package)
155 local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads"))
156 if number_downloading < max_concurrent_downloads then
157 start_install(package)
159 table.insert(download_queue, package)
160 package.queued = true
164 local function get_raw_dependencies(package)
165 if package.raw_deps then
166 return package.raw_deps
169 local url_fmt = "/api/packages/%s/dependencies/?only_hard=1&protocol_version=%s&engine_version=%s"
170 local version = core.get_version()
171 local base_url = core.settings:get("contentdb_url")
172 local url = base_url .. url_fmt:format(package.id, core.get_max_supp_proto(), version.string)
174 local response = http.fetch_sync({ url = url })
175 if not response.succeeded then
179 local data = core.parse_json(response.data) or {}
181 local content_lookup = {}
182 for _, pkg in pairs(store.packages_full) do
183 content_lookup[pkg.id] = pkg
186 for id, raw_deps in pairs(data) do
187 local package2 = content_lookup[id:lower()]
188 if package2 and not package2.raw_deps then
189 package2.raw_deps = raw_deps
191 for _, dep in pairs(raw_deps) do
193 for i=1, #dep.packages do
194 packages[#packages + 1] = content_lookup[dep.packages[i]:lower()]
196 dep.packages = packages
201 return package.raw_deps
204 local function has_hard_deps(raw_deps)
205 for i=1, #raw_deps do
206 if not raw_deps[i].is_optional then
214 -- Recursively resolve dependencies, given the installed mods
215 local function resolve_dependencies_2(raw_deps, installed_mods, out)
216 local function resolve_dep(dep)
217 -- Check whether it's already installed
218 if installed_mods[dep.name] then
220 is_optional = dep.is_optional,
226 -- Find exact name matches
228 for _, package in pairs(dep.packages) do
229 if package.type ~= "game" then
230 if package.name == dep.name then
232 is_optional = dep.is_optional,
237 elseif not fallback then
243 -- Otherwise, find the first mod that fulfils it
246 is_optional = dep.is_optional,
254 is_optional = dep.is_optional,
260 for _, dep in pairs(raw_deps) do
261 if not dep.is_optional and not out[dep.name] then
262 local result = resolve_dep(dep)
263 out[dep.name] = result
264 if result and result.package and not result.installed then
265 local raw_deps2 = get_raw_dependencies(result.package)
267 resolve_dependencies_2(raw_deps2, installed_mods, out)
276 -- Resolve dependencies for a package, calls the recursive version.
277 local function resolve_dependencies(raw_deps, game)
280 local installed_mods = {}
283 pkgmgr.get_game_mods(game, mods)
284 for _, mod in pairs(mods) do
285 installed_mods[mod.name] = true
288 for _, mod in pairs(pkgmgr.global_mods:get_list()) do
289 installed_mods[mod.name] = true
293 if not resolve_dependencies_2(raw_deps, installed_mods, out) then
298 for _, dep in pairs(out) do
299 retval[#retval + 1] = dep
302 table.sort(retval, function(a, b)
303 return a.name < b.name
309 local install_dialog = {}
310 function install_dialog.get_formspec()
311 local package = install_dialog.package
312 local raw_deps = install_dialog.raw_deps
313 local will_install_deps = install_dialog.will_install_deps
315 local selected_game_idx = 1
316 local selected_gameid = core.settings:get("menu_last_game")
317 local games = table.copy(pkgmgr.games)
319 if selected_gameid and games[i].id == selected_gameid then
320 selected_game_idx = i
323 games[i] = core.formspec_escape(games[i].name)
326 local selected_game = pkgmgr.games[selected_game_idx]
327 local deps_to_install = 0
328 local deps_not_found = 0
330 install_dialog.dependencies = resolve_dependencies(raw_deps, selected_game)
331 local formatted_deps = {}
332 for _, dep in pairs(install_dialog.dependencies) do
333 formatted_deps[#formatted_deps + 1] = "#fff"
334 formatted_deps[#formatted_deps + 1] = core.formspec_escape(dep.name)
335 if dep.installed then
336 formatted_deps[#formatted_deps + 1] = "#ccf"
337 formatted_deps[#formatted_deps + 1] = fgettext("Already installed")
338 elseif dep.package then
339 formatted_deps[#formatted_deps + 1] = "#cfc"
340 formatted_deps[#formatted_deps + 1] = fgettext("$1 by $2", dep.package.title, dep.package.author)
341 deps_to_install = deps_to_install + 1
343 formatted_deps[#formatted_deps + 1] = "#f00"
344 formatted_deps[#formatted_deps + 1] = fgettext("Not found")
345 deps_not_found = deps_not_found + 1
349 local message_bg = "#3333"
351 if will_install_deps then
352 message = fgettext("$1 and $2 dependencies will be installed.", package.title, deps_to_install)
354 message = fgettext("$1 will be installed, and $2 dependencies will be skipped.", package.title, deps_to_install)
356 if deps_not_found > 0 then
357 message = fgettext("$1 required dependencies could not be found.", deps_not_found) ..
358 " " .. fgettext("Please check that the base game is correct.", deps_not_found) ..
360 message_bg = mt_color_orange
364 "formspec_version[3]",
366 "style[title;border=false]",
367 "box[0,0;7,0.5;#3333]",
368 "button[0,0;7,0.5;title;", fgettext("Install $1", package.title) , "]",
370 "container[0.375,0.70]",
372 "label[0,0.25;", fgettext("Base Game:"), "]",
373 "dropdown[2,0;4.25,0.5;gameid;", table.concat(games, ","), ";", selected_game_idx, "]",
375 "label[0,0.8;", fgettext("Dependencies:"), "]",
377 "tablecolumns[color;text;color;text]",
378 "table[0,1.1;6.25,3;packages;", table.concat(formatted_deps, ","), "]",
382 "checkbox[0.375,5.1;will_install_deps;",
383 fgettext("Install missing dependencies"), ";",
384 will_install_deps and "true" or "false", "]",
386 "box[0,5.4;7,1.2;", message_bg, "]",
387 "textarea[0.375,5.5;6.25,1;;;", message, "]",
389 "container[1.375,6.85]",
390 "button[0,0;2,0.8;install_all;", fgettext("Install"), "]",
391 "button[2.25,0;2,0.8;cancel;", fgettext("Cancel"), "]",
395 return table.concat(formspec, "")
398 function install_dialog.handle_submit(this, fields)
399 if fields.cancel then
404 if fields.will_install_deps ~= nil then
405 install_dialog.will_install_deps = core.is_yes(fields.will_install_deps)
409 if fields.install_all then
410 queue_download(install_dialog.package)
412 if install_dialog.will_install_deps then
413 for _, dep in pairs(install_dialog.dependencies) do
414 if not dep.is_optional and not dep.installed and dep.package then
415 queue_download(dep.package)
424 if fields.gameid then
425 for _, game in pairs(pkgmgr.games) do
426 if game.name == fields.gameid then
427 core.settings:set("menu_last_game", game.id)
437 function install_dialog.create(package, raw_deps)
438 install_dialog.dependencies = nil
439 install_dialog.package = package
440 install_dialog.raw_deps = raw_deps
441 install_dialog.will_install_deps = true
442 return dialog_create("install_dialog",
443 install_dialog.get_formspec,
444 install_dialog.handle_submit,
449 local confirm_overwrite = {}
450 function confirm_overwrite.get_formspec()
451 local package = confirm_overwrite.package
453 return "size[11.5,4.5,true]" ..
455 fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name) .. "]"..
456 "style[install;bgcolor=red]" ..
457 "button[3.25,3.5;2.5,0.5;install;" .. fgettext("Overwrite") .. "]" ..
458 "button[5.75,3.5;2.5,0.5;cancel;" .. fgettext("Cancel") .. "]"
461 function confirm_overwrite.handle_submit(this, fields)
462 if fields.cancel then
467 if fields.install then
469 confirm_overwrite.callback()
476 function confirm_overwrite.create(package, callback)
477 assert(type(package) == "table")
478 assert(type(callback) == "function")
480 confirm_overwrite.package = package
481 confirm_overwrite.callback = callback
482 return dialog_create("confirm_overwrite",
483 confirm_overwrite.get_formspec,
484 confirm_overwrite.handle_submit,
489 local function get_file_extension(path)
490 local parts = path:split(".")
494 local function get_screenshot(package)
495 if not package.thumbnail then
496 return defaulttexturedir .. "no_screenshot.png"
497 elseif screenshot_downloading[package.thumbnail] then
498 return defaulttexturedir .. "loading_screenshot.png"
501 -- Get tmp screenshot path
502 local ext = get_file_extension(package.thumbnail)
503 local filepath = screenshot_dir .. DIR_DELIM ..
504 ("%s-%s-%s.%s"):format(package.type, package.author, package.name, ext)
506 -- Return if already downloaded
507 local file = io.open(filepath, "r")
513 -- Show error if we've failed to download before
514 if screenshot_downloaded[package.thumbnail] then
515 return defaulttexturedir .. "error_screenshot.png"
520 local function download_screenshot(params)
521 return core.download_file(params.url, params.dest)
523 local function callback(success)
524 screenshot_downloading[package.thumbnail] = nil
525 screenshot_downloaded[package.thumbnail] = true
527 core.log("warning", "Screenshot download failed for some reason")
531 if core.handle_async(download_screenshot,
532 { dest = filepath, url = package.thumbnail }, callback) then
533 screenshot_downloading[package.thumbnail] = true
535 core.log("error", "ERROR: async event failed")
536 return defaulttexturedir .. "error_screenshot.png"
539 return defaulttexturedir .. "loading_screenshot.png"
542 function store.load()
543 local version = core.get_version()
544 local base_url = core.settings:get("contentdb_url")
545 local url = base_url ..
546 "/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
547 core.get_max_supp_proto() .. "&engine_version=" .. version.string
549 for _, item in pairs(core.settings:get("contentdb_flag_blacklist"):split(",")) do
552 url = url .. "&hide=" .. item
556 local timeout = tonumber(core.settings:get("curl_file_download_timeout"))
557 local response = http.fetch_sync({ url = url, timeout = timeout })
558 if not response.succeeded then
562 store.packages_full = core.parse_json(response.data) or {}
564 for _, package in pairs(store.packages_full) do
565 package.url = base_url .. "/packages/" ..
566 package.author .. "/" .. package.name ..
567 "/releases/" .. package.release .. "/download/"
569 local name_len = #package.name
570 if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then
571 package.id = package.author:lower() .. "/" .. package.name:sub(1, name_len - 5)
573 package.id = package.author:lower() .. "/" .. package.name
577 store.packages_full_unordered = store.packages_full
578 store.packages = store.packages_full
582 function store.update_paths()
584 pkgmgr.refresh_globals()
585 for _, mod in pairs(pkgmgr.global_mods:get_list()) do
586 if mod.author and mod.release > 0 then
587 mod_hash[mod.author:lower() .. "/" .. mod.name] = mod
592 pkgmgr.update_gamelist()
593 for _, game in pairs(pkgmgr.games) do
594 if game.author ~= "" and game.release > 0 then
595 game_hash[game.author:lower() .. "/" .. game.id] = game
600 for _, txp in pairs(pkgmgr.get_texture_packs()) do
601 if txp.author and txp.release > 0 then
602 txp_hash[txp.author:lower() .. "/" .. txp.name] = txp
606 for _, package in pairs(store.packages_full) do
608 if package.type == "mod" then
609 content = mod_hash[package.id]
610 elseif package.type == "game" then
611 content = game_hash[package.id]
612 elseif package.type == "txp" then
613 content = txp_hash[package.id]
617 package.path = content.path
618 package.installed_release = content.release or 0
625 function store.sort_packages()
628 -- Add installed content
629 for i=1, #store.packages_full_unordered do
630 local package = store.packages_full_unordered[i]
632 ret[#ret + 1] = package
636 -- Sort installed content by title
637 table.sort(ret, function(a, b)
638 return a.title < b.title
641 -- Add uninstalled content
642 for i=1, #store.packages_full_unordered do
643 local package = store.packages_full_unordered[i]
644 if not package.path then
645 ret[#ret + 1] = package
649 store.packages_full = ret
652 function store.filter_packages(query)
653 if query == "" and filter_type == 1 then
654 store.packages = store.packages_full
659 for word in query:lower():gmatch("%S+") do
660 table.insert(keywords, word)
663 local function matches_keywords(package)
664 for k = 1, #keywords do
665 local keyword = keywords[k]
667 if string.find(package.name:lower(), keyword, 1, true) or
668 string.find(package.title:lower(), keyword, 1, true) or
669 string.find(package.author:lower(), keyword, 1, true) or
670 string.find(package.short_description:lower(), keyword, 1, true) then
679 for _, package in pairs(store.packages_full) do
680 if (query == "" or matches_keywords(package)) and
681 (filter_type == 1 or package.type == filter_types_type[filter_type]) then
682 store.packages[#store.packages + 1] = package
687 function store.get_formspec(dlgdata)
690 dlgdata.pagemax = math.max(math.ceil(#store.packages / num_per_page), 1)
691 if cur_page > dlgdata.pagemax then
698 if #store.packages_full > 0 then
700 "formspec_version[3]",
702 "position[0.5,0.55]",
704 "style[status,downloading,queued;border=false]",
706 "container[0.375,0.375]",
707 "field[0,0;7.225,0.8;search_string;;", core.formspec_escape(search_string), "]",
708 "field_close_on_enter[search_string;false]",
709 "image_button[7.3,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "search.png"), ";search;]",
710 "image_button[8.125,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "clear.png"), ";clear;]",
711 "dropdown[9.6,0;2.4,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]",
715 "container[0,", H - 0.8 - 0.375, "]",
716 "button[0.375,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
718 "container[", W - 0.375 - 0.8*4 - 2, ",0]",
719 "image_button[0,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "start_icon.png;pstart;]",
720 "image_button[0.8,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "prev_icon.png;pback;]",
721 "style[pagenum;border=false]",
722 "button[1.6,0;2,0.8;pagenum;", tonumber(cur_page), " / ", tonumber(dlgdata.pagemax), "]",
723 "image_button[3.6,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "next_icon.png;pnext;]",
724 "image_button[4.4,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "end_icon.png;pend;]",
730 if number_downloading > 0 then
731 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;downloading;"
732 if #download_queue > 0 then
733 formspec[#formspec + 1] = fgettext("$1 downloading,\n$2 queued", number_downloading, #download_queue)
735 formspec[#formspec + 1] = fgettext("$1 downloading...", number_downloading)
737 formspec[#formspec + 1] = "]"
739 local num_avail_updates = 0
740 for i=1, #store.packages_full do
741 local package = store.packages_full[i]
742 if package.path and package.installed_release < package.release and
743 not (package.downloading or package.queued) then
744 num_avail_updates = num_avail_updates + 1
748 if num_avail_updates == 0 then
749 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;status;"
750 formspec[#formspec + 1] = fgettext("No updates")
751 formspec[#formspec + 1] = "]"
753 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;update_all;"
754 formspec[#formspec + 1] = fgettext("Update All [$1]", num_avail_updates)
755 formspec[#formspec + 1] = "]"
759 if #store.packages == 0 then
760 formspec[#formspec + 1] = "label[4,3;"
761 formspec[#formspec + 1] = fgettext("No results")
762 formspec[#formspec + 1] = "]"
767 "position[0.5,0.55]",
768 "label[4,3;", fgettext("No packages could be retrieved"), "]",
769 "container[0,", H - 0.8 - 0.375, "]",
770 "button[0,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
775 -- download/queued tooltips always have the same message
776 local tooltip_colors = ";#dff6f5;#302c2e]"
777 formspec[#formspec + 1] = "tooltip[downloading;" .. fgettext("Downloading...") .. tooltip_colors
778 formspec[#formspec + 1] = "tooltip[queued;" .. fgettext("Queued") .. tooltip_colors
780 local start_idx = (cur_page - 1) * num_per_page + 1
781 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
782 local package = store.packages[i]
783 local container_y = (i - start_idx) * 1.375 + (2*0.375 + 0.8)
784 formspec[#formspec + 1] = "container[0.375,"
785 formspec[#formspec + 1] = container_y
786 formspec[#formspec + 1] = "]"
789 formspec[#formspec + 1] = "image[0,0;1.5,1;"
790 formspec[#formspec + 1] = core.formspec_escape(get_screenshot(package))
791 formspec[#formspec + 1] = "]"
794 formspec[#formspec + 1] = "label[1.875,0.1;"
795 formspec[#formspec + 1] = core.formspec_escape(
796 core.colorize(mt_color_green, package.title) ..
797 core.colorize("#BFBFBF", " by " .. package.author))
798 formspec[#formspec + 1] = "]"
801 local left_base = "image_button[-1.55,0;0.7,0.7;" .. core.formspec_escape(defaulttexturedir)
802 formspec[#formspec + 1] = "container["
803 formspec[#formspec + 1] = W - 0.375*2
804 formspec[#formspec + 1] = ",0.1]"
806 if package.downloading then
807 formspec[#formspec + 1] = "animated_image[-1.7,-0.15;1,1;downloading;"
808 formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir)
809 formspec[#formspec + 1] = "cdb_downloading.png;3;400;]"
810 elseif package.queued then
811 formspec[#formspec + 1] = left_base
812 formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir)
813 formspec[#formspec + 1] = "cdb_queued.png;queued]"
814 elseif not package.path then
815 local elem_name = "install_" .. i .. ";"
816 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#71aa34]"
817 formspec[#formspec + 1] = left_base .. "cdb_add.png;" .. elem_name .. "]"
818 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Install") .. tooltip_colors
820 if package.installed_release < package.release then
822 -- The install_ action also handles updating
823 local elem_name = "install_" .. i .. ";"
824 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#28ccdf]"
825 formspec[#formspec + 1] = left_base .. "cdb_update.png;" .. elem_name .. "]"
826 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Update") .. tooltip_colors
829 local elem_name = "uninstall_" .. i .. ";"
830 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#a93b3b]"
831 formspec[#formspec + 1] = left_base .. "cdb_clear.png;" .. elem_name .. "]"
832 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Uninstall") .. tooltip_colors
836 local web_elem_name = "view_" .. i .. ";"
837 formspec[#formspec + 1] = "image_button[-0.7,0;0.7,0.7;" ..
838 core.formspec_escape(defaulttexturedir) .. "cdb_viewonline.png;" .. web_elem_name .. "]"
839 formspec[#formspec + 1] = "tooltip[" .. web_elem_name ..
840 fgettext("View more information in a web browser") .. tooltip_colors
841 formspec[#formspec + 1] = "container_end[]"
844 local description_width = W - 0.375*5 - 0.85 - 2*0.7
845 formspec[#formspec + 1] = "textarea[1.855,0.3;"
846 formspec[#formspec + 1] = tostring(description_width)
847 formspec[#formspec + 1] = ",0.8;;;"
848 formspec[#formspec + 1] = core.formspec_escape(package.short_description)
849 formspec[#formspec + 1] = "]"
851 formspec[#formspec + 1] = "container_end[]"
854 return table.concat(formspec, "")
857 function store.handle_submit(this, fields)
858 if fields.search or fields.key_enter_field == "search_string" then
859 search_string = fields.search_string:trim()
861 store.filter_packages(search_string)
868 store.filter_packages("")
877 if fields.pstart then
883 cur_page = this.data.pagemax
888 cur_page = cur_page + 1
889 if cur_page > this.data.pagemax then
896 if cur_page == 1 then
897 cur_page = this.data.pagemax
899 cur_page = cur_page - 1
905 local new_type = table.indexof(filter_types_titles, fields.type)
906 if new_type ~= filter_type then
907 filter_type = new_type
908 store.filter_packages(search_string)
913 if fields.update_all then
914 for i=1, #store.packages_full do
915 local package = store.packages_full[i]
916 if package.path and package.installed_release < package.release and
917 not (package.downloading or package.queued) then
918 queue_download(package)
924 local start_idx = (cur_page - 1) * num_per_page + 1
925 assert(start_idx ~= nil)
926 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
927 local package = store.packages[i]
930 if fields["install_" .. i] then
932 if package.type == "mod" then
933 install_parent = core.get_modpath()
934 elseif package.type == "game" then
935 install_parent = core.get_gamepath()
936 elseif package.type == "txp" then
937 install_parent = core.get_texturepath()
939 error("Unknown package type: " .. package.type)
943 local function on_confirm()
944 local deps = get_raw_dependencies(package)
945 if deps and has_hard_deps(deps) then
946 local dlg = install_dialog.create(package, deps)
951 queue_download(package)
955 if not package.path and core.is_dir(install_parent .. DIR_DELIM .. package.name) then
956 local dlg = confirm_overwrite.create(package, on_confirm)
967 if fields["uninstall_" .. i] then
968 local dlg = create_delete_content_dlg(package)
975 if fields["view_" .. i] then
976 local url = ("%s/packages/%s/%s?protocol_version=%d"):format(
977 core.settings:get("contentdb_url"),
978 package.author, package.name, core.get_max_supp_proto())
987 function create_store_dlg(type)
988 if not store.loaded or #store.packages_full == 0 then
993 store.sort_packages()
999 -- table.indexof does not work on tables that contain `nil`
1000 for i, v in pairs(filter_types_type) do
1008 store.filter_packages(search_string)
1010 return dialog_create("store",
1012 store.handle_submit,