hedgewars/uPhysFSLayer.pas
changeset 10127 7f29a65aa1e4
parent 10123 64e72781d344
child 10129 cd2a64a1f4aa
equal deleted inserted replaced
10126:2fa3bb7785ee 10127:7f29a65aa1e4
    34 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
    34 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
    35 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
    35 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
    36 {$ENDIF}
    36 {$ENDIF}
    37 
    37 
    38 implementation
    38 implementation
    39 uses uConsts, uUtils, uVariables, sysutils;
    39 uses uConsts, uUtils, uVariables{$IFNDEF PAS2C}, sysutils{$ENDIF};
    40 
    40 
    41 {$IFNDEF PAS2C}
    41 {$IFNDEF PAS2C}
    42 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
    42 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
    43 function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
    43 function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
    44 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
    44 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
   130         pfsBlockRead:= 0
   130         pfsBlockRead:= 0
   131     else
   131     else
   132         pfsBlockRead:= r
   132         pfsBlockRead:= r
   133 end;
   133 end;
   134 
   134 
   135 procedure pfsMount(path: AnsiString; mountpoint: PChar);
   135 procedure pfsMount(path: ansistring; mountpoint: PChar);
   136 begin
   136 begin
   137     if PHYSFS_mount(Str2PChar(path), mountpoint, false) then
   137     if PHYSFS_mount(PChar(path), mountpoint, false) then
   138         AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : ok')
   138         AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : ok')
   139     else
   139     else
   140         AddFileLog('[PhysFS] mount ' + path + ' at ' + mountpoint + ' : FAILED ("' + PHYSFS_getLastError() + '")');
   140         AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
   141 end;
   141 end;
   142 
   142 
   143 procedure pfsMountAtRoot(path: AnsiString);
   143 procedure pfsMountAtRoot(path: ansistring);
   144 begin
   144 begin
   145     pfsMount(path, '/');
   145     pfsMount(path, PChar('/'));
   146 end;
   146 end;
   147 
   147 
   148 procedure initModule;
   148 procedure initModule;
   149 var i: LongInt;
   149 var i: LongInt;
   150     cPhysfsId: shortstring;
   150     cPhysfsId: shortstring;
   163     // mount system fonts paths first
   163     // mount system fonts paths first
   164     for i:= low(cFontsPaths) to high(cFontsPaths) do
   164     for i:= low(cFontsPaths) to high(cFontsPaths) do
   165         begin
   165         begin
   166             fp := cFontsPaths[i];
   166             fp := cFontsPaths[i];
   167             if fp <> nil then
   167             if fp <> nil then
   168                 pfsMount(fp, '/Fonts');
   168                 pfsMount(ansistring(fp), PChar('/Fonts'));
   169         end;
   169         end;
   170 
   170 
   171     pfsMountAtRoot(PathPrefix);
   171     pfsMountAtRoot(PathPrefix);
   172     pfsMountAtRoot(UserPathPrefix + '/Data');
   172     pfsMountAtRoot(UserPathPrefix + ansistring('/Data'));
   173 
   173 
   174     hedgewarsMountPackages;
   174     hedgewarsMountPackages;
   175 
   175 
   176     // need access to teams and frontend configs (for bindings)
   176     // need access to teams and frontend configs (for bindings)
   177     pfsMountAtRoot(UserPathPrefix);
   177     pfsMountAtRoot(UserPathPrefix);