e2f888955076063cf022a58d1c3bda40b2be01ce
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 {--- append dirs to 'path.wad:\file'. if disk is void, append defWad ---}
54 {--- same as SysUtils.FinFirst ---}
55 function e_FindFirst (dirs: SSArray; name: AnsiString; attr: LongInt; out Rslt: TSearchRec): LongInt;
57 {--- try to get a writeable directory from list, throws if no one directory created ---}
58 {--- (unless `required` is `false`: in this case, returns empty string) ---}
59 {--- creates all necessary subdirs, if it can ---}
62 implementation
66 type
69 var
75 begin
83 begin
87 begin
90 begin
93 begin
96 begin
100 end
101 end
102 end
103 else
104 begin
106 end
107 end
111 begin
116 begin
120 function SpawnStream (dirs: SSArray; name: AnsiString; p: SpawnProc; createNewDir: Boolean): TStream;
122 begin
128 begin
129 try
134 finally
136 end
137 end
141 begin
150 begin
159 begin
168 begin
170 result := b
172 result := a
173 else
177 function e_FindResource (dirs: SSArray; var name: AnsiString; nameIsDir: Boolean = false): Boolean;
179 begin
187 begin
202 begin
210 begin
215 end
220 begin
235 function e_FindFirst (dirs: SSArray; name: AnsiString; attr: LongInt; out Rslt: TSearchRec): LongInt;
237 begin
244 begin
250 end
253 // k8: sorry. i know that this sux, but checking directory access rights is unreliable (unportable).
255 var
260 begin
263 begin
266 begin
268 continue;
271 try
277 begin
282 exit;
287 var
289 begin
293 begin
295 begin
297 begin
298 //writeln('*** KNOWN WRITEABLE DIR: "', result, '"');
299 exit;
304 begin
305 try
307 begin
310 begin
312 begin
315 //writeln('*** NEW WRITEABLE DIR: "', result, '" ("', dirs[f], '"); rq=', required);
316 exit;
323 if required then raise Exception.Create(Format('unable to create directory "%s"', [dirs[High(dirs)]]));