author | unc0rr |
Mon, 19 Nov 2012 17:41:09 +0400 | |
changeset 8067 | 34a679e5ca9d |
parent 8063 | 06efc1ea6a40 |
child 8073 | 5a289ef40fdb |
permissions | -rw-r--r-- |
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 |
|
8067
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
10 |
{$IFDEF WIN32} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
11 |
{$LINKLIB kernel32} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
12 |
{$LINKLIB user32} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
13 |
{$LINKLIB shell32} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
14 |
{$LINKLIB advapi32} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
15 |
{$LINKLIB msvcrt} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
16 |
{$ENDIF} |
34a679e5ca9d
Link some libraries needed for physfs on windows (there are still 5 symbols which couldn't be found - to be resolved)
unc0rr
parents:
8063
diff
changeset
|
17 |
|
8063 | 18 |
{$IFDEF DARWIN} |
19 |
{$LINKFRAMEWORK IOKit} |
|
20 |
{$ENDIF} |
|
21 |
||
7959 | 22 |
interface |
8022 | 23 |
uses SDLh; |
7959 | 24 |
|
25 |
procedure initModule; |
|
26 |
procedure freeModule; |
|
27 |
||
8028 | 28 |
type PFSFile = pointer; |
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 |
|
7959 | 42 |
implementation |
8022 | 43 |
uses uUtils, uVariables; |
7959 | 44 |
|
45 |
function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external; |
|
46 |
function PHYSFS_deinit() : LongInt; cdecl; external; |
|
8025 | 47 |
function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external; |
48 |
function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external; |
|
7959 | 49 |
|
7963 | 50 |
function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external; |
8028 | 51 |
function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external; |
52 |
function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external; |
|
8034 | 53 |
function PHYSFS_readBytes(f: PFSFile; buffer: pointer; len: Int64): Int64; cdecl; external; |
8028 | 54 |
function PHYSFS_close(f: PFSFile): LongBool; cdecl; external; |
8031 | 55 |
function PHYSFS_exists(fname: PChar): LongBool; cdecl; external; |
7959 | 56 |
|
8052 | 57 |
procedure hedgewarsMountPackages(); cdecl; external; |
58 |
||
8025 | 59 |
function rwopsOpenRead(fname: shortstring): PSDL_RWops; |
60 |
begin |
|
61 |
exit(PHYSFSRWOPS_openRead(Str2PChar(fname))); |
|
62 |
end; |
|
63 |
||
64 |
function rwopsOpenWrite(fname: shortstring): PSDL_RWops; |
|
7959 | 65 |
begin |
8025 | 66 |
exit(PHYSFSRWOPS_openWrite(Str2PChar(fname))); |
67 |
end; |
|
8022 | 68 |
|
8028 | 69 |
function pfsOpenRead(fname: shortstring): PFSFile; |
70 |
begin |
|
71 |
exit(PHYSFS_openRead(Str2PChar(fname))); |
|
72 |
end; |
|
73 |
||
74 |
function pfsEOF(f: PFSFile): boolean; |
|
75 |
begin |
|
76 |
exit(PHYSFS_eof(f)) |
|
77 |
end; |
|
78 |
||
79 |
function pfsClose(f: PFSFile): boolean; |
|
80 |
begin |
|
81 |
exit(PHYSFS_close(f)) |
|
82 |
end; |
|
83 |
||
8031 | 84 |
function pfsExists(fname: shortstring): boolean; |
85 |
begin |
|
86 |
exit(PHYSFS_exists(Str2PChar(fname))) |
|
87 |
end; |
|
88 |
||
8028 | 89 |
|
90 |
procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
91 |
var c: char; |
|
92 |
begin |
|
93 |
s[0]:= #0; |
|
94 |
||
8034 | 95 |
while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
8028 | 96 |
if (c <> #13) and (s[0] < #255) then |
97 |
begin |
|
98 |
inc(s[0]); |
|
99 |
s[byte(s[0])]:= c |
|
100 |
end |
|
101 |
end; |
|
102 |
||
8031 | 103 |
function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
104 |
var r: Int64; |
|
105 |
begin |
|
8034 | 106 |
r:= PHYSFS_readBytes(f, buf, size); |
8031 | 107 |
|
108 |
if r <= 0 then |
|
109 |
pfsBlockRead:= 0 |
|
110 |
else |
|
111 |
pfsBlockRead:= r |
|
112 |
end; |
|
113 |
||
8025 | 114 |
procedure initModule; |
115 |
var i: LongInt; |
|
116 |
begin |
|
117 |
i:= PHYSFS_init(Str2PChar(ParamStr(0))); |
|
118 |
AddFileLog('[PhysFS] init: ' + inttostr(i)); |
|
119 |
||
120 |
i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true); |
|
121 |
AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
|
8031 | 122 |
i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true); |
8046 | 123 |
AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i)); |
8052 | 124 |
|
125 |
hedgewarsMountPackages; |
|
7959 | 126 |
end; |
127 |
||
128 |
procedure freeModule; |
|
129 |
begin |
|
130 |
PHYSFS_deinit; |
|
131 |
end; |
|
132 |
||
133 |
end. |