hedgewars/uPhysFSLayer.pas
branchwebgl
changeset 8833 c13ebed437cb
parent 8330 aaefa587e277
parent 8714 ab201a62d115
child 8839 caa57115d7ea
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
     1 unit uPhysFSLayer;
     1 unit uPhysFSLayer;
     2 
     2 
     3 interface
     3 interface
     4 uses SDLh, LuaPas;
     4 uses SDLh, LuaPas;
     5 
     5 
     6 {$IFDEF ANDROID}
     6 const PhysfsLibName = {$IFDEF PHYSFS_INTERNAL}'libhw_physfs'{$ELSE}'libphysfs'{$ENDIF};
       
     7 const PhyslayerLibName = 'libphyslayer';
       
     8 
       
     9 {$IFNDEF WIN32}
     7     {$linklib physfs}
    10     {$linklib physfs}
     8 {$ELSE}
    11     {$linklib physlayer}
     9     {$IFDEF DARWIN}
    12     {$IFDEF DARWIN}
    10         {$LINKFRAMEWORK IOKit}
    13         {$linkframework IOKit}
    11     {$ENDIF}
    14     {$ENDIF}
    12 {$ENDIF}
       
    13 
       
    14 const
       
    15 {$IFDEF WIN32}
       
    16     PhysfsLibName = 'libphysfs';
       
    17 {$ELSE}
       
    18     PhysfsLibName = 'physfs';
       
    19 {$ENDIF}
    15 {$ENDIF}
    20 
    16 
    21 procedure initModule;
    17 procedure initModule;
    22 procedure freeModule;
    18 procedure freeModule;
    23 
    19 
    34 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
    30 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
    35 function pfsEOF(f: PFSFile): boolean;
    31 function pfsEOF(f: PFSFile): boolean;
    36 
    32 
    37 function pfsExists(fname: shortstring): boolean;
    33 function pfsExists(fname: shortstring): boolean;
    38 
    34 
    39 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhysfsLibName;
    35 function  physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhyslayerLibName;
    40 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName;
    36 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhyslayerLibName;
    41 
    37 
    42 {$IFNDEF PAS2C}
    38 {$IFNDEF PAS2C}
    43 //apparently pas2c doesn't render the functions below if it finds 'implementation' first
    39 //apparently pas2c doesn't render the functions below if it finds 'implementation' first
    44 implementation
    40 implementation
    45 uses uUtils, uVariables, sysutils;
    41 uses uUtils, uVariables, sysutils;
    46 {$ENDIF}
    42 {$ENDIF}
    47 
    43 
    48 function PHYSFS_init(argv: PChar): LongInt; cdecl; external PhysfsLibName;
    44 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName;
    49 function PHYSFS_deinit: LongInt; cdecl; external PhysfsLibName;
    45 function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName;
    50 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName;
    46 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhyslayerLibName;
    51 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName;
    47 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhyslayerLibName;
    52 
    48 
    53 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName;
    49 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName;
    54 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
    50 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName;
    55 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    51 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    56 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
    52 function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName;
    57 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    53 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
    58 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
    54 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
    59 
    55 
    60 procedure hedgewarsMountPackages; cdecl; external PhysfsLibName;
    56 procedure hedgewarsMountPackages(); cdecl; external PhyslayerLibName;
    61 
    57 
    62 {$IFDEF PAS2C}
    58 {$IFDEF PAS2C}
    63 implementation
    59 implementation
    64 uses uUtils, uVariables;
    60 uses uUtils, uVariables;
    65 {$ENDIF}
    61 {$ENDIF}
   155 {$ENDIF}
   151 {$ENDIF}
   156 
   152 
   157     i:= PHYSFS_init(Str2PChar(cPhysfsId));
   153     i:= PHYSFS_init(Str2PChar(cPhysfsId));
   158     AddFileLog('[PhysFS] init: ' + inttostr(i));
   154     AddFileLog('[PhysFS] init: ' + inttostr(i));
   159 
   155 
   160     i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true);
   156     i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, false);
   161     AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
   157     AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
   162     i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true);
   158     i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, false);
   163     AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
   159     AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
   164 
   160 
   165     hedgewarsMountPackages;
   161     hedgewarsMountPackages;
   166 end;
   162 end;
   167 
   163