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 ---}
66 implementation
70 type
73 var
79 begin
87 begin
91 begin
94 begin
97 begin
100 begin
104 end
105 end
106 end
107 else
108 begin
110 end
111 end
115 begin
120 begin
124 function SpawnStream (dirs: SSArray; name: AnsiString; p: SpawnProc; createNewDir: Boolean): TStream;
126 begin
132 begin
133 try
138 finally
140 end
141 end
145 begin
154 begin
163 begin
172 begin
174 result := b
176 result := a
177 else
181 function e_FindResource (dirs: SSArray; var name: AnsiString; nameIsDir: Boolean = false): Boolean;
183 begin
191 begin
206 begin
214 begin
219 end
223 var
227 begin
231 begin
242 begin
250 begin
264 function e_FindFirst (dirs: SSArray; name: AnsiString; attr: LongInt; out Rslt: TSearchRec): LongInt;
266 begin
273 begin
279 end
282 // k8: sorry. i know that this sux, but checking directory access rights is unreliable (unportable).
284 var
289 begin
292 begin
295 begin
297 continue;
300 try
306 begin
311 exit;
316 var
318 begin
322 begin
324 begin
326 begin
327 //writeln('*** KNOWN WRITEABLE DIR: "', result, '"');
328 exit;
333 begin
334 try
336 begin
339 begin
341 begin
344 //writeln('*** NEW WRITEABLE DIR: "', result, '" ("', dirs[f], '"); rq=', required);
345 exit;
352 if required then raise Exception.Create(Format('unable to create directory "%s"', [dirs[High(dirs)]]));