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
103 begin
104 // create and load a know map database, if necessary
109 // load map database
111 try
115 except
118 // load resource database
120 try
124 except
127 // rescan dirs
132 // save databases
137 //==========================================================================
138 //
139 // getWord
140 //
141 // get next word from a string
142 // words are delimited with ';'
143 // ignores leading and trailing spaces
144 // returns empty string if there are no more words
145 //
146 //==========================================================================
148 var
150 begin
153 begin
154 if (ord(list[1]) <= 32) or (list[1] = ';') or (list[1] = ':') then begin Delete(list, 1, 1); continue; end;
159 while (length(result) > 0) and (ord(result[length(result)]) <= 32) do Delete(result, length(result), 1);
165 //==========================================================================
166 //
167 // isIgnoredResWad
168 //
169 // checks if the given resource wad can be ignored
170 //
171 // FIXME: preparse name list?
172 //
173 //==========================================================================
175 var
178 begin
185 begin
187 //writeln('*** name=[', name, ']; fname=[', fname, ']');
194 //==========================================================================
195 //
196 // clearReplacementWads
197 //
198 // call this before downloading a new map from a server
199 //
200 //==========================================================================
202 begin
208 //==========================================================================
209 //
210 // addReplacementWad
211 //
212 // register new replacement wad
213 //
214 //==========================================================================
216 begin
223 //==========================================================================
224 //
225 // g_Res_FindReplacementWad
226 //
227 // returns original name, or replacement name
228 //
229 //==========================================================================
231 var
233 begin
234 //e_LogWritefln('LOOKING for replacement wad for [%s]...', [oldname], TMsgType.Notify);
238 begin
239 //e_LogWritefln('found replacement wad for [%s] -> [%s]', [oldname, fn], TMsgType.Notify);
245 //==========================================================================
246 //
247 // findExistingMapWadWithHash
248 //
249 // find map or resource wad using its base name and hash
250 //
251 // returns found wad disk name, or empty string
252 //
253 //==========================================================================
255 begin
256 //result := scanDir(GameDir+'/maps', ExtractFileName(fname), resMd5);
259 begin
262 begin
270 //==========================================================================
271 //
272 // findExistingResWadWithHash
273 //
274 // find map or resource wad using its base name and hash
275 //
276 // returns found wad disk name, or empty string
277 //
278 //==========================================================================
280 begin
281 //result := scanDir(GameDir+'/wads', ExtractFileName(fname), resMd5);
284 begin
287 begin
295 //==========================================================================
296 //
297 // generateFileName
298 //
299 // generate new file name based on the given one and the hash
300 // you can pass files with pathes here too
301 //
302 //==========================================================================
304 var
309 begin
323 //==========================================================================
324 //
325 // g_Res_DownloadMapWAD
326 //
327 // download map wad from server (if necessary)
328 // download all required map resource wads too
329 // registers all required replacement wads
330 //
331 // returns name of the map wad (relative to mapdir), or empty string on error
332 //
333 //==========================================================================
335 var
346 begin
350 try
359 // this also sends map request
363 // find or download a map
366 begin
367 // download map
370 begin
373 exit;
375 try
377 except
381 try
383 except
386 exit;
388 try
390 except
394 exit;
398 begin
401 exit;
403 // if it was resumed, check md5 and initiate full download if necessary
405 begin
407 // sorry for pasta, i am asshole
409 begin
411 try
414 except
417 exit;
419 try
421 except
425 exit;
429 begin
432 exit;
440 // download resources
442 begin
443 // if we got a new-style reslist packet, use received data to check for resource files
445 begin
446 // old-style packet
450 end
451 else
452 begin
453 // new-style packet
460 begin
461 // ignored file, abort download
464 continue;
468 begin
469 // already here
472 end
473 else
474 begin
476 begin
480 try
482 except
486 try
488 except
491 exit;
493 try
495 except
499 exit;
503 begin
506 exit;
508 // if it was resumed, check md5 and initiate full download if necessary
510 begin
512 // sorry for pasta, i am asshole
514 begin
515 e_LogWritefln('resuming failed; downloading resource `%s` to `%s` from scratch...', [tf.diskName, fname]);
516 try
519 except
522 exit;
524 try
526 except
530 exit;
534 begin
537 exit;
545 finally
550 if saveDBsToDiskEnabled and (mapdbUpdated or resdbUpdated) then saveDatabases(mapdbUpdated, resdbUpdated);
554 initialization
555 conRegVar('rdl_ignore_names', @g_res_ignore_names, 'list of resource wad names (without extensions) to ignore in dl hash checks', 'dl ignore wads');
556 conRegVar('rdl_ignore_enabled', @g_res_ignore_enabled, 'enable dl hash check ignore list', 'dl hash check ignore list active');
557 conRegVar('rdl_hashdb_save_enabled', @g_res_save_databases, 'enable saving map/resource hash databases to disk', 'controls storing hash databases to disk');