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
62 begin
66 // rescan dirs
67 // save map database
69 begin
72 try
76 except
79 if (err) then begin saveDBsToDiskEnabled := false; e_LogWriteln('cannot write map database, disk refresh disabled'); exit; end;
81 // save resource database
83 begin
86 try
90 except
93 if (err) then begin saveDBsToDiskEnabled := false; e_LogWriteln('cannot write resource database, disk refresh disabled'); exit; end;
98 //==========================================================================
99 //
100 // g_Res_CreateDatabases
101 //
102 //==========================================================================
104 var
110 begin
112 begin
113 // create and load a know map database, if necessary
119 // load map database
121 try
124 begin
129 except
132 // load resource database
134 try
136 begin
141 except
145 end
146 else
147 begin
151 // rescan dirs
156 // save databases
162 //==========================================================================
163 //
164 // getWord
165 //
166 // get next word from a string
167 // words are delimited with ';'
168 // ignores leading and trailing spaces
169 // returns empty string if there are no more words
170 //
171 //==========================================================================
173 var
175 begin
178 begin
179 if (ord(list[1]) <= 32) or (list[1] = ';') or (list[1] = ':') then begin Delete(list, 1, 1); continue; end;
184 while (length(result) > 0) and (ord(result[length(result)]) <= 32) do Delete(result, length(result), 1);
190 //==========================================================================
191 //
192 // isIgnoredResWad
193 //
194 // checks if the given resource wad can be ignored
195 //
196 // FIXME: preparse name list?
197 //
198 //==========================================================================
200 var
203 begin
210 begin
212 //writeln('*** name=[', name, ']; fname=[', fname, ']');
219 //==========================================================================
220 //
221 // clearReplacementWads
222 //
223 // call this before downloading a new map from a server
224 //
225 //==========================================================================
227 begin
233 //==========================================================================
234 //
235 // addReplacementWad
236 //
237 // register new replacement wad
238 //
239 //==========================================================================
241 begin
248 //==========================================================================
249 //
250 // g_Res_FindReplacementWad
251 //
252 // returns original name, or replacement name
253 //
254 //==========================================================================
256 var
258 begin
259 //e_LogWritefln('LOOKING for replacement wad for [%s]...', [oldname], TMsgType.Notify);
263 begin
264 //e_LogWritefln('found replacement wad for [%s] -> [%s]', [oldname, fn], TMsgType.Notify);
270 //==========================================================================
271 //
272 // findExistingMapWadWithHash
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
283 begin
284 //result := GameDir+'/maps/'+result;
286 begin
294 //==========================================================================
295 //
296 // findExistingResWadWithHash
297 //
298 // find map or resource wad using its base name and hash
299 //
300 // returns found wad disk name, or empty string
301 //
302 //==========================================================================
304 begin
307 begin
308 //result := GameDir+'/wads/'+result;
310 begin
318 //==========================================================================
319 //
320 // generateFileName
321 //
322 // generate new file name based on the given one and the hash
323 // you can pass files with pathes here too
324 //
325 //==========================================================================
327 var
332 begin
346 //==========================================================================
347 //
348 // g_Res_DownloadMapWAD
349 //
350 // download map wad from server (if necessary)
351 // download all required map resource wads too
352 // registers all required replacement wads
353 //
354 // returns name of the map wad (relative to mapdir), or empty string on error
355 //
356 //==========================================================================
358 var
371 begin
379 try
385 // this also sends map request
389 // find or download a map
392 begin
393 // download map
396 begin
399 exit;
401 try
403 except
406 begin
409 exit;
414 try
416 except
419 exit;
421 try
423 except
427 exit;
431 begin
434 exit;
436 // if it was resumed, check md5 and initiate full download if necessary
438 begin
440 // sorry for pasta, i am asshole
442 begin
444 try
447 except
450 exit;
452 try
454 except
458 exit;
462 begin
465 exit;
473 // download resources
475 begin
476 // if we got a new-style reslist packet, use received data to check for resource files
478 begin
479 // old-style packet
483 end
484 else
485 begin
486 // new-style packet
493 begin
494 // ignored file, abort download
497 continue;
501 begin
502 // already here
505 end
506 else
507 begin
509 begin
513 try
515 except
518 begin
521 exit;
525 try
527 except
530 exit;
532 try
534 except
538 exit;
542 begin
545 exit;
547 // if it was resumed, check md5 and initiate full download if necessary
549 begin
551 // sorry for pasta, i am asshole
553 begin
554 e_LogWritefln('resuming failed; downloading resource `%s` to `%s` from scratch...', [tf.diskName, fname]);
555 try
558 except
561 exit;
563 try
565 except
569 exit;
573 begin
576 exit;
584 finally
589 if saveDBsToDiskEnabled and (mapdbUpdated or resdbUpdated) then saveDatabases(mapdbUpdated, resdbUpdated);
593 initialization
594 conRegVar('rdl_ignore_names', @g_res_ignore_names, 'list of resource wad names (without extensions) to ignore in dl hash checks', 'dl ignore wads');
595 conRegVar('rdl_ignore_enabled', @g_res_ignore_enabled, 'enable dl hash check ignore list', 'dl hash check ignore list active');
596 conRegVar('rdl_hashdb_save_enabled', @g_res_save_databases, 'enable saving map/resource hash databases to disk', 'controls storing hash databases to disk');