]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/mainmenu/dlg_delete_content.lua
Fix games not updating on deletion
[dragonfireclient.git] / builtin / mainmenu / dlg_delete_content.lua
1 --Minetest
2 --Copyright (C) 2014 sapier
3 --
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.
8 --
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.
13 --
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.
17
18 --------------------------------------------------------------------------------
19
20 local function delete_content_formspec(dialogdata)
21         local retval =
22                 "size[11.5,4.5,true]" ..
23                 "label[2,2;" ..
24                 fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name) .. "]"..
25                 "button[3.25,3.5;2.5,0.5;dlg_delete_content_confirm;" .. fgettext("Delete") .. "]" ..
26                 "button[5.75,3.5;2.5,0.5;dlg_delete_content_cancel;" .. fgettext("Cancel") .. "]"
27
28         return retval
29 end
30
31 --------------------------------------------------------------------------------
32 local function delete_content_buttonhandler(this, fields)
33         if fields["dlg_delete_content_confirm"] ~= nil then
34
35                 if this.data.content.path ~= nil and
36                                 this.data.content.path ~= "" and
37                                 this.data.content.path ~= core.get_modpath() and
38                                 this.data.content.path ~= core.get_gamepath() and
39                                 this.data.content.path ~= core.get_texturepath() then
40                         if not core.delete_dir(this.data.content.path) then
41                                 gamedata.errormessage = fgettext("pkgmgr: failed to delete \"$1\"", this.data.content.path)
42                         end
43
44                         if this.data.content.type == "game" then
45                                 pkgmgr.update_gamelist()
46                         else
47                                 pkgmgr.refresh_globals()
48                         end
49                 else
50                         gamedata.errormessage = fgettext("pkgmgr: invalid path \"$1\"", this.data.content.path)
51                 end
52                 this:delete()
53                 return true
54         end
55
56         if fields["dlg_delete_content_cancel"] then
57                 this:delete()
58                 return true
59         end
60
61         return false
62 end
63
64 --------------------------------------------------------------------------------
65 function create_delete_content_dlg(content)
66         assert(content.name)
67
68         local retval = dialog_create("dlg_delete_content",
69                                         delete_content_formspec,
70                                         delete_content_buttonhandler,
71                                         nil)
72         retval.data.content = content
73         return retval
74 end