hedgewars/uPhysFSLayer.pas
branchphysfslayer
changeset 8028 dc30104660d3
parent 8025 07862ab415c8
child 8031 fc40b343c45c
equal deleted inserted replaced
8025:07862ab415c8 8028:dc30104660d3
     7 uses SDLh;
     7 uses SDLh;
     8 
     8 
     9 procedure initModule;
     9 procedure initModule;
    10 procedure freeModule;
    10 procedure freeModule;
    11 
    11 
       
    12 type PFSFile = pointer;
       
    13 
    12 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    14 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    13 function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
    15 function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
       
    16 
       
    17 function pfsOpenRead(fname: shortstring): PFSFile;
       
    18 function pfsEOF(f: PFSFile): boolean;
       
    19 function pfsClose(f: PFSFile): boolean;
       
    20 
       
    21 procedure pfsReadLn(f: PFSFile; var s: shortstring);
    14 
    22 
    15 implementation
    23 implementation
    16 uses uUtils, uVariables;
    24 uses uUtils, uVariables;
    17 
    25 
    18 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external;
    26 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external;
    19 function PHYSFS_deinit() : LongInt; cdecl; external;
    27 function PHYSFS_deinit() : LongInt; cdecl; external;
    20 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external;
    28 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external;
    21 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external;
    29 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external;
    22 
    30 
    23 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external;
    31 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external;
       
    32 function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external;
       
    33 function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external;
       
    34 function PHYSFS_read(f: PFSFile; buf: pointer; objSize, objCount: Longword): Int64; cdecl; external;
       
    35 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external;
    24 
    36 
    25 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    37 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
    26 begin
    38 begin
    27     exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
    39     exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
    28 end;
    40 end;
    29 
    41 
    30 function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
    42 function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
    31 begin
    43 begin
    32     exit(PHYSFSRWOPS_openWrite(Str2PChar(fname)));
    44     exit(PHYSFSRWOPS_openWrite(Str2PChar(fname)));
       
    45 end;
       
    46 
       
    47 function pfsOpenRead(fname: shortstring): PFSFile;
       
    48 begin
       
    49     exit(PHYSFS_openRead(Str2PChar(fname)));
       
    50 end;
       
    51 
       
    52 function pfsEOF(f: PFSFile): boolean;
       
    53 begin
       
    54     exit(PHYSFS_eof(f))
       
    55 end;
       
    56 
       
    57 function pfsClose(f: PFSFile): boolean;
       
    58 begin
       
    59     exit(PHYSFS_close(f))
       
    60 end;
       
    61 
       
    62 
       
    63 procedure pfsReadLn(f: PFSFile; var s: shortstring);
       
    64 var c: char;
       
    65 begin
       
    66 s[0]:= #0;
       
    67 
       
    68 while (PHYSFS_read(f, @c, 1, 1) = 1) and (c <> #10) do
       
    69     if (c <> #13) and (s[0] < #255) then
       
    70         begin
       
    71         inc(s[0]);
       
    72         s[byte(s[0])]:= c
       
    73         end
    33 end;
    74 end;
    34 
    75 
    35 procedure initModule;
    76 procedure initModule;
    36 var i: LongInt;
    77 var i: LongInt;
    37 begin
    78 begin