hedgewars/uPhysFSLayer.pas
changeset 10129 cd2a64a1f4aa
parent 10127 7f29a65aa1e4
child 10424 4be6cd55f1cf
child 10564 0cb20aa8877a
equal deleted inserted replaced
10128:0f6878b5395a 10129:cd2a64a1f4aa
       
     1 {$INCLUDE "options.inc"}
       
     2 
     1 unit uPhysFSLayer;
     3 unit uPhysFSLayer;
     2 
     4 
     3 interface
     5 interface
     4 uses SDLh, LuaPas;
     6 uses SDLh, LuaPas;
     5 
     7 
    27 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
    29 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
    28 function pfsEOF(f: PFSFile): boolean;
    30 function pfsEOF(f: PFSFile): boolean;
    29 
    31 
    30 function pfsExists(fname: shortstring): boolean;
    32 function pfsExists(fname: shortstring): boolean;
    31 
    33 
    32 {$IFNDEF PAS2C}
       
    33 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
    34 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
    34 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
    35 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
    35 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
    36 procedure hedgewarsMountPackage(filename: PChar); cdecl; external PhyslayerLibName;
    36 {$ENDIF}
       
    37 
    37 
    38 implementation
    38 implementation
    39 uses uConsts, uUtils, uVariables{$IFNDEF PAS2C}, sysutils{$ENDIF};
    39 uses uConsts, uUtils, uVariables{$IFNDEF PAS2C}, sysutils{$ELSE}, physfs{$ENDIF};
    40 
    40 
    41 {$IFNDEF PAS2C}
       
    42 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
       
    43 function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
       
    44 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
    41 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
    45 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
    42 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
    46 
    43 procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName;
       
    44 {$IFNDEF PAS2C}
       
    45 function PHYSFS_init(argv0: PChar): LongInt; cdecl; external PhysfsLibName;
       
    46 function PHYSFS_deinit(): LongInt; cdecl; external PhysfsLibName;
    47 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
    47 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongBool; cdecl; external PhysfsLibName;
    48 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
    48 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
    49 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    49 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    50 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
    50 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
    51 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    51 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    52 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
    52 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
    53 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName;
    53 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName;
    54 
    54 {$ELSE}
    55 procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName;
    55 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64;
       
    56 begin
       
    57     PHYSFS_readBytes:= PHYSFS_read(f, buffer, 1, len);
       
    58 end;
    56 {$ENDIF}
    59 {$ENDIF}
    57 
    60 
    58 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    61 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    59 begin
    62 begin
    60     exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
    63     exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
   140         AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
   143         AddFileLog('[PhysFS] mount ' + shortstring(path) + ' at ' + shortstring(mountpoint) + ' : FAILED ("' + shortstring(PHYSFS_getLastError()) + '")');
   141 end;
   144 end;
   142 
   145 
   143 procedure pfsMountAtRoot(path: ansistring);
   146 procedure pfsMountAtRoot(path: ansistring);
   144 begin
   147 begin
   145     pfsMount(path, PChar('/'));
   148     pfsMount(path, PChar(_S'/'));
   146 end;
   149 end;
   147 
   150 
   148 procedure initModule;
   151 procedure initModule;
   149 var i: LongInt;
   152 var i: LongInt;
   150     cPhysfsId: shortstring;
   153     cPhysfsId: shortstring;