15
15
-- with this program; if not, write to the Free Software Foundation, Inc.,
16
16
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
+ local store = {}
19
+ local package_dialog = {}
20
+
21
+ local search_string = " "
22
+ local cur_page = 1
23
+ local num_per_page = 5
24
+ local filter_type = 1
25
+ local filter_types_titles = {
26
+ fgettext (" All packages" ),
27
+ fgettext (" Games" ),
28
+ fgettext (" Mods" ),
29
+ fgettext (" Texture packs" ),
30
+ }
31
+
32
+ local filter_types_type = {
33
+ nil ,
34
+ " game" ,
35
+ " mod" ,
36
+ " txp" ,
37
+ }
38
+
39
+
40
+
41
+
18
42
local function download_package (param )
19
43
if core .download_file (param .package .url , param .filename ) then
20
44
return {
@@ -39,7 +63,9 @@ local function start_install(calling_dialog, package)
39
63
40
64
local function callback (result )
41
65
if result .successful then
42
- local path , msg = pkgmgr .install (result .package .type , result .filename , result .package .name )
66
+ local path , msg = pkgmgr .install (result .package .type ,
67
+ result .filename , result .package .name ,
68
+ result .package .path )
43
69
if not path then
44
70
gamedata .errormessage = msg
45
71
else
@@ -69,6 +95,7 @@ local function start_install(calling_dialog, package)
69
95
end
70
96
set_def (" description" , result .package .short_description )
71
97
set_def (" author" , result .package .author )
98
+ conf :set (" release" , result .package .release )
72
99
conf :write ()
73
100
end
74
101
end
@@ -85,7 +112,7 @@ local function start_install(calling_dialog, package)
85
112
end
86
113
87
114
if not core .handle_async (download_package , params , callback ) then
88
- minetest .log (" error" , " ERROR: async event failed" )
115
+ core .log (" error" , " ERROR: async event failed" )
89
116
gamedata .errormessage = fgettext (" Failed to download $1" , package .name )
90
117
end
91
118
@@ -111,19 +138,35 @@ local function start_install(calling_dialog, package)
111
138
end
112
139
113
140
114
- local package_dialog = {}
115
-
116
141
function package_dialog .get_formspec ()
117
142
local package = package_dialog .package
118
143
144
+ store .update_paths ()
145
+
119
146
local formspec = {
120
- " size[8 ,4;true]" ,
147
+ " size[9 ,4;true]" ,
121
148
" label[2.5,0.2;" , core .formspec_escape (package .title ), " ]" ,
122
- " textarea[0.2,1;8 ,3;;;" , core .formspec_escape (package .short_description ), " ]" ,
149
+ " textarea[0.2,1;9 ,3;;;" , core .formspec_escape (package .short_description ), " ]" ,
123
150
" button[0,0;2,1;back;" , fgettext (" Back" ), " ]" ,
124
- " button[6,0;2,1;install;" , fgettext (" Install" ), " ]" ,
125
151
}
126
152
153
+ if not package.path then
154
+ formspec [# formspec + 1 ] = " button[7,0;2,1;install;"
155
+ formspec [# formspec + 1 ] = fgettext (" Install" )
156
+ formspec [# formspec + 1 ] = " ]"
157
+ elseif package .installed_release < package .release then
158
+ formspec [# formspec + 1 ] = " button[7,0;2,1;install;"
159
+ formspec [# formspec + 1 ] = fgettext (" Update" )
160
+ formspec [# formspec + 1 ] = " ]"
161
+ formspec [# formspec + 1 ] = " button[7,1;2,1;uninstall;"
162
+ formspec [# formspec + 1 ] = fgettext (" Uninstall" )
163
+ formspec [# formspec + 1 ] = " ]"
164
+ else
165
+ formspec [# formspec + 1 ] = " button[7,0;2,1;uninstall;"
166
+ formspec [# formspec + 1 ] = fgettext (" Uninstall" )
167
+ formspec [# formspec + 1 ] = " ]"
168
+ end
169
+
127
170
-- TODO: screenshots
128
171
129
172
return table.concat (formspec , " " )
@@ -136,7 +179,15 @@ function package_dialog.handle_submit(this, fields, tabname, tabdata)
136
179
end
137
180
138
181
if fields .install then
139
- start_install (package_dialog .package )
182
+ start_install (this , package_dialog .package )
183
+ return true
184
+ end
185
+
186
+ if fields .uninstall then
187
+ local dlg_delmod = create_delete_content_dlg (package_dialog .package )
188
+ dlg_delmod :set_parent (this )
189
+ this :hide ()
190
+ dlg_delmod :show ()
140
191
return true
141
192
end
142
193
@@ -151,28 +202,6 @@ function package_dialog.create(package)
151
202
nil )
152
203
end
153
204
154
-
155
-
156
-
157
- local store = {}
158
- local search_string = " "
159
- local cur_page = 1
160
- local num_per_page = 5
161
- local filter_type = 1
162
- local filter_types_titles = {
163
- fgettext (" All packages" ),
164
- fgettext (" Games" ),
165
- fgettext (" Mods" ),
166
- fgettext (" Texture packs" ),
167
- }
168
-
169
- local filter_types_type = {
170
- nil ,
171
- " game" ,
172
- " mod" ,
173
- " txp" ,
174
- }
175
-
176
205
function store .load ()
177
206
store .packages_full = core .get_package_list ()
178
207
store .packages = store .packages_full
@@ -209,6 +238,7 @@ function store.update_paths()
209
238
210
239
if content and content .author == package .author then
211
240
package.path = content .path
241
+ package .installed_release = content .release
212
242
else
213
243
package.path = nil
214
244
end
@@ -301,17 +331,23 @@ function store.get_formspec()
301
331
formspec [# formspec + 1 ] = " ]"
302
332
303
333
-- buttons
304
- if package.path then
305
- formspec [# formspec + 1 ] = " button[6,0;1.5,1;uninstall_ "
334
+ if not package.path then
335
+ formspec [# formspec + 1 ] = " button[6,0;1.5,1;install_ "
306
336
formspec [# formspec + 1 ] = tostring (i )
307
337
formspec [# formspec + 1 ] = " ;"
308
- formspec [# formspec + 1 ] = fgettext (" Uninstall " )
338
+ formspec [# formspec + 1 ] = fgettext (" Install " )
309
339
formspec [# formspec + 1 ] = " ]"
310
- else
340
+ elseif package . installed_release < package . release then
311
341
formspec [# formspec + 1 ] = " button[6,0;1.5,1;install_"
312
342
formspec [# formspec + 1 ] = tostring (i )
313
343
formspec [# formspec + 1 ] = " ;"
314
- formspec [# formspec + 1 ] = fgettext (" Install" )
344
+ formspec [# formspec + 1 ] = fgettext (" Update" )
345
+ formspec [# formspec + 1 ] = " ]"
346
+ else
347
+ formspec [# formspec + 1 ] = " button[6,0;1.5,1;uninstall_"
348
+ formspec [# formspec + 1 ] = tostring (i )
349
+ formspec [# formspec + 1 ] = " ;"
350
+ formspec [# formspec + 1 ] = fgettext (" Uninstall" )
315
351
formspec [# formspec + 1 ] = " ]"
316
352
end
317
353
formspec [# formspec + 1 ] = " button[7.5,0;1.5,1;view_"
0 commit comments