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 = {
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 if name_is_title then
155 conf:set("name", package.title)
157 conf:set("title", package.title)
158 conf:set("name", package.name)
160 if not conf:get("description") then
161 conf:set("description", package.short_description)
163 conf:set("author", package.author)
164 conf:set("release", package.release)
170 package.downloading = false
172 number_downloading = number_downloading - 1
174 local next = download_queue[1]
176 table.remove(download_queue, 1)
178 start_install(next.package, next.reason)
184 package.queued = false
185 package.downloading = true
187 if not core.handle_async(download_and_extract, params, callback) then
188 core.log("error", "ERROR: async event failed")
189 gamedata.errormessage = fgettext("Failed to download $1", package.name)
194 local function queue_download(package, reason)
195 local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads"))
196 if number_downloading < max_concurrent_downloads then
197 start_install(package, reason)
199 table.insert(download_queue, { package = package, reason = reason })
200 package.queued = true
204 local function get_raw_dependencies(package)
205 if package.raw_deps then
206 return package.raw_deps
209 local url_fmt = "/api/packages/%s/dependencies/?only_hard=1&protocol_version=%s&engine_version=%s"
210 local version = core.get_version()
211 local base_url = core.settings:get("contentdb_url")
212 local url = base_url .. url_fmt:format(package.url_part, core.get_max_supp_proto(), urlencode(version.string))
214 local response = http.fetch_sync({ url = url })
215 if not response.succeeded then
219 local data = core.parse_json(response.data) or {}
221 local content_lookup = {}
222 for _, pkg in pairs(store.packages_full) do
223 content_lookup[pkg.id] = pkg
226 for id, raw_deps in pairs(data) do
227 local package2 = content_lookup[id:lower()]
228 if package2 and not package2.raw_deps then
229 package2.raw_deps = raw_deps
231 for _, dep in pairs(raw_deps) do
233 for i=1, #dep.packages do
234 packages[#packages + 1] = content_lookup[dep.packages[i]:lower()]
236 dep.packages = packages
241 return package.raw_deps
244 local function has_hard_deps(raw_deps)
245 for i=1, #raw_deps do
246 if not raw_deps[i].is_optional then
254 -- Recursively resolve dependencies, given the installed mods
255 local function resolve_dependencies_2(raw_deps, installed_mods, out)
256 local function resolve_dep(dep)
257 -- Check whether it's already installed
258 if installed_mods[dep.name] then
260 is_optional = dep.is_optional,
266 -- Find exact name matches
268 for _, package in pairs(dep.packages) do
269 if package.type ~= "game" then
270 if package.name == dep.name then
272 is_optional = dep.is_optional,
277 elseif not fallback then
283 -- Otherwise, find the first mod that fulfils it
286 is_optional = dep.is_optional,
294 is_optional = dep.is_optional,
300 for _, dep in pairs(raw_deps) do
301 if not dep.is_optional and not out[dep.name] then
302 local result = resolve_dep(dep)
303 out[dep.name] = result
304 if result and result.package and not result.installed then
305 local raw_deps2 = get_raw_dependencies(result.package)
307 resolve_dependencies_2(raw_deps2, installed_mods, out)
316 -- Resolve dependencies for a package, calls the recursive version.
317 local function resolve_dependencies(raw_deps, game)
320 local installed_mods = {}
323 pkgmgr.get_game_mods(game, mods)
324 for _, mod in pairs(mods) do
325 installed_mods[mod.name] = true
328 for _, mod in pairs(pkgmgr.global_mods:get_list()) do
329 installed_mods[mod.name] = true
333 if not resolve_dependencies_2(raw_deps, installed_mods, out) then
338 for _, dep in pairs(out) do
339 retval[#retval + 1] = dep
342 table.sort(retval, function(a, b)
343 return a.name < b.name
349 local install_dialog = {}
350 function install_dialog.get_formspec()
351 local package = install_dialog.package
352 local raw_deps = install_dialog.raw_deps
353 local will_install_deps = install_dialog.will_install_deps
355 local selected_game_idx = 1
356 local selected_gameid = core.settings:get("menu_last_game")
357 local games = table.copy(pkgmgr.games)
359 if selected_gameid and games[i].id == selected_gameid then
360 selected_game_idx = i
363 games[i] = core.formspec_escape(games[i].name)
366 local selected_game = pkgmgr.games[selected_game_idx]
367 local deps_to_install = 0
368 local deps_not_found = 0
370 install_dialog.dependencies = resolve_dependencies(raw_deps, selected_game)
371 local formatted_deps = {}
372 for _, dep in pairs(install_dialog.dependencies) do
373 formatted_deps[#formatted_deps + 1] = "#fff"
374 formatted_deps[#formatted_deps + 1] = core.formspec_escape(dep.name)
375 if dep.installed then
376 formatted_deps[#formatted_deps + 1] = "#ccf"
377 formatted_deps[#formatted_deps + 1] = fgettext("Already installed")
378 elseif dep.package then
379 formatted_deps[#formatted_deps + 1] = "#cfc"
380 formatted_deps[#formatted_deps + 1] = fgettext("$1 by $2", dep.package.title, dep.package.author)
381 deps_to_install = deps_to_install + 1
383 formatted_deps[#formatted_deps + 1] = "#f00"
384 formatted_deps[#formatted_deps + 1] = fgettext("Not found")
385 deps_not_found = deps_not_found + 1
389 local message_bg = "#3333"
391 if will_install_deps then
392 message = fgettext("$1 and $2 dependencies will be installed.", package.title, deps_to_install)
394 message = fgettext("$1 will be installed, and $2 dependencies will be skipped.", package.title, deps_to_install)
396 if deps_not_found > 0 then
397 message = fgettext("$1 required dependencies could not be found.", deps_not_found) ..
398 " " .. fgettext("Please check that the base game is correct.", deps_not_found) ..
400 message_bg = mt_color_orange
404 "formspec_version[3]",
406 "style[title;border=false]",
407 "box[0,0;7,0.5;#3333]",
408 "button[0,0;7,0.5;title;", fgettext("Install $1", package.title) , "]",
410 "container[0.375,0.70]",
412 "label[0,0.25;", fgettext("Base Game:"), "]",
413 "dropdown[2,0;4.25,0.5;gameid;", table.concat(games, ","), ";", selected_game_idx, "]",
415 "label[0,0.8;", fgettext("Dependencies:"), "]",
417 "tablecolumns[color;text;color;text]",
418 "table[0,1.1;6.25,3;packages;", table.concat(formatted_deps, ","), "]",
422 "checkbox[0.375,5.1;will_install_deps;",
423 fgettext("Install missing dependencies"), ";",
424 will_install_deps and "true" or "false", "]",
426 "box[0,5.4;7,1.2;", message_bg, "]",
427 "textarea[0.375,5.5;6.25,1;;;", message, "]",
429 "container[1.375,6.85]",
430 "button[0,0;2,0.8;install_all;", fgettext("Install"), "]",
431 "button[2.25,0;2,0.8;cancel;", fgettext("Cancel"), "]",
435 return table.concat(formspec, "")
438 function install_dialog.handle_submit(this, fields)
439 if fields.cancel then
444 if fields.will_install_deps ~= nil then
445 install_dialog.will_install_deps = core.is_yes(fields.will_install_deps)
449 if fields.install_all then
450 queue_download(install_dialog.package, REASON_NEW)
452 if install_dialog.will_install_deps then
453 for _, dep in pairs(install_dialog.dependencies) do
454 if not dep.is_optional and not dep.installed and dep.package then
455 queue_download(dep.package, REASON_DEPENDENCY)
464 if fields.gameid then
465 for _, game in pairs(pkgmgr.games) do
466 if game.name == fields.gameid then
467 core.settings:set("menu_last_game", game.id)
477 function install_dialog.create(package, raw_deps)
478 install_dialog.dependencies = nil
479 install_dialog.package = package
480 install_dialog.raw_deps = raw_deps
481 install_dialog.will_install_deps = true
482 return dialog_create("install_dialog",
483 install_dialog.get_formspec,
484 install_dialog.handle_submit,
489 local confirm_overwrite = {}
490 function confirm_overwrite.get_formspec()
491 local package = confirm_overwrite.package
493 return "size[11.5,4.5,true]" ..
495 fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name) .. "]"..
496 "style[install;bgcolor=red]" ..
497 "button[3.25,3.5;2.5,0.5;install;" .. fgettext("Overwrite") .. "]" ..
498 "button[5.75,3.5;2.5,0.5;cancel;" .. fgettext("Cancel") .. "]"
501 function confirm_overwrite.handle_submit(this, fields)
502 if fields.cancel then
507 if fields.install then
509 confirm_overwrite.callback()
516 function confirm_overwrite.create(package, callback)
517 assert(type(package) == "table")
518 assert(type(callback) == "function")
520 confirm_overwrite.package = package
521 confirm_overwrite.callback = callback
522 return dialog_create("confirm_overwrite",
523 confirm_overwrite.get_formspec,
524 confirm_overwrite.handle_submit,
529 local function get_file_extension(path)
530 local parts = path:split(".")
534 local function get_screenshot(package)
535 if not package.thumbnail then
536 return defaulttexturedir .. "no_screenshot.png"
537 elseif screenshot_downloading[package.thumbnail] then
538 return defaulttexturedir .. "loading_screenshot.png"
541 -- Get tmp screenshot path
542 local ext = get_file_extension(package.thumbnail)
543 local filepath = screenshot_dir .. DIR_DELIM ..
544 ("%s-%s-%s.%s"):format(package.type, package.author, package.name, ext)
546 -- Return if already downloaded
547 local file = io.open(filepath, "r")
553 -- Show error if we've failed to download before
554 if screenshot_downloaded[package.thumbnail] then
555 return defaulttexturedir .. "error_screenshot.png"
560 local function download_screenshot(params)
561 return core.download_file(params.url, params.dest)
563 local function callback(success)
564 screenshot_downloading[package.thumbnail] = nil
565 screenshot_downloaded[package.thumbnail] = true
567 core.log("warning", "Screenshot download failed for some reason")
571 if core.handle_async(download_screenshot,
572 { dest = filepath, url = package.thumbnail }, callback) then
573 screenshot_downloading[package.thumbnail] = true
575 core.log("error", "ERROR: async event failed")
576 return defaulttexturedir .. "error_screenshot.png"
579 return defaulttexturedir .. "loading_screenshot.png"
582 function store.load()
583 local version = core.get_version()
584 local base_url = core.settings:get("contentdb_url")
585 local url = base_url ..
586 "/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
587 core.get_max_supp_proto() .. "&engine_version=" .. urlencode(version.string)
589 for _, item in pairs(core.settings:get("contentdb_flag_blacklist"):split(",")) do
592 url = url .. "&hide=" .. urlencode(item)
596 local response = http.fetch_sync({ url = url })
597 if not response.succeeded then
601 store.packages_full = core.parse_json(response.data) or {}
604 for _, package in pairs(store.packages_full) do
605 local name_len = #package.name
606 -- This must match what store.update_paths() does!
607 package.id = package.author:lower() .. "/"
608 if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then
609 package.id = package.id .. package.name:sub(1, name_len - 5)
611 package.id = package.id .. package.name
614 package.url_part = urlencode(package.author) .. "/" .. urlencode(package.name)
616 if package.aliases then
617 for _, alias in ipairs(package.aliases) do
618 -- We currently don't support name changing
619 local suffix = "/" .. package.name
620 if alias:sub(-#suffix) == suffix then
621 store.aliases[alias:lower()] = package.id
627 store.packages_full_unordered = store.packages_full
628 store.packages = store.packages_full
632 function store.update_paths()
634 pkgmgr.refresh_globals()
635 for _, mod in pairs(pkgmgr.global_mods:get_list()) do
636 if mod.author and mod.release > 0 then
637 local id = mod.author:lower() .. "/" .. mod.name
638 mod_hash[store.aliases[id] or id] = mod
643 pkgmgr.update_gamelist()
644 for _, game in pairs(pkgmgr.games) do
645 if game.author ~= "" and game.release > 0 then
646 local id = game.author:lower() .. "/" .. game.id
647 game_hash[store.aliases[id] or id] = game
652 for _, txp in pairs(pkgmgr.get_texture_packs()) do
653 if txp.author and txp.release > 0 then
654 local id = txp.author:lower() .. "/" .. txp.name
655 txp_hash[store.aliases[id] or id] = txp
659 for _, package in pairs(store.packages_full) do
661 if package.type == "mod" then
662 content = mod_hash[package.id]
663 elseif package.type == "game" then
664 content = game_hash[package.id]
665 elseif package.type == "txp" then
666 content = txp_hash[package.id]
670 package.path = content.path
671 package.installed_release = content.release or 0
678 function store.sort_packages()
681 -- Add installed content
682 for i=1, #store.packages_full_unordered do
683 local package = store.packages_full_unordered[i]
685 ret[#ret + 1] = package
689 -- Sort installed content by title
690 table.sort(ret, function(a, b)
691 return a.title < b.title
694 -- Add uninstalled content
695 for i=1, #store.packages_full_unordered do
696 local package = store.packages_full_unordered[i]
697 if not package.path then
698 ret[#ret + 1] = package
702 store.packages_full = ret
705 function store.filter_packages(query)
706 if query == "" and filter_type == 1 then
707 store.packages = store.packages_full
712 for word in query:lower():gmatch("%S+") do
713 table.insert(keywords, word)
716 local function matches_keywords(package)
717 for k = 1, #keywords do
718 local keyword = keywords[k]
720 if string.find(package.name:lower(), keyword, 1, true) or
721 string.find(package.title:lower(), keyword, 1, true) or
722 string.find(package.author:lower(), keyword, 1, true) or
723 string.find(package.short_description:lower(), keyword, 1, true) then
732 for _, package in pairs(store.packages_full) do
733 if (query == "" or matches_keywords(package)) and
734 (filter_type == 1 or package.type == filter_types_type[filter_type]) then
735 store.packages[#store.packages + 1] = package
740 function store.get_formspec(dlgdata)
743 dlgdata.pagemax = math.max(math.ceil(#store.packages / num_per_page), 1)
744 if cur_page > dlgdata.pagemax then
751 if #store.packages_full > 0 then
753 "formspec_version[3]",
755 "position[0.5,0.55]",
757 "style[status,downloading,queued;border=false]",
759 "container[0.375,0.375]",
760 "field[0,0;7.225,0.8;search_string;;", core.formspec_escape(search_string), "]",
761 "field_close_on_enter[search_string;false]",
762 "image_button[7.3,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "search.png"), ";search;]",
763 "image_button[8.125,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "clear.png"), ";clear;]",
764 "dropdown[9.6,0;2.4,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]",
768 "container[0,", H - 0.8 - 0.375, "]",
769 "button[0.375,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
771 "container[", W - 0.375 - 0.8*4 - 2, ",0]",
772 "image_button[0,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "start_icon.png;pstart;]",
773 "image_button[0.8,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "prev_icon.png;pback;]",
774 "style[pagenum;border=false]",
775 "button[1.6,0;2,0.8;pagenum;", tonumber(cur_page), " / ", tonumber(dlgdata.pagemax), "]",
776 "image_button[3.6,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "next_icon.png;pnext;]",
777 "image_button[4.4,0;0.8,0.8;", core.formspec_escape(defaulttexturedir), "end_icon.png;pend;]",
783 if number_downloading > 0 then
784 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;downloading;"
785 if #download_queue > 0 then
786 formspec[#formspec + 1] = fgettext("$1 downloading,\n$2 queued", number_downloading, #download_queue)
788 formspec[#formspec + 1] = fgettext("$1 downloading...", number_downloading)
790 formspec[#formspec + 1] = "]"
792 local num_avail_updates = 0
793 for i=1, #store.packages_full do
794 local package = store.packages_full[i]
795 if package.path and package.installed_release < package.release and
796 not (package.downloading or package.queued) then
797 num_avail_updates = num_avail_updates + 1
801 if num_avail_updates == 0 then
802 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;status;"
803 formspec[#formspec + 1] = fgettext("No updates")
804 formspec[#formspec + 1] = "]"
806 formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;update_all;"
807 formspec[#formspec + 1] = fgettext("Update All [$1]", num_avail_updates)
808 formspec[#formspec + 1] = "]"
812 if #store.packages == 0 then
813 formspec[#formspec + 1] = "label[4,3;"
814 formspec[#formspec + 1] = fgettext("No results")
815 formspec[#formspec + 1] = "]"
820 "position[0.5,0.55]",
821 "label[4,3;", fgettext("No packages could be retrieved"), "]",
822 "container[0,", H - 0.8 - 0.375, "]",
823 "button[0,0;4,0.8;back;", fgettext("Back to Main Menu"), "]",
828 -- download/queued tooltips always have the same message
829 local tooltip_colors = ";#dff6f5;#302c2e]"
830 formspec[#formspec + 1] = "tooltip[downloading;" .. fgettext("Downloading...") .. tooltip_colors
831 formspec[#formspec + 1] = "tooltip[queued;" .. fgettext("Queued") .. tooltip_colors
833 local start_idx = (cur_page - 1) * num_per_page + 1
834 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
835 local package = store.packages[i]
836 local container_y = (i - start_idx) * 1.375 + (2*0.375 + 0.8)
837 formspec[#formspec + 1] = "container[0.375,"
838 formspec[#formspec + 1] = container_y
839 formspec[#formspec + 1] = "]"
842 formspec[#formspec + 1] = "image[0,0;1.5,1;"
843 formspec[#formspec + 1] = core.formspec_escape(get_screenshot(package))
844 formspec[#formspec + 1] = "]"
847 formspec[#formspec + 1] = "label[1.875,0.1;"
848 formspec[#formspec + 1] = core.formspec_escape(
849 core.colorize(mt_color_green, package.title) ..
850 core.colorize("#BFBFBF", " by " .. package.author))
851 formspec[#formspec + 1] = "]"
854 local left_base = "image_button[-1.55,0;0.7,0.7;" .. core.formspec_escape(defaulttexturedir)
855 formspec[#formspec + 1] = "container["
856 formspec[#formspec + 1] = W - 0.375*2
857 formspec[#formspec + 1] = ",0.1]"
859 if package.downloading then
860 formspec[#formspec + 1] = "animated_image[-1.7,-0.15;1,1;downloading;"
861 formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir)
862 formspec[#formspec + 1] = "cdb_downloading.png;3;400;]"
863 elseif package.queued then
864 formspec[#formspec + 1] = left_base
865 formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir)
866 formspec[#formspec + 1] = "cdb_queued.png;queued]"
867 elseif not package.path then
868 local elem_name = "install_" .. i .. ";"
869 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#71aa34]"
870 formspec[#formspec + 1] = left_base .. "cdb_add.png;" .. elem_name .. "]"
871 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Install") .. tooltip_colors
873 if package.installed_release < package.release then
875 -- The install_ action also handles updating
876 local elem_name = "install_" .. i .. ";"
877 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#28ccdf]"
878 formspec[#formspec + 1] = left_base .. "cdb_update.png;" .. elem_name .. "]"
879 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Update") .. tooltip_colors
882 local elem_name = "uninstall_" .. i .. ";"
883 formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#a93b3b]"
884 formspec[#formspec + 1] = left_base .. "cdb_clear.png;" .. elem_name .. "]"
885 formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Uninstall") .. tooltip_colors
889 local web_elem_name = "view_" .. i .. ";"
890 formspec[#formspec + 1] = "image_button[-0.7,0;0.7,0.7;" ..
891 core.formspec_escape(defaulttexturedir) .. "cdb_viewonline.png;" .. web_elem_name .. "]"
892 formspec[#formspec + 1] = "tooltip[" .. web_elem_name ..
893 fgettext("View more information in a web browser") .. tooltip_colors
894 formspec[#formspec + 1] = "container_end[]"
897 local description_width = W - 0.375*5 - 0.85 - 2*0.7
898 formspec[#formspec + 1] = "textarea[1.855,0.3;"
899 formspec[#formspec + 1] = tostring(description_width)
900 formspec[#formspec + 1] = ",0.8;;;"
901 formspec[#formspec + 1] = core.formspec_escape(package.short_description)
902 formspec[#formspec + 1] = "]"
904 formspec[#formspec + 1] = "container_end[]"
907 return table.concat(formspec, "")
910 function store.handle_submit(this, fields)
911 if fields.search or fields.key_enter_field == "search_string" then
912 search_string = fields.search_string:trim()
914 store.filter_packages(search_string)
921 store.filter_packages("")
930 if fields.pstart then
936 cur_page = this.data.pagemax
941 cur_page = cur_page + 1
942 if cur_page > this.data.pagemax then
949 if cur_page == 1 then
950 cur_page = this.data.pagemax
952 cur_page = cur_page - 1
958 local new_type = table.indexof(filter_types_titles, fields.type)
959 if new_type ~= filter_type then
960 filter_type = new_type
961 store.filter_packages(search_string)
966 if fields.update_all then
967 for i=1, #store.packages_full do
968 local package = store.packages_full[i]
969 if package.path and package.installed_release < package.release and
970 not (package.downloading or package.queued) then
971 queue_download(package, REASON_UPDATE)
977 local start_idx = (cur_page - 1) * num_per_page + 1
978 assert(start_idx ~= nil)
979 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do
980 local package = store.packages[i]
983 if fields["install_" .. i] then
985 if package.type == "mod" then
986 install_parent = core.get_modpath()
987 elseif package.type == "game" then
988 install_parent = core.get_gamepath()
989 elseif package.type == "txp" then
990 install_parent = core.get_texturepath()
992 error("Unknown package type: " .. package.type)
996 local function on_confirm()
997 local deps = get_raw_dependencies(package)
998 if deps and has_hard_deps(deps) then
999 local dlg = install_dialog.create(package, deps)
1000 dlg:set_parent(this)
1004 queue_download(package, package.path and REASON_UPDATE or REASON_NEW)
1008 if not package.path and core.is_dir(install_parent .. DIR_DELIM .. package.name) then
1009 local dlg = confirm_overwrite.create(package, on_confirm)
1010 dlg:set_parent(this)
1020 if fields["uninstall_" .. i] then
1021 local dlg = create_delete_content_dlg(package)
1022 dlg:set_parent(this)
1028 if fields["view_" .. i] then
1029 local url = ("%s/packages/%s?protocol_version=%d"):format(
1030 core.settings:get("contentdb_url"), package.url_part,
1031 core.get_max_supp_proto())
1040 function create_store_dlg(type)
1041 if not store.loaded or #store.packages_full == 0 then
1045 store.update_paths()
1046 store.sort_packages()
1052 -- table.indexof does not work on tables that contain `nil`
1053 for i, v in pairs(filter_types_type) do
1061 store.filter_packages(search_string)
1063 return dialog_create("store",
1065 store.handle_submit,