7959
|
1 |
unit uPhysFSLayer;
|
|
2 |
|
|
3 |
{$LINKLIB ../bin/libphysfs.a}
|
8022
|
4 |
{$LINKLIB ../bin/libphysfsrwops.a}
|
7959
|
5 |
|
|
6 |
interface
|
8022
|
7 |
uses SDLh;
|
7959
|
8 |
|
|
9 |
procedure initModule;
|
|
10 |
procedure freeModule;
|
|
11 |
|
8028
|
12 |
type PFSFile = pointer;
|
|
13 |
|
8025
|
14 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops;
|
|
15 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
|
8022
|
16 |
|
8028
|
17 |
function pfsOpenRead(fname: shortstring): PFSFile;
|
|
18 |
function pfsClose(f: PFSFile): boolean;
|
|
19 |
|
|
20 |
procedure pfsReadLn(f: PFSFile; var s: shortstring);
|
8031
|
21 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
|
|
22 |
function pfsEOF(f: PFSFile): boolean;
|
|
23 |
|
|
24 |
function pfsExists(fname: shortstring): boolean;
|
8028
|
25 |
|
7959
|
26 |
implementation
|
8022
|
27 |
uses uUtils, uVariables;
|
7959
|
28 |
|
|
29 |
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external;
|
|
30 |
function PHYSFS_deinit() : LongInt; cdecl; external;
|
8025
|
31 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external;
|
|
32 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external;
|
7959
|
33 |
|
7963
|
34 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external;
|
8028
|
35 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external;
|
|
36 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external;
|
8034
|
37 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external;
|
8028
|
38 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external;
|
8031
|
39 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external;
|
7959
|
40 |
|
8025
|
41 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops;
|
|
42 |
begin
|
|
43 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
|
|
44 |
end;
|
|
45 |
|
|
46 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
|
7959
|
47 |
begin
|
8025
|
48 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname)));
|
|
49 |
end;
|
8022
|
50 |
|
8028
|
51 |
function pfsOpenRead(fname: shortstring): PFSFile;
|
|
52 |
begin
|
|
53 |
exit(PHYSFS_openRead(Str2PChar(fname)));
|
|
54 |
end;
|
|
55 |
|
|
56 |
function pfsEOF(f: PFSFile): boolean;
|
|
57 |
begin
|
|
58 |
exit(PHYSFS_eof(f))
|
|
59 |
end;
|
|
60 |
|
|
61 |
function pfsClose(f: PFSFile): boolean;
|
|
62 |
begin
|
|
63 |
exit(PHYSFS_close(f))
|
|
64 |
end;
|
|
65 |
|
8031
|
66 |
function pfsExists(fname: shortstring): boolean;
|
|
67 |
begin
|
|
68 |
exit(PHYSFS_exists(Str2PChar(fname)))
|
|
69 |
end;
|
|
70 |
|
8028
|
71 |
|
|
72 |
procedure pfsReadLn(f: PFSFile; var s: shortstring);
|
|
73 |
var c: char;
|
|
74 |
begin
|
|
75 |
s[0]:= #0;
|
|
76 |
|
8034
|
77 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do
|
8028
|
78 |
if (c <> #13) and (s[0] < #255) then
|
|
79 |
begin
|
|
80 |
inc(s[0]);
|
|
81 |
s[byte(s[0])]:= c
|
|
82 |
end
|
|
83 |
end;
|
|
84 |
|
8031
|
85 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
|
|
86 |
var r: Int64;
|
|
87 |
begin
|
8034
|
88 |
r:= PHYSFS_readBytes(f, buf, size);
|
8031
|
89 |
|
|
90 |
if r <= 0 then
|
|
91 |
pfsBlockRead:= 0
|
|
92 |
else
|
|
93 |
pfsBlockRead:= r
|
|
94 |
end;
|
|
95 |
|
8025
|
96 |
procedure initModule;
|
|
97 |
var i: LongInt;
|
|
98 |
begin
|
|
99 |
i:= PHYSFS_init(Str2PChar(ParamStr(0)));
|
|
100 |
AddFileLog('[PhysFS] init: ' + inttostr(i));
|
|
101 |
|
|
102 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true);
|
|
103 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
|
8031
|
104 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true);
|
8046
|
105 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
|
7959
|
106 |
end;
|
|
107 |
|
|
108 |
procedure freeModule;
|
|
109 |
begin
|
|
110 |
PHYSFS_deinit;
|
|
111 |
end;
|
|
112 |
|
|
113 |
end.
|