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 = {}, aliases = {} }
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 = {
60 local REASON_NEW = "new"
61 local REASON_UPDATE = "update"
62 local REASON_DEPENDENCY = "dependency"
65 -- encodes for use as URL parameter or path component
66 local function urlencode(str)
67 return str:gsub("[^%a%d()._~-]", function(char)
68 return string.format("%%%02X", string.byte(char))
71 assert(urlencode("sample text?") == "sample%20text%3F")
74 local function get_download_url(package, reason)
75 local base_url = core.settings:get("contentdb_url")
76 local ret = base_url .. ("/packages/%s/releases/%d/download/"):format(
77 package.url_part, package.release)
79 ret = ret .. "?reason=" .. reason
85 local function download_and_extract(param)
86 local package = param.package
88 local filename = core.get_temp_path(true)
89 if filename == "" or not core.download_file(param.url, filename) then
90 core.log("error", "Downloading " .. dump(param.url) .. " failed")
92 msg = fgettext("Failed to download $1", package.name)
96 local tempfolder = core.get_temp_path()
97 if tempfolder ~= "" then
98 tempfolder = tempfolder .. DIR_DELIM .. "MT_" .. math.random(1, 1024000)
99 if not core.extract_zip(filename, tempfolder) then
106 if not tempfolder then
108 msg = fgettext("Install: Unsupported file type or broken archive"),
117 local function start_install(package, reason)
120 url = get_download_url(package, reason),
123 number_downloading = number_downloading + 1
125 local function callback(result)
127 gamedata.errormessage = result.msg
129 local path, msg = pkgmgr.install_dir(package.type, result.path, package.name, package.path)
130 core.delete_dir(result.path)
132 gamedata.errormessage = msg
134 core.log("action", "Installed package to " .. path)
137 local name_is_title = false
138 if package.type == "mod" then
139 local actual_type = pkgmgr.get_folder_type(path)
140 if actual_type.type == "modpack" then
141 conf_path = path .. DIR_DELIM .. "modpack.conf"
143 conf_path = path .. DIR_DELIM .. "mod.conf"
145 elseif package.type == "game" then
146 conf_path = path .. DIR_DELIM .. "game.conf"
148 elseif package.type == "txp" then
149 conf_path = path .. DIR_DELIM .. "texture_pack.conf"
153 local conf = Settings(conf_path)
154 conf:set("title", package.title)
155 if not name_is_title then
156 conf:set("name", package.name)
158 if not conf:get("description") then
159 conf:set("description", package.short_description)
161 conf:set("author", package.author)
162 conf:set("release", package.release)
168 package.downloading = false
170 number_downloading = number_downloading - 1
172 local next = download_queue[1]
174 table.remove(download_queue, 1)
176 start_install(next.package, next.reason)
182 package.queued = false
183 package.downloading = true
185 if not core.handle_async(download_and_extract, params, callback) then
186 core.log("error", "ERROR: async event failed")
187 gamedata.errormessage = fgettext("Failed to download $1", package.name)
192 local function queue_download(package, reason)
193 local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads"))
194 if number_downloading < max_concurrent_downloads then
195 start_install(package, reason)
197 table.insert(download_queue, { package = package, reason = reason })
198 package.queued = true
202 local function get_raw_dependencies(package)
203 if package.raw_deps then
204 return package.raw_deps
207 local url_fmt = "/api/packages/%s/dependencies/?only_hard=1&protocol_version=%s&engine_version=%s"
208 local version = core.get_version()
209 local base_url = core.settings:get("contentdb_url")
210 local url = base_url .. url_fmt:format(package.url_part, core.get_max_supp_proto(), urlencode(version.string))
212 local response = http.fetch_sync({ url = url })
213 if not response.succeeded then
217 local data = core.parse_json(response.data) or {}
219 local content_lookup = {}
220 for _, pkg in pairs(store.packages_full) do
221 content_lookup[pkg.id] = pkg
224 for id, raw_deps in pairs(data) do
225 local package2 = content_lookup[id:lower()]
226 if package2 and not package2.raw_deps then
227 package2.raw_deps = raw_deps
229 for _, dep in pairs(raw_deps) do
231 for i=1, #dep.packages do
232 packages[#packages + 1] = content_lookup[dep.packages[i]:lower()]
234 dep.packages = packages
239 return package.raw_deps
242 local function has_hard_deps(raw_deps)
243 for i=1, #raw_deps do
244 if not raw_deps[i].is_optional then
252 -- Recursively resolve dependencies, given the installed mods
253 local function resolve_dependencies_2(raw_deps, installed_mods, out)
254 local function resolve_dep(dep)
255 -- Check whether it's already installed
256 if installed_mods[dep.name] then
258 is_optional = dep.is_optional,
264 -- Find exact name matches
266 for _, package in pairs(dep.packages) do
267 if package.type ~= "game" then
268 if package.name == dep.name then
270 is_optional = dep.is_optional,
275 elseif not fallback then
281 -- Otherwise, find the first mod that fulfils it
284 is_optional = dep.is_optional,
292 is_optional = dep.is_optional,
298 for _, dep in pairs(raw_deps) do
299 if not dep.is_optional and not out[dep.name] then
300 local result = resolve_dep(dep)
301 out[dep.name] = result
302 if result and result.package and not result.installed then
303 local raw_deps2 = get_raw_dependencies(result.package)
305 resolve_dependencies_2(raw_deps2, installed_mods, out)
314 -- Resolve dependencies for a package, calls the recursive version.
315 local function resolve_dependencies(raw_deps, game)
318 local installed_mods = {}
321 pkgmgr.get_game_mods(game, mods)
322 for _, mod in pairs(mods) do
323 installed_mods[mod.name] = true
326 for _, mod in pairs(pkgmgr.global_mods:get_list()) do
327 installed_mods[mod.name] = true
331 if not resolve_dependencies_2(raw_deps, installed_mods, out) then
336 for _, dep in pairs(out) do
337 retval[#retval + 1] = dep
340 table.sort(retval, function(a, b)
341 return a.name < b.name
347 local install_dialog = {}
348 function install_dialog.get_formspec()
349 local package = install_dialog.package
350 local raw_deps = install_dialog.raw_deps
351 local will_install_deps = install_dialog.will_install_deps
353 local selected_game_idx = 1
354 local selected_gameid = core.settings:get("menu_last_game")
355 local games = table.copy(pkgmgr.games)
357 if selected_gameid and games[i].id == selected_gameid then
358 selected_game_idx = i
361 games[i] = core.formspec_escape(games[i].title)
364 local selected_game = pkgmgr.games[selected_game_idx]
365 local deps_to_install = 0
366 local deps_not_found = 0
368 install_dialog.dependencies = resolve_dependencies(raw_deps, selected_game)
369 local formatted_deps = {}
370 for _, dep in pairs(install_dialog.dependencies) do
371 formatted_deps[#formatted_deps + 1] = "#fff"
372 formatted_deps[#formatted_deps + 1] = core.formspec_escape(dep.name)
373 if dep.installed then
374 formatted_deps[#formatted_deps + 1] = "#ccf"
375 formatted_deps[#formatted_deps + 1] = fgettext("Already installed")
376 elseif dep.package then
377 formatted_deps[#formatted_deps + 1] = "#cfc"
378 formatted_deps[#formatted_deps + 1] = fgettext("$1 by $2", dep.package.title, dep.package.author)
379 deps_to_install = deps_to_install + 1
381 formatted_deps[#formatted_deps + 1] = "#f00"
382 formatted_deps[#formatted_deps + 1] = fgettext("Not found")
383 deps_not_found = deps_not_found + 1
387 local message_bg = "#3333"
389 if will_install_deps then
390 message = fgettext("$1 and $2 dependencies will be installed.", package.title, deps_to_install)
392 message = fgettext("$1 will be installed, and $2 dependencies will be skipped.", package.title, deps_to_install)
394 if deps_not_found > 0 then
395 message = fgettext("$1 required dependencies could not be found.", deps_not_found) ..
396 " " .. fgettext("Please check that the base game is correct.", deps_not_found) ..
398 message_bg = mt_color_orange
402 "formspec_version[3]",
404 "style[title;border=false]",
405 "box[0,0;7,0.5;#3333]",
406 "button[0,0;7,0.5;title;", fgettext("Install $1", package.title) , "]",
408 "container[0.375,0.70]",
410 "label[0,0.25;", fgettext("Base Game:"), "]",
411 "dropdown[2,0;4.25,0.5;selected_game;", table.concat(games, ","), ";", selected_game_idx, "]",
413 "label[0,0.8;", fgettext("Dependencies:"), "]",
415 "tablecolumns[color;text;color;text]",
416 "table[0,1.1;6.25,3;packages;", table.concat(formatted_deps, ","), "]",
420 "checkbox[0.375,5.1;will_install_deps;",
421 fgettext("Install missing dependencies"), ";",
422 will_install_deps and "true" or "false", "]",
424 "box[0,5.4;7,1.2;", message_bg, "]",
425 "textarea[0.375,5.5;6.25,1;;;", message, "]",
427 "container[1.375,6.85]",
428 "button[0,0;2,0.8;install_all;", fgettext("Install"), "]",
429 "button[2.25,0;2,0.8;cancel;", fgettext("Cancel"), "]",
433 return table.concat(formspec, "")
436 function install_dialog.handle_submit(this, fields)
437 if fields.cancel then
442 if fields.will_install_deps ~= nil then
443 install_dialog.will_install_deps = core.is_yes(fields.will_install_deps)
447 if fields.install_all then
448 queue_download(install_dialog.package, REASON_NEW)
450 if install_dialog.will_install_deps then
451 for _, dep in pairs(install_dialog.dependencies) do
452 if not dep.is_optional and not dep.installed and dep.package then
453 queue_download(dep.package, REASON_DEPENDENCY)
462 if fields.selected_game then
463 for _, game in pairs(pkgmgr.games) do
464 if game.title == fields.selected_game then
465 core.settings:set("menu_last_game", game.id)
475 function install_dialog.create(package, raw_deps)
476 install_dialog.dependencies = nil
477 install_dialog.package = package
478 install_dialog.raw_deps = raw_deps
479 install_dialog.will_install_deps = true
480 return dialog_create("install_dialog",
481 install_dialog.get_formspec,
482 install_dialog.handle_submit,
487 local confirm_overwrite = {}
488 function confirm_overwrite.get_formspec()
489 local package = confirm_overwrite.package
491 return "size[11.5,4.5,true]" ..
493 fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name) .. "]"..
494 "style[install;bgcolor=red]" ..
495 "button[3.25,3.5;2.5,0.5;install;" .. fgettext("Overwrite") .. "]" ..
496 "button[5.75,3.5;2.5,0.5;cancel;" .. fgettext("Cancel") .. "]"
499 function confirm_overwrite.handle_submit(this, fields)
500 if fields.cancel then
505 if fields.install then
507 confirm_overwrite.callback()
514 function confirm_overwrite.create(package, callback)
515 assert(type(package) == "table")
516 assert(type(callback) == "function")
518 confirm_overwrite.package = package
519 confirm_overwrite.callback = callback
520 return dialog_create("confirm_overwrite",
521 confirm_overwrite.get_formspec,
522 confirm_overwrite.handle_submit,
527 local function get_file_extension(path)
528 local parts = path:split(".")
532 local function get_screenshot(package)
533 if not package.thumbnail then
534 return defaulttexturedir .. "no_screenshot.png"
535 elseif screenshot_downloading[package.thumbnail] then
536 return defaulttexturedir .. "loading_screenshot.png"
539 -- Get tmp screenshot path
540 local ext = get_file_extension(package.thumbnail)
541 local filepath = screenshot_dir .. DIR_DELIM ..
542 ("%s-%s-%s.%s"):format(package.type, package.author, package.name, ext)
544 -- Return if already downloaded
545 local file = io.open(filepath, "r")
551 -- Show error if we've failed to download before
552 if screenshot_downloaded[package.thumbnail] then
553 return defaulttexturedir .. "error_screenshot.png"
558 local function download_screenshot(params)
559 return core.download_file(params.url, params.dest)
561 local function callback(success)
562 screenshot_downloading[package.thumbnail] = nil
563 screenshot_downloaded[package.thumbnail] = true
565 core.log("warning", "Screenshot download failed for some reason")
569 if core.handle_async(download_screenshot,
570 { dest = filepath, url = package.thumbnail }, callback) then
571 screenshot_downloading[package.thumbnail] = true
573 core.log("error", "ERROR: async event failed")
574 return defaulttexturedir .. "error_screenshot.png"
577 return defaulttexturedir .. "loading_screenshot.png"
580 function store.load()
581 local version = core.get_version()
582 local base_url = core.settings:get("contentdb_url")
583 local url = base_url ..
584 "/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
585 core.get_max_supp_proto() .. "&engine_version=" .. urlencode(version.string)
587 for _, item in pairs(core.settings:get("contentdb_flag_blacklist"):split(",")) do
590 url = url .. "&hide=" .. urlencode(item)
594 local response = http.fetch_sync({ url = url })
595 if not response.succeeded then
599 store.packages_full = core.parse_json(response.data) or {}
602 for _, package in pairs(store.packages_full) do
603 local name_len = #package.name
604 -- This must match what store.update_paths() does!
605 package.id = package.author:lower() .. "/"
606 if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then
607 package.id = package.id .. package.name:sub(1, name_len - 5)
609 package.id = package.id .. package.name
612 package.url_part = urlencode(package.author) .. "/" .. urlencode(package.name)
614 if package.aliases then
615 for _, alias in ipairs(package.aliases) do
616 -- We currently don't support name changing
617 local suffix = "/" .. package.name
618 if alias:sub(-#suffix) == suffix then
619 store.aliases[alias:lower()] = package.id
625 store.packages_full_unordered = store.packages_full
626 store.packages = store.packages_full
630 function store.update_paths()
632 pkgmgr.refresh_globals()
633 for _, mod in pairs(pkgmgr.global_mods:get_list()) do
634 if mod.author and mod.release > 0 then
635 local id = mod.author:lower() .. "/" .. mod.name
636 mod_hash[store.aliases[id] or id] = mod
641 pkgmgr.update_gamelist()
642 for _, game in pairs(pkgmgr.games) do
643 if game.author ~= "" and game.release > 0 then
644 local id = game.author:lower() .. "/" .. game.id
645 game_hash[store.aliases[id] or id] = game
650 for _, txp in pairs(pkgmgr.get_texture_packs()) do
651 if txp.author and txp.release > 0 then
652 local id = txp.author:lower() .. "/" .. txp.name
653 txp_hash[store.aliases[id] or id] = txp
657 for _, package in pairs(store.packages_full) do
659 if package.type == "mod" then
660 content = mod_hash[package.id]
661 elseif package.type == "game" then
662 content = game_hash[package.id]
663 elseif package.type == "txp" then
664 content = txp_hash[package.id]
668 package.path = content.path
669 package.installed_release = content.release or 0
676 function store.sort_packages()
679 -- Add installed content
680 for i=1, #store.packages_full_unordered do
681 local package = store.packages_full_unordered[i]
683 ret[#ret + 1] = package
687 -- Sort installed content by title
688 table.sort(ret, function(a, b)
689 return a.title < b.title
692 -- Add uninstalled content
693 for i=1, #store.packages_full_unordered do
694 local package = store.packages_full_unordered[i]
695 if not package.path then
696 ret[#ret + 1] = package
700 store.packages_full = ret
703 function store.filter_packages(query)
704 if query == "" and filter_type == 1 then
705 store.packages = store.packages_full
710 for word in query:lower():gmatch("%S+") do
711 table.insert(keywords, word)
714 local function matches_keywords(package)
715 for k = 1, #keywords do
716 local keyword = keywords[k]
718 if string.find(package.name:lower(), keyword, 1, true) or
719 string.find(package.title:lower(), keyword, 1, true) or
720 string.find(package.author:lower(), keyword, 1, true) or
721 string.find(package.short_description:lower(), keyword, 1, true) then
730 for _, package in pairs(store.packages_full) do
731 if (query == "" or matches_keywords(package)) and
732 (filter_type == 1 or package.type == filter_types_type[filter_type]) then
733 store.packages[#store.packages + 1] = package
738 function store.get_formspec(dlgdata)
741 dlgdata.pagemax = math.max(math.ceil(#store.packages / num_per_page), 1)
742 if cur_page > dlgdata.pagemax then
749 if #store.packages_full > 0 then
751 "formspec_version[3]",
753 "position[0.5,0.55]",
755 "style[status,downloading,queued;border=false]",
757 "container[0.375,0.375]",
758 "field[0,0;7.225,0.8;search_string;;", core.formspec_escape(search_string), "]",
759 "field_close_on_enter[search_string;false]",
760 "image_button[7.3,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "search.png"), ";search;]",
761 "image_button[8.125,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "clear.png"), ";clear;]",
762 "dropdown[9.6,0;2.4,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]",
766 "container[0,", H - 0.8 - 0.375, "]",
767 "button[0.375,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
769 "container[", W - 0.375 - 0.8*4 - 2, ",0]",
770 "image_button[0,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "start_icon.png;pstart;]",
771 "image_button[0.8,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "prev_icon.png;pback;]",
772 "style[pagenum;border=false]",
773 "button[1.6,0;2,0.8;pagenum;", tonumber(cur_page), " / ", tonumber(dlgdata.pagemax), "]",
774 "image_button[3.6,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "next_icon.png;pnext;]",
775 "image_button[4.4,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "end_icon.png;pend;]",
781 if number_downloading > 0 then
782 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;downloading;"
783 if #download_queue > 0 then
784 formspec[#formspec + 1] = fgettext("$1 downloading,\n$2 queued", number_downloading, #download_queue)
786 formspec[#formspec + 1] = fgettext("$1 downloading...", number_downloading)
788 formspec[#formspec + 1] = "]"
790 local num_avail_updates = 0
791 for i=1, #store.packages_full do
792 local package = store.packages_full[i]
793 if package.path and package.installed_release < package.release and
794 not (package.downloading or package.queued) then
795 num_avail_updates = num_avail_updates + 1
799 if num_avail_updates == 0 then
800 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;status;"
801 formspec[#formspec + 1] = fgettext("No updates")
802 formspec[#formspec + 1] = "]"
804 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;update_all;"
805 formspec[#formspec + 1] = fgettext("Update All [$1]", num_avail_updates)
806 formspec[#formspec + 1] = "]"
810 if #store.packages == 0 then
811 formspec[#formspec + 1] = "label[4,3;"
812 formspec[#formspec + 1] = fgettext("No results")
813 formspec[#formspec + 1] = "]"
818 "position[0.5,0.55]",
819 "label[4,3;", fgettext("No packages could be retrieved"), "]",
820 "container[0,", H - 0.8 - 0.375, "]",
821 "button[0,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
826 -- download/queued tooltips always have the same message
827 local tooltip_colors = ";#dff6f5;#302c2e]"
828 formspec[#formspec + 1] = "tooltip[downloading;" .. fgettext("Downloading...") .. tooltip_colors
829 formspec[#formspec + 1] = "tooltip[queued;" .. fgettext("Queued") .. tooltip_colors
831 local start_idx = (cur_page - 1) * num_per_page + 1
832 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
833 local package = store.packages[i]
834 local container_y = (i - start_idx) * 1.375 + (2*0.375 + 0.8)
835 formspec[#formspec + 1] = "container[0.375,"
836 formspec[#formspec + 1] = container_y
837 formspec[#formspec + 1] = "]"
840 formspec[#formspec + 1] = "image[0,0;1.5,1;"
841 formspec[#formspec + 1] = core.formspec_escape(get_screenshot(package))
842 formspec[#formspec + 1] = "]"
845 formspec[#formspec + 1] = "label[1.875,0.1;"
846 formspec[#formspec + 1] = core.formspec_escape(
847 core.colorize(mt_color_green, package.title) ..
848 core.colorize("#BFBFBF", " by " .. package.author))
849 formspec[#formspec + 1] = "]"
852 local left_base = "image_button[-1.55,0;0.7,0.7;" .. core.formspec_escape(defaulttexturedir)
853 formspec[#formspec + 1] = "container["
854 formspec[#formspec + 1] = W - 0.375*2
855 formspec[#formspec + 1] = ",0.1]"
857 if package.downloading then
858 formspec[#formspec + 1] = "animated_image[-1.7,-0.15;1,1;downloading;"
859 formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir)
860 formspec[#formspec + 1] = "cdb_downloading.png;3;400;]"
861 elseif package.queued then
862 formspec[#formspec + 1] = left_base
863 formspec[#formspec + 1] = "cdb_queued.png;queued;]"
864 elseif not package.path then
865 local elem_name = "install_" .. i .. ";"
866 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#71aa34]"
867 formspec[#formspec + 1] = left_base .. "cdb_add.png;" .. elem_name .. "]"
868 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Install") .. tooltip_colors
870 if package.installed_release < package.release then
872 -- The install_ action also handles updating
873 local elem_name = "install_" .. i .. ";"
874 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#28ccdf]"
875 formspec[#formspec + 1] = left_base .. "cdb_update.png;" .. elem_name .. "]"
876 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Update") .. tooltip_colors
879 local elem_name = "uninstall_" .. i .. ";"
880 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#a93b3b]"
881 formspec[#formspec + 1] = left_base .. "cdb_clear.png;" .. elem_name .. "]"
882 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Uninstall") .. tooltip_colors
886 local web_elem_name = "view_" .. i .. ";"
887 formspec[#formspec + 1] = "image_button[-0.7,0;0.7,0.7;" ..
888 core.formspec_escape(defaulttexturedir) .. "cdb_viewonline.png;" .. web_elem_name .. "]"
889 formspec[#formspec + 1] = "tooltip[" .. web_elem_name ..
890 fgettext("View more information in a web browser") .. tooltip_colors
891 formspec[#formspec + 1] = "container_end[]"
894 local description_width = W - 0.375*5 - 0.85 - 2*0.7
895 formspec[#formspec + 1] = "textarea[1.855,0.3;"
896 formspec[#formspec + 1] = tostring(description_width)
897 formspec[#formspec + 1] = ",0.8;;;"
898 formspec[#formspec + 1] = core.formspec_escape(package.short_description)
899 formspec[#formspec + 1] = "]"
901 formspec[#formspec + 1] = "container_end[]"
904 return table.concat(formspec, "")
907 function store.handle_submit(this, fields)
908 if fields.search or fields.key_enter_field == "search_string" then
909 search_string = fields.search_string:trim()
911 store.filter_packages(search_string)
918 store.filter_packages("")
927 if fields.pstart then
933 cur_page = this.data.pagemax
938 cur_page = cur_page + 1
939 if cur_page > this.data.pagemax then
946 if cur_page == 1 then
947 cur_page = this.data.pagemax
949 cur_page = cur_page - 1
955 local new_type = table.indexof(filter_types_titles, fields.type)
956 if new_type ~= filter_type then
957 filter_type = new_type
958 store.filter_packages(search_string)
963 if fields.update_all then
964 for i=1, #store.packages_full do
965 local package = store.packages_full[i]
966 if package.path and package.installed_release < package.release and
967 not (package.downloading or package.queued) then
968 queue_download(package, REASON_UPDATE)
974 local start_idx = (cur_page - 1) * num_per_page + 1
975 assert(start_idx ~= nil)
976 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
977 local package = store.packages[i]
980 if fields["install_" .. i] then
982 if package.type == "mod" then
983 install_parent = core.get_modpath()
984 elseif package.type == "game" then
985 install_parent = core.get_gamepath()
986 elseif package.type == "txp" then
987 install_parent = core.get_texturepath()
989 error("Unknown package type: " .. package.type)
993 local function on_confirm()
994 local deps = get_raw_dependencies(package)
995 if deps and has_hard_deps(deps) then
996 local dlg = install_dialog.create(package, deps)
1001 queue_download(package, package.path and REASON_UPDATE or REASON_NEW)
1005 if not package.path and core.is_dir(install_parent .. DIR_DELIM .. package.name) then
1006 local dlg = confirm_overwrite.create(package, on_confirm)
1007 dlg:set_parent(this)
1017 if fields["uninstall_" .. i] then
1018 local dlg = create_delete_content_dlg(package)
1019 dlg:set_parent(this)
1025 if fields["view_" .. i] then
1026 local url = ("%s/packages/%s?protocol_version=%d"):format(
1027 core.settings:get("contentdb_url"), package.url_part,
1028 core.get_max_supp_proto())
1037 function create_store_dlg(type)
1038 if not store.loaded or #store.packages_full == 0 then
1042 store.update_paths()
1043 store.sort_packages()
1049 -- table.indexof does not work on tables that contain `nil`
1050 for i, v in pairs(filter_types_type) do
1058 store.filter_packages(search_string)
1060 return dialog_create("store",
1062 store.handle_submit,