fd2d90b9d4d541c4275dc644a211c0e15b6f4c35
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
33 implementation
37 var
38 // cvars
41 // other vars
45 //==========================================================================
46 //
47 // getWord
48 //
49 // get next word from a string
50 // words are delimited with ';'
51 // ignores leading and trailing spaces
52 // returns empty string if there are no more words
53 //
54 //==========================================================================
56 var
58 begin
61 begin
62 if (ord(list[1]) <= 32) or (list[1] = ';') or (list[1] = ':') then begin Delete(list, 1, 1); continue; end;
67 while (length(result) > 0) and (ord(result[length(result)]) <= 32) do Delete(result, length(result), 1);
73 //==========================================================================
74 //
75 // isIgnoredResWad
76 //
77 // checks if the given resource wad can be ignored
78 //
79 // FIXME: preparse name list?
80 //
81 //==========================================================================
83 var
86 begin
93 begin
95 //writeln('*** name=[', name, ']; fname=[', fname, ']');
102 //==========================================================================
103 //
104 // clearReplacementWads
105 //
106 // call this before downloading a new map from a server
107 //
108 //==========================================================================
110 begin
116 //==========================================================================
117 //
118 // addReplacementWad
119 //
120 // register new replacement wad
121 //
122 //==========================================================================
124 begin
131 //==========================================================================
132 //
133 // g_Res_FindReplacementWad
134 //
135 // returns original name, or replacement name
136 //
137 //==========================================================================
139 var
141 begin
142 //e_LogWritefln('LOOKING for replacement wad for [%s]...', [oldname], TMsgType.Notify);
146 begin
147 //e_LogWritefln('found replacement wad for [%s] -> [%s]', [oldname, fn], TMsgType.Notify);
153 //==========================================================================
154 //
155 // scanDir
156 //
157 // look for a wad to match the hash
158 // scans subdirs, ignores known wad extensions
159 //
160 // returns found wad disk name, or empty string
161 //
162 //==========================================================================
163 function scanDir (dirName: AnsiString; baseName: AnsiString; const resMd5: TMD5Digest): AnsiString;
164 var
170 begin
177 // scan files
179 try
180 repeat
182 begin
184 begin
187 begin
191 begin
195 exit;
199 end
200 else
201 begin
203 begin
210 finally
214 // scan subdirs
216 begin
225 //==========================================================================
226 //
227 // findExistingMapWadWithHash
228 //
229 // find map or resource wad using its base name and hash
230 //
231 // returns found wad disk name, or empty string
232 //
233 //==========================================================================
235 begin
240 //==========================================================================
241 //
242 // findExistingResWadWithHash
243 //
244 // find map or resource wad using its base name and hash
245 //
246 // returns found wad disk name, or empty string
247 //
248 //==========================================================================
250 begin
255 //==========================================================================
256 //
257 // g_Res_DownloadMapWAD
258 //
259 // download map wad from server (if necessary)
260 // download all required map resource wads too
261 // registers all required replacement wads
262 //
263 // returns name of the map wad (relative to mapdir), or empty string on error
264 //
265 //==========================================================================
267 var
275 begin
281 try
293 // find or download a map
296 begin
297 // download map
300 begin
303 exit;
305 try
307 except
310 try
312 except
315 exit;
318 try
320 except
324 exit;
328 begin
331 exit;
333 // if it was resumed, check md5 and initiate full download if necessary
335 begin
337 // sorry for pasta, i am asshole
339 begin
341 try
344 except
347 exit;
349 try
351 except
355 exit;
359 begin
362 exit;
369 // download resources
371 begin
375 begin
376 // ignored file, abort download
379 continue;
383 begin
384 // already here
387 end
388 else
389 begin
390 try
392 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
425 e_LogWritefln('resuming failed; downloading resource `%s` to `%s` from scratch...', [tf.diskName, fname]);
426 try
429 except
432 exit;
434 try
436 except
440 exit;
444 begin
447 exit;
454 finally
461 initialization
462 conRegVar('rdl_ignore_names', @g_res_ignore_names, 'list of resource wad names (without extensions) to ignore in dl hash checks', 'dl ignore wads');
463 conRegVar('rdl_ignore_enabled', @g_res_ignore_enabled, 'enable dl hash check ignore list', 'dl hash check ignore list active');