20 |
20 |
21 function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
21 function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
22 function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
22 function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
23 |
23 |
24 function pfsOpenRead(fname: shortstring): PFSFile; |
24 function pfsOpenRead(fname: shortstring): PFSFile; |
|
25 function pfsOpenWrite(fname: shortstring): PFSFile; |
|
26 function pfsFlush(f: PFSFile): boolean; |
25 function pfsClose(f: PFSFile): boolean; |
27 function pfsClose(f: PFSFile): boolean; |
26 |
28 |
27 procedure pfsReadLn(f: PFSFile; var s: shortstring); |
29 procedure pfsReadLn(f: PFSFile; var s: shortstring); |
28 procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
30 procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
|
31 procedure pfsWriteLn(f: PFSFile; s: shortstring); |
29 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
32 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
30 function pfsEOF(f: PFSFile): boolean; |
33 function pfsEOF(f: PFSFile): boolean; |
31 |
34 |
32 function pfsExists(fname: shortstring): boolean; |
35 function pfsExists(fname: shortstring): boolean; |
|
36 function pfsMakeDir(path: shortstring): boolean; |
33 |
37 |
34 function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName; |
38 function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName; |
35 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName; |
39 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName; |
36 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName; |
40 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName; |
37 |
41 |
44 {$IFNDEF PAS2C} |
48 {$IFNDEF PAS2C} |
45 function PHYSFS_init(argv0: PChar): LongInt; cdecl; external PhysfsLibName; |
49 function PHYSFS_init(argv0: PChar): LongInt; cdecl; external PhysfsLibName; |
46 function PHYSFS_deinit(): LongInt; cdecl; external PhysfsLibName; |
50 function PHYSFS_deinit(): LongInt; cdecl; external PhysfsLibName; |
47 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName; |
51 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName; |
48 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
52 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
53 function PHYSFS_openWrite(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
54 function PHYSFS_setWriteDir(path: PChar): LongBool; cdecl; external PhysfsLibName; |
49 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
55 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
50 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
56 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
57 function PHYSFS_writeBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
58 function PHYSFS_seek(f: PFSFile; pos: QWord): LongBool; cdecl; external PhysfsLibName; |
|
59 function PHYSFS_flush(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
51 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
60 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
52 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
61 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
62 function PHYSFS_mkdir(path: PChar): LongBool; cdecl; external PhysfsLibName; |
53 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName; |
63 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName; |
|
64 function PHYSFS_enumerateFiles(dir: PChar): PPChar; cdecl; external PhysfsLibName; |
|
65 procedure PHYSFS_freeList(list: PPChar); cdecl; external PhysfsLibName; |
54 {$ELSE} |
66 {$ELSE} |
55 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; |
67 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; |
56 begin |
68 begin |
57 PHYSFS_readBytes:= PHYSFS_read(f, buffer, 1, len); |
69 PHYSFS_readBytes:= PHYSFS_read(f, buffer, 1, len); |
58 end; |
70 end; |
71 function pfsOpenRead(fname: shortstring): PFSFile; |
83 function pfsOpenRead(fname: shortstring): PFSFile; |
72 begin |
84 begin |
73 exit(PHYSFS_openRead(Str2PChar(fname))); |
85 exit(PHYSFS_openRead(Str2PChar(fname))); |
74 end; |
86 end; |
75 |
87 |
|
88 function pfsOpenWrite(fname: shortstring): PFSFile; |
|
89 begin |
|
90 exit(PHYSFS_openWrite(Str2PChar(fname))); |
|
91 end; |
|
92 |
76 function pfsEOF(f: PFSFile): boolean; |
93 function pfsEOF(f: PFSFile): boolean; |
77 begin |
94 begin |
78 exit(PHYSFS_eof(f)) |
95 exit(PHYSFS_eof(f)) |
79 end; |
96 end; |
80 |
97 |
|
98 function pfsFlush(f: PFSFile): boolean; |
|
99 begin |
|
100 exit(PHYSFS_flush(f)) |
|
101 end; |
|
102 |
81 function pfsClose(f: PFSFile): boolean; |
103 function pfsClose(f: PFSFile): boolean; |
82 begin |
104 begin |
83 exit(PHYSFS_close(f)) |
105 exit(PHYSFS_close(f)) |
84 end; |
106 end; |
85 |
107 |
86 function pfsExists(fname: shortstring): boolean; |
108 function pfsExists(fname: shortstring): boolean; |
87 begin |
109 begin |
88 exit(PHYSFS_exists(Str2PChar(fname))) |
110 exit(PHYSFS_exists(Str2PChar(fname))) |
89 end; |
111 end; |
90 |
112 |
|
113 function pfsMakeDir(path: shortstring): boolean; |
|
114 begin |
|
115 exit(PHYSFS_mkdir(Str2PChar(path))) |
|
116 end; |
|
117 |
|
118 function pfsEnumerateFiles(dir: shortstring): PPChar; |
|
119 begin |
|
120 exit(PHYSFS_enumerateFiles(Str2PChar(dir))) |
|
121 end; |
|
122 |
|
123 procedure pfsFreeList(list: PPChar); |
|
124 begin |
|
125 PHYSFS_freeList(list) |
|
126 end; |
91 |
127 |
92 procedure pfsReadLn(f: PFSFile; var s: shortstring); |
128 procedure pfsReadLn(f: PFSFile; var s: shortstring); |
93 var c: char; |
129 var c: char; |
94 begin |
130 begin |
95 s[0]:= #0; |
131 s[0]:= #0; |
122 end; |
158 end; |
123 |
159 |
124 s:= s + ansistring(b) |
160 s:= s + ansistring(b) |
125 end; |
161 end; |
126 |
162 |
|
163 procedure pfsWriteLn(f: PFSFile; s: shortstring); |
|
164 var c: char; |
|
165 begin |
|
166 c:= #10; |
|
167 PHYSFS_writeBytes(f, @s[1], byte(s[0])); |
|
168 PHYSFS_writeBytes(f, @c, 1); |
|
169 end; |
|
170 |
127 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
171 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
128 var r: Int64; |
172 var r: Int64; |
129 begin |
173 begin |
130 r:= PHYSFS_readBytes(f, buf, size); |
174 r:= PHYSFS_readBytes(f, buf, size); |
131 |
175 |
174 pfsMount(ansistring(fp), _P'/Fonts'); |
218 pfsMount(ansistring(fp), _P'/Fonts'); |
175 end; |
219 end; |
176 {$ENDIF} |
220 {$ENDIF} |
177 |
221 |
178 pfsMountAtRoot(localPrefix); |
222 pfsMountAtRoot(localPrefix); |
|
223 pfsMount(userPrefix, PChar('/Config')); |
|
224 pfsMakeDir('/Config/Data'); |
|
225 pfsMakeDir('/Config/Logs'); |
179 pfsMountAtRoot(userPrefix + ansistring('/Data')); |
226 pfsMountAtRoot(userPrefix + ansistring('/Data')); |
|
227 PHYSFS_setWriteDir(userPrefix); |
180 |
228 |
181 hedgewarsMountPackages; |
229 hedgewarsMountPackages; |
182 |
230 |
183 // need access to teams and frontend configs (for bindings) |
231 // need access to teams and frontend configs (for bindings) |
184 pfsMountAtRoot(userPrefix); |
232 pfsMountAtRoot(userPrefix); |