185 pfsBlockRead:= 0 |
185 pfsBlockRead:= 0 |
186 else |
186 else |
187 pfsBlockRead:= r |
187 pfsBlockRead:= r |
188 end; |
188 end; |
189 |
189 |
190 procedure pfsMount(path: ansistring; mountpoint: PChar); |
190 procedure pfsMount(path: PChar; mountpoint: PChar); |
191 begin |
191 begin |
192 if PHYSFS_mount(PChar(path), mountpoint, false) then |
192 PHYSFS_mount(path, mountpoint, false) |
193 //AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : ok') |
193 end; |
194 else |
194 |
195 //AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")'); |
195 procedure pfsMountAtRoot(path: PChar); |
196 end; |
|
197 |
|
198 procedure pfsMountAtRoot(path: ansistring); |
|
199 begin |
196 begin |
200 pfsMount(path, PChar(_S'/')); |
197 pfsMount(path, PChar(_S'/')); |
201 end; |
198 end; |
202 |
199 |
203 procedure initModule(localPrefix, userPrefix: PChar); |
200 procedure initModule(localPrefix, userPrefix: PChar); |
206 {$IFNDEF MOBILE} |
203 {$IFNDEF MOBILE} |
207 fp: PChar; |
204 fp: PChar; |
208 {$ENDIF} |
205 {$ENDIF} |
209 begin |
206 begin |
210 //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html |
207 //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html |
211 cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars'; |
208 cPhysfsId:= shortstring(GetCurrentDir()) + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars'; |
212 |
209 |
213 i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
210 i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
214 //AddFileLog('[PhysFS] init: ' + inttostr(i)); |
211 //AddFileLog('[PhysFS] init: ' + inttostr(i)); |
215 |
212 |
216 {$IFNDEF MOBILE} |
213 {$IFNDEF MOBILE} |
217 // mount system fonts paths first |
214 // mount system fonts paths first |
218 for i:= low(cFontsPaths) to high(cFontsPaths) do |
215 for i:= low(cFontsPaths) to high(cFontsPaths) do |
219 begin |
216 begin |
220 fp := cFontsPaths[i]; |
217 fp := cFontsPaths[i]; |
221 if fp <> nil then |
218 if fp <> nil then |
222 pfsMount(ansistring(fp), _P'/Fonts'); |
219 pfsMount(fp, _P'/Fonts'); |
223 end; |
220 end; |
224 {$ENDIF} |
221 {$ENDIF} |
225 |
222 |
226 pfsMountAtRoot(localPrefix); |
223 pfsMountAtRoot(localPrefix); |
227 pfsMount(userPrefix, PChar('/Config')); |
224 pfsMount(userPrefix, PChar('/Config')); |
228 pfsMakeDir('/Config/Data'); |
225 pfsMakeDir('/Config/Data'); |
229 pfsMakeDir('/Config/Logs'); |
226 pfsMakeDir('/Config/Logs'); |
230 pfsMountAtRoot(userPrefix + ansistring('/Data')); |
227 pfsMountAtRoot(Str2PChar(shortstring(userPrefix) + '/Data')); |
231 PHYSFS_setWriteDir(userPrefix); |
228 PHYSFS_setWriteDir(userPrefix); |
232 |
229 |
233 hedgewarsMountPackages; |
230 hedgewarsMountPackages; |
234 |
231 |
235 if cTestLua then |
232 if cTestLua then |
236 begin |
233 begin |
237 pfsMountAtRoot(ansistring(ExtractFileDir(cScriptName))); |
234 pfsMountAtRoot(Str2PChar(ExtractFileDir(cScriptName))); |
238 cScriptName := ExtractFileName(cScriptName); |
235 cScriptName := ExtractFileName(cScriptName); |
239 end; |
236 end; |
240 end; |
237 end; |
241 |
238 |
242 procedure freeModule; |
239 procedure freeModule; |