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
377 try
386 // this also sends map request
390 // find or download a map
393 begin
394 // download map
397 begin
400 exit;
402 try
404 except
407 begin
410 exit;
415 try
417 except
420 exit;
422 try
424 except
428 exit;
432 begin
435 exit;
437 // if it was resumed, check md5 and initiate full download if necessary
439 begin
441 // sorry for pasta, i am asshole
443 begin
445 try
448 except
451 exit;
453 try
455 except
459 exit;
463 begin
466 exit;
474 // download resources
476 begin
477 // if we got a new-style reslist packet, use received data to check for resource files
479 begin
480 // old-style packet
484 end
485 else
486 begin
487 // new-style packet
494 begin
495 // ignored file, abort download
498 continue;
502 begin
503 // already here
506 end
507 else
508 begin
510 begin
514 try
516 except
519 begin
522 exit;
526 try
528 except
531 exit;
533 try
535 except
539 exit;
543 begin
546 exit;
548 // if it was resumed, check md5 and initiate full download if necessary
550 begin
552 // sorry for pasta, i am asshole
554 begin
555 e_LogWritefln('resuming failed; downloading resource `%s` to `%s` from scratch...', [tf.diskName, fname]);
556 try
559 except
562 exit;
564 try
566 except
570 exit;
574 begin
577 exit;
585 finally
590 if saveDBsToDiskEnabled and (mapdbUpdated or resdbUpdated) then saveDatabases(mapdbUpdated, resdbUpdated);
594 initialization
595 conRegVar('rdl_ignore_names', @g_res_ignore_names, 'list of resource wad names (without extensions) to ignore in dl hash checks', 'dl ignore wads');
596 conRegVar('rdl_ignore_enabled', @g_res_ignore_enabled, 'enable dl hash check ignore list', 'dl hash check ignore list active');
597 conRegVar('rdl_hashdb_save_enabled', @g_res_save_databases, 'enable saving map/resource hash databases to disk', 'controls storing hash databases to disk');