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 |
|
8052
|
41 |
procedure hedgewarsMountPackages(); cdecl; external;
|
|
42 |
|
8025
|
43 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops;
|
|
44 |
begin
|
|
45 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname)));
|
|
46 |
end;
|
|
47 |
|
|
48 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
|
7959
|
49 |
begin
|
8025
|
50 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname)));
|
|
51 |
end;
|
8022
|
52 |
|
8028
|
53 |
function pfsOpenRead(fname: shortstring): PFSFile;
|
|
54 |
begin
|
|
55 |
exit(PHYSFS_openRead(Str2PChar(fname)));
|
|
56 |
end;
|
|
57 |
|
|
58 |
function pfsEOF(f: PFSFile): boolean;
|
|
59 |
begin
|
|
60 |
exit(PHYSFS_eof(f))
|
|
61 |
end;
|
|
62 |
|
|
63 |
function pfsClose(f: PFSFile): boolean;
|
|
64 |
begin
|
|
65 |
exit(PHYSFS_close(f))
|
|
66 |
end;
|
|
67 |
|
8031
|
68 |
function pfsExists(fname: shortstring): boolean;
|
|
69 |
begin
|
|
70 |
exit(PHYSFS_exists(Str2PChar(fname)))
|
|
71 |
end;
|
|
72 |
|
8028
|
73 |
|
|
74 |
procedure pfsReadLn(f: PFSFile; var s: shortstring);
|
|
75 |
var c: char;
|
|
76 |
begin
|
|
77 |
s[0]:= #0;
|
|
78 |
|
8034
|
79 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do
|
8028
|
80 |
if (c <> #13) and (s[0] < #255) then
|
|
81 |
begin
|
|
82 |
inc(s[0]);
|
|
83 |
s[byte(s[0])]:= c
|
|
84 |
end
|
|
85 |
end;
|
|
86 |
|
8031
|
87 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
|
|
88 |
var r: Int64;
|
|
89 |
begin
|
8034
|
90 |
r:= PHYSFS_readBytes(f, buf, size);
|
8031
|
91 |
|
|
92 |
if r <= 0 then
|
|
93 |
pfsBlockRead:= 0
|
|
94 |
else
|
|
95 |
pfsBlockRead:= r
|
|
96 |
end;
|
|
97 |
|
8025
|
98 |
procedure initModule;
|
|
99 |
var i: LongInt;
|
|
100 |
begin
|
|
101 |
i:= PHYSFS_init(Str2PChar(ParamStr(0)));
|
|
102 |
AddFileLog('[PhysFS] init: ' + inttostr(i));
|
|
103 |
|
|
104 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true);
|
|
105 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
|
8031
|
106 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true);
|
8046
|
107 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
|
8052
|
108 |
|
|
109 |
hedgewarsMountPackages;
|
7959
|
110 |
end;
|
|
111 |
|
|
112 |
procedure freeModule;
|
|
113 |
begin
|
|
114 |
PHYSFS_deinit;
|
|
115 |
end;
|
|
116 |
|
|
117 |
end.
|