1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
18 interface
23 // download map wad from server (if necessary)
24 // download all required map resource wads too
25 // registers all required replacement wads
26 // returns name of the map wad (relative to mapdir), or empty string on error
29 // returns original name, or replacement name
32 // call this somewhere in startup sequence
36 implementation
40 var
41 // cvars
45 // other vars
49 saveDBsToDiskEnabled: Boolean = false; // this will be set to `true` if initial database saving succeed
52 //==========================================================================
53 //
54 // saveDatabases
55 //
56 //==========================================================================
58 var
61 begin
63 // rescan dirs
64 // save map database
66 begin
69 try
73 except
76 if (err) then begin saveDBsToDiskEnabled := false; e_LogWriteln('cannot write map database, disk refresh disabled'); exit; end;
78 // save resource database
80 begin
83 try
87 except
90 if (err) then begin saveDBsToDiskEnabled := false; e_LogWriteln('cannot write resource database, disk refresh disabled'); exit; end;
95 //==========================================================================
96 //
97 // g_Res_CreateDatabases
98 //
99 //==========================================================================
101 var
106 begin
108 begin
109 // create and load a know map database, if necessary
113 // load map database
115 try
119 except
122 // load resource database
124 try
128 except
132 end
133 else
134 begin
138 // rescan dirs
143 // save databases
149 //==========================================================================
150 //
151 // getWord
152 //
153 // get next word from a string
154 // words are delimited with ';'
155 // ignores leading and trailing spaces
156 // returns empty string if there are no more words
157 //
158 //==========================================================================
160 var
162 begin
165 begin
166 if (ord(list[1]) <= 32) or (list[1] = ';') or (list[1] = ':') then begin Delete(list, 1, 1); continue; end;
171 while (length(result) > 0) and (ord(result[length(result)]) <= 32) do Delete(result, length(result), 1);
177 //==========================================================================
178 //
179 // isIgnoredResWad
180 //
181 // checks if the given resource wad can be ignored
182 //
183 // FIXME: preparse name list?
184 //
185 //==========================================================================
187 var
190 begin
197 begin
199 //writeln('*** name=[', name, ']; fname=[', fname, ']');
206 //==========================================================================
207 //
208 // clearReplacementWads
209 //
210 // call this before downloading a new map from a server
211 //
212 //==========================================================================
214 begin
220 //==========================================================================
221 //
222 // addReplacementWad
223 //
224 // register new replacement wad
225 //
226 //==========================================================================
228 begin
235 //==========================================================================
236 //
237 // g_Res_FindReplacementWad
238 //
239 // returns original name, or replacement name
240 //
241 //==========================================================================
243 var
245 begin
246 //e_LogWritefln('LOOKING for replacement wad for [%s]...', [oldname], TMsgType.Notify);
250 begin
251 //e_LogWritefln('found replacement wad for [%s] -> [%s]', [oldname, fn], TMsgType.Notify);
257 //==========================================================================
258 //
259 // findExistingMapWadWithHash
260 //
261 // find map or resource wad using its base name and hash
262 //
263 // returns found wad disk name, or empty string
264 //
265 //==========================================================================
267 begin
268 //result := scanDir(GameDir+'/maps', ExtractFileName(fname), resMd5);
271 begin
274 begin
282 //==========================================================================
283 //
284 // findExistingResWadWithHash
285 //
286 // find map or resource wad using its base name and hash
287 //
288 // returns found wad disk name, or empty string
289 //
290 //==========================================================================
292 begin
293 //result := scanDir(GameDir+'/wads', ExtractFileName(fname), resMd5);
296 begin
299 begin
307 //==========================================================================
308 //
309 // generateFileName
310 //
311 // generate new file name based on the given one and the hash
312 // you can pass files with pathes here too
313 //
314 //==========================================================================
316 var
321 begin
335 //==========================================================================
336 //
337 // g_Res_DownloadMapWAD
338 //
339 // download map wad from server (if necessary)
340 // download all required map resource wads too
341 // registers all required replacement wads
342 //
343 // returns name of the map wad (relative to mapdir), or empty string on error
344 //
345 //==========================================================================
347 var
358 begin
364 try
373 // this also sends map request
377 // find or download a map
380 begin
381 // download map
384 begin
387 exit;
389 try
391 except
396 try
398 except
401 exit;
403 try
405 except
409 exit;
413 begin
416 exit;
418 // if it was resumed, check md5 and initiate full download if necessary
420 begin
422 // sorry for pasta, i am asshole
424 begin
426 try
429 except
432 exit;
434 try
436 except
440 exit;
444 begin
447 exit;
455 // download resources
457 begin
458 // if we got a new-style reslist packet, use received data to check for resource files
460 begin
461 // old-style packet
465 end
466 else
467 begin
468 // new-style packet
475 begin
476 // ignored file, abort download
479 continue;
483 begin
484 // already here
487 end
488 else
489 begin
491 begin
495 try
497 except
501 try
503 except
506 exit;
508 try
510 except
514 exit;
518 begin
521 exit;
523 // if it was resumed, check md5 and initiate full download if necessary
525 begin
527 // sorry for pasta, i am asshole
529 begin
530 e_LogWritefln('resuming failed; downloading resource `%s` to `%s` from scratch...', [tf.diskName, fname]);
531 try
534 except
537 exit;
539 try
541 except
545 exit;
549 begin
552 exit;
560 finally
565 if saveDBsToDiskEnabled and (mapdbUpdated or resdbUpdated) then saveDatabases(mapdbUpdated, resdbUpdated);
569 initialization
570 conRegVar('rdl_ignore_names', @g_res_ignore_names, 'list of resource wad names (without extensions) to ignore in dl hash checks', 'dl ignore wads');
571 conRegVar('rdl_ignore_enabled', @g_res_ignore_enabled, 'enable dl hash check ignore list', 'dl hash check ignore list active');
572 conRegVar('rdl_hashdb_save_enabled', @g_res_save_databases, 'enable saving map/resource hash databases to disk', 'controls storing hash databases to disk');