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 {$I ../shared/a_modes.inc}
18 interface
22 var
25 {-------------------------------------------}
26 {--- insert separator beetwin a and b ---}
27 {--- result are correct if (a or b) = '' ---}
28 {--- - - - - - - - - - - - - - - - - - - ---}
31 {--- remove last entry from path ---}
34 {--- not absolute and have no relative dirs ---}
37 {-----------------------------------------------------------------------}
38 {--- try to open/create file in one dir from `dirs` in reverse order ---}
39 {--- e_OpenResourceRW tries to create if not exists ---}
40 {--- create dirs if not exists ---}
41 {--- result <> nil, throws exceptions on errors ---}
42 {--- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ---}
47 {--- same as shared/utils ---}
48 function e_FindResource (dirs: SSArray; var name: AnsiString; nameIsDir: Boolean = false): Boolean;
51 {--- returns relative wad name; never empty string ---}
54 {--- prepend dirs to 'disk.wad:\file'. if empty disk string then prepend defWad ---}
55 {--- return empty string if error occured or 'path/to/disk.wad:\file' on success ---}
58 {--- same as SysUtils.FinFirst ---}
59 function e_FindFirst (dirs: SSArray; name: AnsiString; attr: LongInt; out Rslt: TSearchRec): LongInt;
61 {--- try to get a writeable directory from list, throws if no one directory created ---}
62 {--- (unless `required` is `false`: in this case, returns empty string) ---}
63 {--- creates all necessary subdirs, if it can ---}
68 implementation
72 type
75 var
81 begin
89 begin
93 begin
96 begin
99 begin
102 begin
106 end
107 end
108 end
109 else
110 begin
112 end
113 end
117 begin
122 begin
126 function SpawnStream (dirs: SSArray; name: AnsiString; p: SpawnProc; createNewDir: Boolean): TStream;
128 begin
134 begin
135 try
140 finally
142 end
143 end
147 begin
156 begin
165 begin
174 begin
176 result := b
178 result := a
179 else
183 function e_FindResource (dirs: SSArray; var name: AnsiString; nameIsDir: Boolean = false): Boolean;
185 begin
193 begin
208 begin
216 begin
221 end
225 var
229 begin
233 begin
244 begin
252 begin
266 function e_FindFirst (dirs: SSArray; name: AnsiString; attr: LongInt; out Rslt: TSearchRec): LongInt;
268 begin
275 begin
281 end
284 // k8: sorry. i know that this sux, but checking directory access rights is unreliable (unportable).
286 var
291 begin
294 begin
297 begin
299 continue;
302 try
308 begin
313 exit;
318 var
320 begin
324 begin
326 begin
328 begin
329 //writeln('*** KNOWN WRITEABLE DIR: "', result, '"');
330 exit;
335 begin
336 try
338 begin
341 begin
343 begin
346 //writeln('*** NEW WRITEABLE DIR: "', result, '" ("', dirs[f], '"); rq=', required);
347 exit;
354 if required then raise Exception.Create(Format('unable to create directory "%s"', [dirs[High(dirs)]]));