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