author | sheepluva |
Thu, 06 Dec 2012 11:14:21 +0100 | |
changeset 8262 | f01702bfb764 |
parent 8134 | 38e163cc3bfd |
child 8283 | af97cdbb7713 |
permissions | -rw-r--r-- |
7959 | 1 |
unit uPhysFSLayer; |
8063 | 2 |
|
7959 | 3 |
interface |
8077 | 4 |
uses SDLh, LuaPas; |
7959 | 5 |
|
8073 | 6 |
{$IFDEF ANDROID} |
7 |
{$linklib physfs} |
|
8 |
{$ELSE} |
|
9 |
{$IFDEF DARWIN} |
|
10 |
{$LINKFRAMEWORK IOKit} |
|
11 |
{$ENDIF} |
|
12 |
{$ENDIF} |
|
13 |
||
14 |
const |
|
15 |
{$IFDEF WIN32} |
|
16 |
PhysfsLibName = 'libphysfs'; |
|
17 |
{$ELSE} |
|
8134
38e163cc3bfd
unbreak linking pending some fix or other by koda. this is the same thing video recording still does.
nemo
parents:
8107
diff
changeset
|
18 |
{$LINKLIB ../bin/libphysfs.a} |
8073 | 19 |
PhysfsLibName = 'physfs'; |
20 |
{$ENDIF} |
|
21 |
||
7959 | 22 |
procedure initModule; |
23 |
procedure freeModule; |
|
24 |
||
8028 | 25 |
type PFSFile = pointer; |
26 |
||
8025 | 27 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
28 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
8022 | 29 |
|
8028 | 30 |
function pfsOpenRead(fname: shortstring): PFSFile; |
31 |
function pfsClose(f: PFSFile): boolean; |
|
32 |
||
33 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
8107 | 34 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
8031 | 35 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
36 |
function pfsEOF(f: PFSFile): boolean; |
|
37 |
||
38 |
function pfsExists(fname: shortstring): boolean; |
|
8028 | 39 |
|
8077 | 40 |
function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhysfsLibName; |
41 |
procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName; |
|
42 |
||
7959 | 43 |
implementation |
8022 | 44 |
uses uUtils, uVariables; |
7959 | 45 |
|
8073 | 46 |
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external PhysfsLibName; |
47 |
function PHYSFS_deinit() : LongInt; cdecl; external PhysfsLibName; |
|
48 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl ; external PhysfsLibName; |
|
49 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
|
7959 | 50 |
|
8073 | 51 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName; |
52 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
53 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
54 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
55 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
56 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
7959 | 57 |
|
8073 | 58 |
procedure hedgewarsMountPackages(); cdecl; external PhysfsLibName; |
8052 | 59 |
|
8025 | 60 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
61 |
begin |
|
62 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
63 |
end; |
|
64 |
||
65 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 66 |
begin |
8025 | 67 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
68 |
end; |
|
8022 | 69 |
|
8028 | 70 |
function pfsOpenRead(fname: shortstring): PFSFile; |
71 |
begin |
|
72 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
73 |
end; |
|
74 |
||
75 |
function pfsEOF(f: PFSFile): boolean; |
|
76 |
begin |
|
77 |
exit(PHYSFS_eof(f)) |
|
78 |
end; |
|
79 |
||
80 |
function pfsClose(f: PFSFile): boolean; |
|
81 |
begin |
|
82 |
exit(PHYSFS_close(f)) |
|
83 |
end; |
|
84 |
||
8031 | 85 |
function pfsExists(fname: shortstring): boolean; |
86 |
begin |
|
87 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
88 |
end; |
|
89 |
||
8028 | 90 |
|
91 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
92 |
var c: char; |
|
93 |
begin |
|
94 |
s[0]:= #0; |
|
95 |
||
8034 | 96 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 97 |
if (c <> #13) and (s[0] < #255) then |
98 |
begin |
|
99 |
inc(s[0]); |
|
100 |
s[byte(s[0])]:= c |
|
101 |
end |
|
102 |
end; |
|
103 |
||
8107 | 104 |
procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
105 |
var c: char; |
|
106 |
b: shortstring; |
|
107 |
begin |
|
108 |
s:= ''; |
|
109 |
b[0]:= #0; |
|
110 |
||
111 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
|
112 |
if (c <> #13) then |
|
113 |
begin |
|
114 |
inc(b[0]); |
|
115 |
b[byte(b[0])]:= c; |
|
116 |
if b[0] = #255 then |
|
117 |
begin |
|
118 |
s:= s + b; |
|
119 |
b[0]:= #0 |
|
120 |
end |
|
121 |
end; |
|
122 |
||
123 |
s:= s + b |
|
124 |
end; |
|
125 |
||
8031 | 126 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
127 |
var r: Int64; |
|
128 |
begin |
|
8034 | 129 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 130 |
|
131 |
if r <= 0 then |
|
132 |
pfsBlockRead:= 0 |
|
133 |
else |
|
134 |
pfsBlockRead:= r |
|
135 |
end; |
|
136 |
||
8025 | 137 |
procedure initModule; |
138 |
var i: LongInt; |
|
139 |
begin |
|
140 |
i:= PHYSFS_init(Str2PChar(ParamStr(0))); |
|
141 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
|
142 |
||
143 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true); |
|
144 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
|
8031 | 145 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true); |
8046 | 146 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 147 |
|
148 |
hedgewarsMountPackages; |
|
7959 | 149 |
end; |
150 |
||
151 |
procedure freeModule; |
|
152 |
begin |
|
153 |
PHYSFS_deinit; |
|
154 |
end; |
|
155 |
||
156 |
end. |