summaryrefslogtreecommitdiff
path: root/builtin/mainmenu/dlg_contentstore.lua
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/mainmenu/dlg_contentstore.lua')
-rw-r--r--builtin/mainmenu/dlg_contentstore.lua106
1 files changed, 71 insertions, 35 deletions
diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua
index e3505456e..2c9e80e15 100644
--- a/builtin/mainmenu/dlg_contentstore.lua
+++ b/builtin/mainmenu/dlg_contentstore.lua
@@ -15,6 +15,30 @@
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+local store = {}
+local package_dialog = {}
+
+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",
+}
+
+
+
+
local function download_package(param)
if core.download_file(param.package.url, param.filename) then
return {
@@ -39,7 +63,9 @@ local function start_install(calling_dialog, package)
local function callback(result)
if result.successful then
- local path, msg = pkgmgr.install(result.package.type, result.filename, result.package.name)
+ local path, msg = pkgmgr.install(result.package.type,
+ result.filename, result.package.name,
+ result.package.path)
if not path then
gamedata.errormessage = msg
else
@@ -69,6 +95,7 @@ local function start_install(calling_dialog, package)
end
set_def("description", result.package.short_description)
set_def("author", result.package.author)
+ conf:set("release", result.package.release)
conf:write()
end
end
@@ -85,7 +112,7 @@ local function start_install(calling_dialog, package)
end
if not core.handle_async(download_package, params, callback) then
- minetest.log("error", "ERROR: async event failed")
+ core.log("error", "ERROR: async event failed")
gamedata.errormessage = fgettext("Failed to download $1", package.name)
end
@@ -111,19 +138,35 @@ local function start_install(calling_dialog, package)
end
-local package_dialog = {}
-
function package_dialog.get_formspec()
local package = package_dialog.package
+ store.update_paths()
+
local formspec = {
- "size[8,4;true]",
+ "size[9,4;true]",
"label[2.5,0.2;", core.formspec_escape(package.title), "]",
- "textarea[0.2,1;8,3;;;", core.formspec_escape(package.short_description), "]",
+ "textarea[0.2,1;9,3;;;", core.formspec_escape(package.short_description), "]",
"button[0,0;2,1;back;", fgettext("Back"), "]",
- "button[6,0;2,1;install;", fgettext("Install"), "]",
}
+ if not package.path then
+ formspec[#formspec + 1] = "button[7,0;2,1;install;"
+ formspec[#formspec + 1] = fgettext("Install")
+ formspec[#formspec + 1] = "]"
+ elseif package.installed_release < package.release then
+ formspec[#formspec + 1] = "button[7,0;2,1;install;"
+ formspec[#formspec + 1] = fgettext("Update")
+ formspec[#formspec + 1] = "]"
+ formspec[#formspec + 1] = "button[7,1;2,1;uninstall;"
+ formspec[#formspec + 1] = fgettext("Uninstall")
+ formspec[#formspec + 1] = "]"
+ else
+ formspec[#formspec + 1] = "button[7,0;2,1;uninstall;"
+ formspec[#formspec + 1] = fgettext("Uninstall")
+ formspec[#formspec + 1] = "]"
+ end
+
-- TODO: screenshots
return table.concat(formspec, "")
@@ -136,7 +179,15 @@ function package_dialog.handle_submit(this, fields, tabname, tabdata)
end
if fields.install then
- start_install(package_dialog.package)
+ start_install(this, package_dialog.package)
+ return true
+ end
+
+ if fields.uninstall then
+ local dlg_delmod = create_delete_content_dlg(package_dialog.package)
+ dlg_delmod:set_parent(this)
+ this:hide()
+ dlg_delmod:show()
return true
end
@@ -151,28 +202,6 @@ function package_dialog.create(package)
nil)
end
-
-
-
-local store = {}
-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",
-}
-
function store.load()
store.packages_full = core.get_package_list()
store.packages = store.packages_full
@@ -209,6 +238,7 @@ function store.update_paths()
if content and content.author == package.author then
package.path = content.path
+ package.installed_release = content.release
else
package.path = nil
end
@@ -301,17 +331,23 @@ function store.get_formspec()
formspec[#formspec + 1] = "]"
-- buttons
- if package.path then
- formspec[#formspec + 1] = "button[6,0;1.5,1;uninstall_"
+ if not package.path then
+ formspec[#formspec + 1] = "button[6,0;1.5,1;install_"
formspec[#formspec + 1] = tostring(i)
formspec[#formspec + 1] = ";"
- formspec[#formspec + 1] = fgettext("Uninstall")
+ formspec[#formspec + 1] = fgettext("Install")
formspec[#formspec + 1] = "]"
- else
+ elseif package.installed_release < package.release then
formspec[#formspec + 1] = "button[6,0;1.5,1;install_"
formspec[#formspec + 1] = tostring(i)
formspec[#formspec + 1] = ";"
- formspec[#formspec + 1] = fgettext("Install")
+ formspec[#formspec + 1] = fgettext("Update")
+ formspec[#formspec + 1] = "]"
+ else
+ formspec[#formspec + 1] = "button[6,0;1.5,1;uninstall_"
+ formspec[#formspec + 1] = tostring(i)
+ formspec[#formspec + 1] = ";"
+ formspec[#formspec + 1] = fgettext("Uninstall")
formspec[#formspec + 1] = "]"
end
formspec[#formspec + 1] = "button[7.5,0;1.5,1;view_"