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