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