equal
deleted
inserted
replaced
28 |
28 |
29 function pfsOpenRead(fname: shortstring): PFSFile; |
29 function pfsOpenRead(fname: shortstring): PFSFile; |
30 function pfsClose(f: PFSFile): boolean; |
30 function pfsClose(f: PFSFile): boolean; |
31 |
31 |
32 procedure pfsReadLn(f: PFSFile; var s: shortstring); |
32 procedure pfsReadLn(f: PFSFile; var s: shortstring); |
|
33 procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
33 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
34 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
34 function pfsEOF(f: PFSFile): boolean; |
35 function pfsEOF(f: PFSFile): boolean; |
35 |
36 |
36 function pfsExists(fname: shortstring): boolean; |
37 function pfsExists(fname: shortstring): boolean; |
37 |
38 |
39 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName; |
40 procedure physfsReaderSetBuffer(buf: pointer); cdecl; external PhysfsLibName; |
40 |
41 |
41 {$IFNDEF PAS2C} |
42 {$IFNDEF PAS2C} |
42 //apparently pas2c doesn't render the functions below if it finds 'implementation' first |
43 //apparently pas2c doesn't render the functions below if it finds 'implementation' first |
43 implementation |
44 implementation |
44 uses uUtils, uVariables; |
45 uses uUtils, uVariables, sysutils; |
45 {$ENDIF} |
46 {$ENDIF} |
46 |
47 |
47 function PHYSFS_init(argv: PChar): LongInt; cdecl; external PhysfsLibName; |
48 function PHYSFS_init(argv: PChar): LongInt; cdecl; external PhysfsLibName; |
48 function PHYSFS_deinit: LongInt; cdecl; external PhysfsLibName; |
49 function PHYSFS_deinit: LongInt; cdecl; external PhysfsLibName; |
49 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
50 function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external PhysfsLibName; |
107 inc(s[0]); |
108 inc(s[0]); |
108 s[byte(s[0])]:= c |
109 s[byte(s[0])]:= c |
109 end |
110 end |
110 end; |
111 end; |
111 |
112 |
|
113 procedure pfsReadLnA(f: PFSFile; var s: ansistring); |
|
114 var c: char; |
|
115 b: shortstring; |
|
116 begin |
|
117 s:= ''; |
|
118 b[0]:= #0; |
|
119 |
|
120 while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do |
|
121 if (c <> #13) then |
|
122 begin |
|
123 inc(b[0]); |
|
124 b[byte(b[0])]:= c; |
|
125 if b[0] = #255 then |
|
126 begin |
|
127 s:= s + b; |
|
128 b[0]:= #0 |
|
129 end |
|
130 end; |
|
131 |
|
132 s:= s + b |
|
133 end; |
|
134 |
112 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
135 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64; |
113 var r: Int64; |
136 var r: Int64; |
114 begin |
137 begin |
115 r:= PHYSFS_readBytes(f, buf, size); |
138 r:= PHYSFS_readBytes(f, buf, size); |
116 |
139 |
120 pfsBlockRead:= r |
143 pfsBlockRead:= r |
121 end; |
144 end; |
122 |
145 |
123 procedure initModule; |
146 procedure initModule; |
124 var i: LongInt; |
147 var i: LongInt; |
|
148 cPhysfsId: shortstring; |
125 begin |
149 begin |
126 i:= PHYSFS_init(Str2PChar(ParamStr(0))); |
150 {$IFDEF HWLIBRARY} |
|
151 //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html |
|
152 cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF} ' hedgewars'; |
|
153 {$ELSE} |
|
154 cPhysfsId:= ParamStr(0); |
|
155 {$ENDIF} |
|
156 |
|
157 i:= PHYSFS_init(Str2PChar(cPhysfsId)); |
127 AddFileLog('[PhysFS] init: ' + inttostr(i)); |
158 AddFileLog('[PhysFS] init: ' + inttostr(i)); |
128 |
159 |
129 i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true); |
160 i:= PHYSFS_mount(Str2PChar(PathPrefix), nil, true); |
130 AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
161 AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i)); |
131 i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true); |
162 i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, true); |