author | Bryan Dunsmore <dunsmoreb@gmail.com> |
Fri, 30 Nov 2012 21:28:40 -0600 | |
branch | webgl |
changeset 8111 | 4307de8780fa |
parent 8105 | d088be5ecdcb |
child 8330 | aaefa587e277 |
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} |
|
18 |
PhysfsLibName = 'physfs'; |
|
19 |
{$ENDIF} |
|
20 |
||
7959 | 21 |
procedure initModule; |
22 |
procedure freeModule; |
|
23 |
||
8028 | 24 |
type PFSFile = pointer; |
25 |
||
8025 | 26 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
27 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
8022 | 28 |
|
8028 | 29 |
function pfsOpenRead(fname: shortstring): PFSFile; |
30 |
function pfsClose(f: PFSFile): boolean; |
|
31 |
||
32 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
8031 | 33 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
34 |
function pfsEOF(f: PFSFile): boolean; |
|
35 |
||
36 |
function pfsExists(fname: shortstring): boolean; |
|
8028 | 37 |
|
8077 | 38 |
function physfsReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; cdecl; external PhysfsLibName; |
39 |
procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName; |
|
40 |
||
8105 | 41 |
{$IFNDEF PAS2C} |
42 |
//apparently pas2c doesn't render the functions below if it finds 'implementation' first |
|
7959 | 43 |
implementation |
8022 | 44 |
uses uUtils, uVariables; |
8105 | 45 |
{$ENDIF} |
7959 | 46 |
|
8105 | 47 |
function PHYSFS_init(argv: PChar): LongInt; cdecl; external PhysfsLibName; |
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
48 |
function PHYSFS_deinit: LongInt; cdecl; external PhysfsLibName; |
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
49 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
8073 | 50 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
7959 | 51 |
|
8073 | 52 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external PhysfsLibName; |
53 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external PhysfsLibName; |
|
54 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
55 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external PhysfsLibName; |
|
56 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName; |
|
57 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName; |
|
7959 | 58 |
|
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
59 |
procedure hedgewarsMountPackages; cdecl; external PhysfsLibName; |
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
60 |
|
8105 | 61 |
{$IFDEF PAS2C} |
62 |
implementation |
|
63 |
uses uUtils, uVariables; |
|
64 |
{$ENDIF} |
|
65 |
||
8099
a7f02b902b6f
throw in some 'nots' trying to restore pas2c functionality
koda
parents:
8080
diff
changeset
|
66 |
(*****************************************************************) |
8052 | 67 |
|
8025 | 68 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
69 |
begin |
|
70 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
71 |
end; |
|
72 |
||
73 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 74 |
begin |
8025 | 75 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
76 |
end; |
|
8022 | 77 |
|
8028 | 78 |
function pfsOpenRead(fname: shortstring): PFSFile; |
79 |
begin |
|
80 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
81 |
end; |
|
82 |
||
83 |
function pfsEOF(f: PFSFile): boolean; |
|
84 |
begin |
|
85 |
exit(PHYSFS_eof(f)) |
|
86 |
end; |
|
87 |
||
88 |
function pfsClose(f: PFSFile): boolean; |
|
89 |
begin |
|
90 |
exit(PHYSFS_close(f)) |
|
91 |
end; |
|
92 |
||
8031 | 93 |
function pfsExists(fname: shortstring): boolean; |
94 |
begin |
|
95 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
96 |
end; |
|
97 |
||
8028 | 98 |
|
99 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
100 |
var c: char; |
|
101 |
begin |
|
102 |
s[0]:= #0; |
|
103 |
||
8034 | 104 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 105 |
if (c <> #13) and (s[0] < #255) then |
106 |
begin |
|
107 |
inc(s[0]); |
|
108 |
s[byte(s[0])]:= c |
|
109 |
end |
|
110 |
end; |
|
111 |
||
8031 | 112 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
113 |
var r: Int64; |
|
114 |
begin |
|
8034 | 115 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 116 |
|
117 |
if r <= 0 then |
|
118 |
pfsBlockRead:= 0 |
|
119 |
else |
|
120 |
pfsBlockRead:= r |
|
121 |
end; |
|
122 |
||
8025 | 123 |
procedure initModule; |
124 |
var i: LongInt; |
|
125 |
begin |
|
126 |
i:= PHYSFS_init(Str2PChar(ParamStr(0))); |
|
127 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
|
128 |
||
129 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true); |
|
130 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
|
8031 | 131 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true); |
8046 | 132 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 133 |
|
134 |
hedgewarsMountPackages; |
|
7959 | 135 |
end; |
136 |
||
137 |
procedure freeModule; |
|
138 |
begin |
|
139 |
PHYSFS_deinit; |
|
140 |
end; |
|
141 |
||
142 |
end. |