hedgewars/uPhysFSLayer.pas
changeset 9994 8455993a7a1b
parent 9993 76ad55807c24
child 9996 d93fb04619ee
--- a/hedgewars/uPhysFSLayer.pas	Thu Jan 16 17:18:53 2014 +0100
+++ b/hedgewars/uPhysFSLayer.pas	Thu Jan 16 19:50:18 2014 +0100
@@ -3,6 +3,8 @@
 interface
 uses SDLh, LuaPas;
 
+{$INCLUDE "config.inc"}
+
 const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhwphysfs'{$ELSE}'libphysfs'{$ENDIF};
 const PhyslayerLibName = 'libphyslayer';
 
@@ -31,7 +33,6 @@
 
 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
-procedure pfsPermitSymbolicLinks(allow: boolean);
 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
 
 implementation
@@ -42,8 +43,6 @@
 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhyslayerLibName;
 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
 
-procedure PHYSFS_permitSymbolicLinks(allow: boolean); cdecl; external PhysfsLibName;
-
 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
@@ -131,27 +130,23 @@
         pfsBlockRead:= r
 end;
 
-procedure pfsPermitSymbolicLinks(allow: boolean);
-begin
-    PHYSFS_permitSymbolicLinks(allow);
-end;
-
 procedure pfsMount(path: AnsiString; mountpoint: PChar);
 begin
     if PHYSFS_mount(Str2PChar(path), mountpoint, false) then
-        AddFileLog('[PhysFS] mount ' + path + ': ok')
+        AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : ok')
     else
-        AddFileLog('[PhysFS] mount ' + path + ': FAILED ("' + PHYSFS_getLastError() + '")');
+        AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : FAILED ("' + PHYSFS_getLastError() + '")');
 end;
 
 procedure pfsMountAtRoot(path: AnsiString);
 begin
-    pfsMount(path, nil);
+    pfsMount(path, '/');
 end;
 
 procedure initModule;
 var i: LongInt;
     cPhysfsId: shortstring;
+    fp: AnsiString;
 begin
 {$IFDEF HWLIBRARY}
     //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
@@ -163,6 +158,25 @@
     i:= PHYSFS_init(Str2PChar(cPhysfsId));
     AddFileLog('[PhysFS] init: ' + inttostr(i));
 
+    // mount system fonts paths first
+    fp := cFontsPaths;
+
+    // let's remove paths from fp and mount them until nothing is left
+    while length(fp) > 0 do
+        begin
+        AddFileLog('lol');
+        // search for ;
+        i := pos(';', fp);
+        // if there is no ; left, read to end
+        if i < 1 then
+            i := length(fp) + 1;
+        // don't mount empty path
+        if i > 2 then
+            pfsMount(copy(fp, 1, i-1), '/Fonts');
+        // remove mounted path from fp
+        fp := copy(fp, i+1, length(fp)-i);
+        end;
+
     pfsMountAtRoot(PathPrefix);
     pfsMountAtRoot(UserPathPrefix + '/Data');
 
@@ -176,9 +190,6 @@
             pfsMountAtRoot(ExtractFileDir(cScriptName));
             cScriptName := ExtractFileName(cScriptName);
         end;
-
-    // mounts fonts last - don't allow overwriting them as we allow symlinks there
-    pfsMount(PathPrefix + '/Fonts', '/Fonts');
 end;
 
 procedure freeModule;