OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fgas/crt/fgas_stream.h" | 7 #include "xfa/fgas/crt/fgas_stream.h" |
8 | 8 |
9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
10 _FX_OS_ == _FX_WIN64_ | 10 _FX_OS_ == _FX_WIN64_ |
11 #include <io.h> | 11 #include <io.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <memory> | 15 #include <memory> |
16 | 16 |
17 #include "xfa/fgas/crt/fgas_codepage.h" | 17 #include "xfa/fgas/crt/fgas_codepage.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class IFX_StreamImp { | 21 class IFX_StreamImp { |
22 public: | 22 public: |
23 virtual ~IFX_StreamImp() {} | 23 virtual ~IFX_StreamImp() {} |
24 | 24 |
25 virtual int32_t GetLength() const = 0; | 25 virtual int32_t GetLength() const = 0; |
26 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; | 26 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; |
27 virtual int32_t GetPosition() = 0; | 27 virtual int32_t GetPosition() = 0; |
28 virtual FX_BOOL IsEOF() const = 0; | 28 virtual bool IsEOF() const = 0; |
29 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; | 29 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; |
30 virtual int32_t ReadString(FX_WCHAR* pStr, | 30 virtual int32_t ReadString(FX_WCHAR* pStr, |
31 int32_t iMaxLength, | 31 int32_t iMaxLength, |
32 FX_BOOL& bEOS) = 0; | 32 bool& bEOS) = 0; |
33 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; | 33 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; |
34 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; | 34 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; |
35 virtual void Flush() = 0; | 35 virtual void Flush() = 0; |
36 virtual FX_BOOL SetLength(int32_t iLength) = 0; | 36 virtual bool SetLength(int32_t iLength) = 0; |
37 | 37 |
38 protected: | 38 protected: |
39 IFX_StreamImp(); | 39 IFX_StreamImp(); |
40 | 40 |
41 uint32_t GetAccessModes() const { return m_dwAccess; } | 41 uint32_t GetAccessModes() const { return m_dwAccess; } |
42 void SetAccessModes(uint32_t modes) { m_dwAccess = modes; } | 42 void SetAccessModes(uint32_t modes) { m_dwAccess = modes; } |
43 | 43 |
44 private: | 44 private: |
45 uint32_t m_dwAccess; | 45 uint32_t m_dwAccess; |
46 }; | 46 }; |
47 | 47 |
48 class CFX_FileStreamImp : public IFX_StreamImp { | 48 class CFX_FileStreamImp : public IFX_StreamImp { |
49 public: | 49 public: |
50 CFX_FileStreamImp(); | 50 CFX_FileStreamImp(); |
51 ~CFX_FileStreamImp() override; | 51 ~CFX_FileStreamImp() override; |
52 | 52 |
53 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 53 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
54 | 54 |
55 // IFX_StreamImp: | 55 // IFX_StreamImp: |
56 int32_t GetLength() const override; | 56 int32_t GetLength() const override; |
57 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 57 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
58 int32_t GetPosition() override; | 58 int32_t GetPosition() override; |
59 FX_BOOL IsEOF() const override; | 59 bool IsEOF() const override; |
60 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 60 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
61 int32_t ReadString(FX_WCHAR* pStr, | 61 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
62 int32_t iMaxLength, | |
63 FX_BOOL& bEOS) override; | |
64 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 62 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
65 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 63 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
66 void Flush() override; | 64 void Flush() override; |
67 FX_BOOL SetLength(int32_t iLength) override; | 65 bool SetLength(int32_t iLength) override; |
68 | 66 |
69 protected: | 67 protected: |
70 FXSYS_FILE* m_hFile; | 68 FXSYS_FILE* m_hFile; |
71 int32_t m_iLength; | 69 int32_t m_iLength; |
72 }; | 70 }; |
73 | 71 |
74 class CFX_BufferStreamImp : public IFX_StreamImp { | 72 class CFX_BufferStreamImp : public IFX_StreamImp { |
75 public: | 73 public: |
76 CFX_BufferStreamImp(); | 74 CFX_BufferStreamImp(); |
77 ~CFX_BufferStreamImp() override {} | 75 ~CFX_BufferStreamImp() override {} |
78 | 76 |
79 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 77 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
80 | 78 |
81 // IFX_StreamImp: | 79 // IFX_StreamImp: |
82 int32_t GetLength() const override; | 80 int32_t GetLength() const override; |
83 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 81 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
84 int32_t GetPosition() override; | 82 int32_t GetPosition() override; |
85 FX_BOOL IsEOF() const override; | 83 bool IsEOF() const override; |
86 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 84 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
87 int32_t ReadString(FX_WCHAR* pStr, | 85 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
88 int32_t iMaxLength, | |
89 FX_BOOL& bEOS) override; | |
90 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 86 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
91 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 87 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
92 void Flush() override {} | 88 void Flush() override {} |
93 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | 89 bool SetLength(int32_t iLength) override { return false; } |
94 | 90 |
95 protected: | 91 protected: |
96 uint8_t* m_pData; | 92 uint8_t* m_pData; |
97 int32_t m_iTotalSize; | 93 int32_t m_iTotalSize; |
98 int32_t m_iPosition; | 94 int32_t m_iPosition; |
99 int32_t m_iLength; | 95 int32_t m_iLength; |
100 }; | 96 }; |
101 | 97 |
102 class CFX_FileReadStreamImp : public IFX_StreamImp { | 98 class CFX_FileReadStreamImp : public IFX_StreamImp { |
103 public: | 99 public: |
104 CFX_FileReadStreamImp(); | 100 CFX_FileReadStreamImp(); |
105 ~CFX_FileReadStreamImp() override {} | 101 ~CFX_FileReadStreamImp() override {} |
106 | 102 |
107 FX_BOOL LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); | 103 bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); |
108 | 104 |
109 // IFX_StreamImp: | 105 // IFX_StreamImp: |
110 int32_t GetLength() const override; | 106 int32_t GetLength() const override; |
111 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 107 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
112 int32_t GetPosition() override { return m_iPosition; } | 108 int32_t GetPosition() override { return m_iPosition; } |
113 FX_BOOL IsEOF() const override; | 109 bool IsEOF() const override; |
114 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 110 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
115 int32_t ReadString(FX_WCHAR* pStr, | 111 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
116 int32_t iMaxLength, | |
117 FX_BOOL& bEOS) override; | |
118 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | 112 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { |
119 return 0; | 113 return 0; |
120 } | 114 } |
121 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { | 115 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
122 return 0; | 116 return 0; |
123 } | 117 } |
124 void Flush() override {} | 118 void Flush() override {} |
125 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | 119 bool SetLength(int32_t iLength) override { return false; } |
126 | 120 |
127 protected: | 121 protected: |
128 IFX_SeekableReadStream* m_pFileRead; | 122 IFX_SeekableReadStream* m_pFileRead; |
129 int32_t m_iPosition; | 123 int32_t m_iPosition; |
130 int32_t m_iLength; | 124 int32_t m_iLength; |
131 }; | 125 }; |
132 | 126 |
133 class CFX_BufferReadStreamImp : public IFX_StreamImp { | 127 class CFX_BufferReadStreamImp : public IFX_StreamImp { |
134 public: | 128 public: |
135 CFX_BufferReadStreamImp(); | 129 CFX_BufferReadStreamImp(); |
136 ~CFX_BufferReadStreamImp() override; | 130 ~CFX_BufferReadStreamImp() override; |
137 | 131 |
138 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 132 bool LoadBufferRead(IFX_BufferRead* pBufferRead, |
139 int32_t iFileSize, | 133 int32_t iFileSize, |
140 uint32_t dwAccess, | 134 uint32_t dwAccess, |
141 FX_BOOL bReleaseBufferRead); | 135 bool bReleaseBufferRead); |
142 | 136 |
143 // IFX_StreamImp: | 137 // IFX_StreamImp: |
144 int32_t GetLength() const override; | 138 int32_t GetLength() const override; |
145 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 139 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
146 int32_t GetPosition() override { return m_iPosition; } | 140 int32_t GetPosition() override { return m_iPosition; } |
147 FX_BOOL IsEOF() const override; | 141 bool IsEOF() const override; |
148 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 142 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
149 int32_t ReadString(FX_WCHAR* pStr, | 143 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
150 int32_t iMaxLength, | |
151 FX_BOOL& bEOS) override; | |
152 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | 144 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { |
153 return 0; | 145 return 0; |
154 } | 146 } |
155 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { | 147 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
156 return 0; | 148 return 0; |
157 } | 149 } |
158 void Flush() override {} | 150 void Flush() override {} |
159 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | 151 bool SetLength(int32_t iLength) override { return false; } |
160 | 152 |
161 private: | 153 private: |
162 IFX_BufferRead* m_pBufferRead; | 154 IFX_BufferRead* m_pBufferRead; |
163 FX_BOOL m_bReleaseBufferRead; | 155 bool m_bReleaseBufferRead; |
164 int32_t m_iPosition; | 156 int32_t m_iPosition; |
165 int32_t m_iBufferSize; | 157 int32_t m_iBufferSize; |
166 }; | 158 }; |
167 | 159 |
168 class CFX_FileWriteStreamImp : public IFX_StreamImp { | 160 class CFX_FileWriteStreamImp : public IFX_StreamImp { |
169 public: | 161 public: |
170 CFX_FileWriteStreamImp(); | 162 CFX_FileWriteStreamImp(); |
171 ~CFX_FileWriteStreamImp() override {} | 163 ~CFX_FileWriteStreamImp() override {} |
172 | 164 |
173 FX_BOOL LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); | 165 bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); |
174 | 166 |
175 // IFX_StreamImp: | 167 // IFX_StreamImp: |
176 int32_t GetLength() const override; | 168 int32_t GetLength() const override; |
177 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 169 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
178 int32_t GetPosition() override { return m_iPosition; } | 170 int32_t GetPosition() override { return m_iPosition; } |
179 FX_BOOL IsEOF() const override; | 171 bool IsEOF() const override; |
180 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } | 172 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } |
181 int32_t ReadString(FX_WCHAR* pStr, | 173 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override { |
182 int32_t iMaxLength, | |
183 FX_BOOL& bEOS) override { | |
184 return 0; | 174 return 0; |
185 } | 175 } |
186 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 176 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
187 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 177 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
188 void Flush() override; | 178 void Flush() override; |
189 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | 179 bool SetLength(int32_t iLength) override { return false; } |
190 | 180 |
191 protected: | 181 protected: |
192 IFX_SeekableWriteStream* m_pFileWrite; | 182 IFX_SeekableWriteStream* m_pFileWrite; |
193 int32_t m_iPosition; | 183 int32_t m_iPosition; |
194 }; | 184 }; |
195 | 185 |
196 enum FX_STREAMTYPE { | 186 enum FX_STREAMTYPE { |
197 FX_SREAMTYPE_Unknown = 0, | 187 FX_SREAMTYPE_Unknown = 0, |
198 FX_STREAMTYPE_File, | 188 FX_STREAMTYPE_File, |
199 FX_STREAMTYPE_Buffer, | 189 FX_STREAMTYPE_Buffer, |
200 FX_STREAMTYPE_Stream, | 190 FX_STREAMTYPE_Stream, |
201 FX_STREAMTYPE_BufferRead, | 191 FX_STREAMTYPE_BufferRead, |
202 }; | 192 }; |
203 | 193 |
204 class CFX_Stream : public IFX_Stream { | 194 class CFX_Stream : public IFX_Stream { |
205 public: | 195 public: |
206 CFX_Stream(); | 196 CFX_Stream(); |
207 ~CFX_Stream() override; | 197 ~CFX_Stream() override; |
208 | 198 |
209 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 199 bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
210 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 200 bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
211 FX_BOOL LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); | 201 bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); |
212 FX_BOOL LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); | 202 bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); |
213 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 203 bool LoadBufferRead(IFX_BufferRead* pBufferRead, |
214 int32_t iFileSize, | 204 int32_t iFileSize, |
215 uint32_t dwAccess, | 205 uint32_t dwAccess, |
216 FX_BOOL bReleaseBufferRead); | 206 bool bReleaseBufferRead); |
217 | 207 |
218 // IFX_Stream | 208 // IFX_Stream |
219 void Release() override; | 209 void Release() override; |
220 IFX_Stream* Retain() override; | 210 IFX_Stream* Retain() override; |
221 uint32_t GetAccessModes() const override; | 211 uint32_t GetAccessModes() const override; |
222 int32_t GetLength() const override; | 212 int32_t GetLength() const override; |
223 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 213 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
224 int32_t GetPosition() override; | 214 int32_t GetPosition() override; |
225 FX_BOOL IsEOF() const override; | 215 bool IsEOF() const override; |
226 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 216 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
227 int32_t ReadString(FX_WCHAR* pStr, | 217 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
228 int32_t iMaxLength, | |
229 FX_BOOL& bEOS) override; | |
230 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 218 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
231 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 219 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
232 void Flush() override; | 220 void Flush() override; |
233 FX_BOOL SetLength(int32_t iLength) override; | 221 bool SetLength(int32_t iLength) override; |
234 int32_t GetBOM(uint8_t bom[4]) const override; | 222 int32_t GetBOM(uint8_t bom[4]) const override; |
235 uint16_t GetCodePage() const override; | 223 uint16_t GetCodePage() const override; |
236 uint16_t SetCodePage(uint16_t wCodePage) override; | 224 uint16_t SetCodePage(uint16_t wCodePage) override; |
237 IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 225 IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
238 int32_t iOffset, | 226 int32_t iOffset, |
239 int32_t iLength) override; | 227 int32_t iLength) override; |
240 | 228 |
241 protected: | 229 protected: |
242 FX_STREAMTYPE m_eStreamType; | 230 FX_STREAMTYPE m_eStreamType; |
243 IFX_StreamImp* m_pStreamImp; | 231 IFX_StreamImp* m_pStreamImp; |
244 uint32_t m_dwAccess; | 232 uint32_t m_dwAccess; |
245 int32_t m_iTotalSize; | 233 int32_t m_iTotalSize; |
246 int32_t m_iPosition; | 234 int32_t m_iPosition; |
247 int32_t m_iStart; | 235 int32_t m_iStart; |
248 int32_t m_iLength; | 236 int32_t m_iLength; |
249 int32_t m_iRefCount; | 237 int32_t m_iRefCount; |
250 }; | 238 }; |
251 | 239 |
252 class CFX_TextStream : public IFX_Stream { | 240 class CFX_TextStream : public IFX_Stream { |
253 public: | 241 public: |
254 CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream); | 242 CFX_TextStream(IFX_Stream* pStream, bool bDelStream); |
255 ~CFX_TextStream() override; | 243 ~CFX_TextStream() override; |
256 | 244 |
257 // IFX_Stream | 245 // IFX_Stream |
258 void Release() override; | 246 void Release() override; |
259 IFX_Stream* Retain() override; | 247 IFX_Stream* Retain() override; |
260 uint32_t GetAccessModes() const override; | 248 uint32_t GetAccessModes() const override; |
261 int32_t GetLength() const override; | 249 int32_t GetLength() const override; |
262 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 250 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
263 int32_t GetPosition() override; | 251 int32_t GetPosition() override; |
264 FX_BOOL IsEOF() const override; | 252 bool IsEOF() const override; |
265 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 253 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
266 int32_t ReadString(FX_WCHAR* pStr, | 254 int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) override; |
267 int32_t iMaxLength, | |
268 FX_BOOL& bEOS) override; | |
269 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 255 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
270 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 256 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
271 void Flush() override; | 257 void Flush() override; |
272 FX_BOOL SetLength(int32_t iLength) override; | 258 bool SetLength(int32_t iLength) override; |
273 int32_t GetBOM(uint8_t bom[4]) const override; | 259 int32_t GetBOM(uint8_t bom[4]) const override; |
274 uint16_t GetCodePage() const override; | 260 uint16_t GetCodePage() const override; |
275 uint16_t SetCodePage(uint16_t wCodePage) override; | 261 uint16_t SetCodePage(uint16_t wCodePage) override; |
276 IFX_Stream* CreateSharedStream(uint32_t dwAccess, | 262 IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
277 int32_t iOffset, | 263 int32_t iOffset, |
278 int32_t iLength) override; | 264 int32_t iLength) override; |
279 | 265 |
280 protected: | 266 protected: |
281 uint16_t m_wCodePage; | 267 uint16_t m_wCodePage; |
282 int32_t m_wBOMLength; | 268 int32_t m_wBOMLength; |
283 uint32_t m_dwBOM; | 269 uint32_t m_dwBOM; |
284 uint8_t* m_pBuf; | 270 uint8_t* m_pBuf; |
285 int32_t m_iBufSize; | 271 int32_t m_iBufSize; |
286 FX_BOOL m_bDelStream; | 272 bool m_bDelStream; |
287 IFX_Stream* m_pStreamImp; | 273 IFX_Stream* m_pStreamImp; |
288 int32_t m_iRefCount; | 274 int32_t m_iRefCount; |
289 void InitStream(); | 275 void InitStream(); |
290 }; | 276 }; |
291 | 277 |
292 class CFGAS_FileRead : public IFX_SeekableReadStream { | 278 class CFGAS_FileRead : public IFX_SeekableReadStream { |
293 public: | 279 public: |
294 CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream); | 280 CFGAS_FileRead(IFX_Stream* pStream, bool bReleaseStream); |
295 ~CFGAS_FileRead() override; | 281 ~CFGAS_FileRead() override; |
296 | 282 |
(...skipping 13 matching lines...) Expand all Loading... |
310 return _filelength(_fileno(file)); | 296 return _filelength(_fileno(file)); |
311 #else | 297 #else |
312 int32_t iPos = FXSYS_ftell(file); | 298 int32_t iPos = FXSYS_ftell(file); |
313 FXSYS_fseek(file, 0, FXSYS_SEEK_END); | 299 FXSYS_fseek(file, 0, FXSYS_SEEK_END); |
314 int32_t iLen = FXSYS_ftell(file); | 300 int32_t iLen = FXSYS_ftell(file); |
315 FXSYS_fseek(file, iPos, FXSYS_SEEK_SET); | 301 FXSYS_fseek(file, iPos, FXSYS_SEEK_SET); |
316 return iLen; | 302 return iLen; |
317 #endif | 303 #endif |
318 } | 304 } |
319 | 305 |
320 FX_BOOL FileSetSize(FXSYS_FILE* file, int32_t size) { | 306 bool FileSetSize(FXSYS_FILE* file, int32_t size) { |
321 ASSERT(file); | 307 ASSERT(file); |
322 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | 308 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ |
323 return _chsize(_fileno(file), size) == 0; | 309 return _chsize(_fileno(file), size) == 0; |
324 #elif _FX_OS_ == _FX_WIN32_MOBILE_ | 310 #elif _FX_OS_ == _FX_WIN32_MOBILE_ |
325 HANDLE hFile = _fileno(file); | 311 HANDLE hFile = _fileno(file); |
326 uint32_t dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT); | 312 uint32_t dwPos = ::SetFilePointer(hFile, 0, 0, FILE_CURRENT); |
327 ::SetFilePointer(hFile, size, 0, FILE_BEGIN); | 313 ::SetFilePointer(hFile, size, 0, FILE_BEGIN); |
328 FX_BOOL bRet = ::SetEndOfFile(hFile); | 314 bool bRet = ::SetEndOfFile(hFile); |
329 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); | 315 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); |
330 return bRet; | 316 return bRet; |
331 #else | 317 #else |
332 return FALSE; | 318 return false; |
333 #endif | 319 #endif |
334 } | 320 } |
335 | 321 |
336 } // namespace | 322 } // namespace |
337 | 323 |
338 // static | 324 // static |
339 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, | 325 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, |
340 uint32_t dwAccess) { | 326 uint32_t dwAccess) { |
341 CFX_Stream* pSR = new CFX_Stream; | 327 CFX_Stream* pSR = new CFX_Stream; |
342 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { | 328 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { |
343 pSR->Release(); | 329 pSR->Release(); |
344 return nullptr; | 330 return nullptr; |
345 } | 331 } |
346 if (dwAccess & FX_STREAMACCESS_Text) { | 332 if (dwAccess & FX_STREAMACCESS_Text) { |
347 return new CFX_TextStream(pSR, TRUE); | 333 return new CFX_TextStream(pSR, true); |
348 } | 334 } |
349 return pSR; | 335 return pSR; |
350 } | 336 } |
351 | 337 |
352 // static | 338 // static |
353 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableWriteStream* pFileWrite, | 339 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableWriteStream* pFileWrite, |
354 uint32_t dwAccess) { | 340 uint32_t dwAccess) { |
355 CFX_Stream* pSR = new CFX_Stream; | 341 CFX_Stream* pSR = new CFX_Stream; |
356 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { | 342 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { |
357 pSR->Release(); | 343 pSR->Release(); |
358 return nullptr; | 344 return nullptr; |
359 } | 345 } |
360 if (dwAccess & FX_STREAMACCESS_Text) { | 346 if (dwAccess & FX_STREAMACCESS_Text) { |
361 return new CFX_TextStream(pSR, TRUE); | 347 return new CFX_TextStream(pSR, true); |
362 } | 348 } |
363 return pSR; | 349 return pSR; |
364 } | 350 } |
365 | 351 |
366 // static | 352 // static |
367 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, | 353 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, |
368 int32_t length, | 354 int32_t length, |
369 uint32_t dwAccess) { | 355 uint32_t dwAccess) { |
370 CFX_Stream* pSR = new CFX_Stream; | 356 CFX_Stream* pSR = new CFX_Stream; |
371 if (!pSR->LoadBuffer(pData, length, dwAccess)) { | 357 if (!pSR->LoadBuffer(pData, length, dwAccess)) { |
372 pSR->Release(); | 358 pSR->Release(); |
373 return nullptr; | 359 return nullptr; |
374 } | 360 } |
375 if (dwAccess & FX_STREAMACCESS_Text) { | 361 if (dwAccess & FX_STREAMACCESS_Text) { |
376 return new CFX_TextStream(pSR, TRUE); | 362 return new CFX_TextStream(pSR, true); |
377 } | 363 } |
378 return pSR; | 364 return pSR; |
379 } | 365 } |
380 | 366 |
381 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {} | 367 IFX_StreamImp::IFX_StreamImp() : m_dwAccess(0) {} |
382 | 368 |
383 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} | 369 CFX_FileStreamImp::CFX_FileStreamImp() : m_hFile(nullptr), m_iLength(0) {} |
384 | 370 |
385 CFX_FileStreamImp::~CFX_FileStreamImp() { | 371 CFX_FileStreamImp::~CFX_FileStreamImp() { |
386 if (m_hFile) | 372 if (m_hFile) |
387 FXSYS_fclose(m_hFile); | 373 FXSYS_fclose(m_hFile); |
388 } | 374 } |
389 | 375 |
390 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, | 376 bool CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, |
391 uint32_t dwAccess) { | 377 uint32_t dwAccess) { |
392 ASSERT(!m_hFile); | 378 ASSERT(!m_hFile); |
393 ASSERT(pszSrcFileName && FXSYS_wcslen(pszSrcFileName) > 0); | 379 ASSERT(pszSrcFileName && FXSYS_wcslen(pszSrcFileName) > 0); |
394 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 380 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
395 _FX_OS_ == _FX_WIN64_ | 381 _FX_OS_ == _FX_WIN64_ |
396 const FX_WCHAR* wsMode; | 382 const FX_WCHAR* wsMode; |
397 if (dwAccess & FX_STREAMACCESS_Write) { | 383 if (dwAccess & FX_STREAMACCESS_Write) { |
398 if (dwAccess & FX_STREAMACCESS_Append) { | 384 if (dwAccess & FX_STREAMACCESS_Append) { |
399 wsMode = L"a+b"; | 385 wsMode = L"a+b"; |
400 } else if (dwAccess & FX_STREAMACCESS_Truncate) { | 386 } else if (dwAccess & FX_STREAMACCESS_Truncate) { |
401 wsMode = L"w+b"; | 387 wsMode = L"w+b"; |
402 } else { | 388 } else { |
403 wsMode = L"r+b"; | 389 wsMode = L"r+b"; |
404 } | 390 } |
405 } else { | 391 } else { |
406 wsMode = L"rb"; | 392 wsMode = L"rb"; |
407 } | 393 } |
408 m_hFile = FXSYS_wfopen(pszSrcFileName, wsMode); | 394 m_hFile = FXSYS_wfopen(pszSrcFileName, wsMode); |
409 | 395 |
410 if (!m_hFile) { | 396 if (!m_hFile) { |
411 if (dwAccess & FX_STREAMACCESS_Write) { | 397 if (dwAccess & FX_STREAMACCESS_Write) { |
412 if (dwAccess & FX_STREAMACCESS_Create) | 398 if (dwAccess & FX_STREAMACCESS_Create) |
413 m_hFile = FXSYS_wfopen(pszSrcFileName, L"w+b"); | 399 m_hFile = FXSYS_wfopen(pszSrcFileName, L"w+b"); |
414 | 400 |
415 if (!m_hFile) { | 401 if (!m_hFile) { |
416 m_hFile = FXSYS_wfopen(pszSrcFileName, L"r+b"); | 402 m_hFile = FXSYS_wfopen(pszSrcFileName, L"r+b"); |
417 if (!m_hFile) | 403 if (!m_hFile) |
418 return FALSE; | 404 return false; |
419 | 405 |
420 if (dwAccess & FX_STREAMACCESS_Truncate) | 406 if (dwAccess & FX_STREAMACCESS_Truncate) |
421 FileSetSize(m_hFile, 0); | 407 FileSetSize(m_hFile, 0); |
422 } | 408 } |
423 } else { | 409 } else { |
424 return FALSE; | 410 return false; |
425 } | 411 } |
426 } | 412 } |
427 #else | 413 #else |
428 const FX_CHAR* wsMode = "rb"; | 414 const FX_CHAR* wsMode = "rb"; |
429 if (dwAccess & FX_STREAMACCESS_Write) { | 415 if (dwAccess & FX_STREAMACCESS_Write) { |
430 if (dwAccess & FX_STREAMACCESS_Append) { | 416 if (dwAccess & FX_STREAMACCESS_Append) { |
431 wsMode = "a+b"; | 417 wsMode = "a+b"; |
432 } else if (dwAccess & FX_STREAMACCESS_Truncate) { | 418 } else if (dwAccess & FX_STREAMACCESS_Truncate) { |
433 wsMode = "w+b"; | 419 wsMode = "w+b"; |
434 } else { | 420 } else { |
435 wsMode = "r+b"; | 421 wsMode = "r+b"; |
436 } | 422 } |
437 } | 423 } |
438 CFX_ByteString szFileName = CFX_ByteString::FromUnicode(pszSrcFileName); | 424 CFX_ByteString szFileName = CFX_ByteString::FromUnicode(pszSrcFileName); |
439 m_hFile = FXSYS_fopen(szFileName.c_str(), wsMode); | 425 m_hFile = FXSYS_fopen(szFileName.c_str(), wsMode); |
440 if (!m_hFile) { | 426 if (!m_hFile) { |
441 if (dwAccess & FX_STREAMACCESS_Write) { | 427 if (dwAccess & FX_STREAMACCESS_Write) { |
442 if (dwAccess & FX_STREAMACCESS_Create) { | 428 if (dwAccess & FX_STREAMACCESS_Create) { |
443 m_hFile = FXSYS_fopen(szFileName.c_str(), "w+b"); | 429 m_hFile = FXSYS_fopen(szFileName.c_str(), "w+b"); |
444 } | 430 } |
445 if (!m_hFile) { | 431 if (!m_hFile) { |
446 m_hFile = FXSYS_fopen(szFileName.c_str(), "r+b"); | 432 m_hFile = FXSYS_fopen(szFileName.c_str(), "r+b"); |
447 if (!m_hFile) { | 433 if (!m_hFile) { |
448 return FALSE; | 434 return false; |
449 } | 435 } |
450 if (dwAccess & FX_STREAMACCESS_Truncate) { | 436 if (dwAccess & FX_STREAMACCESS_Truncate) { |
451 FileSetSize(m_hFile, 0); | 437 FileSetSize(m_hFile, 0); |
452 } | 438 } |
453 } | 439 } |
454 } else { | 440 } else { |
455 return FALSE; | 441 return false; |
456 } | 442 } |
457 } | 443 } |
458 #endif | 444 #endif |
459 SetAccessModes(dwAccess); | 445 SetAccessModes(dwAccess); |
460 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == | 446 if ((dwAccess & (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) == |
461 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { | 447 (FX_STREAMACCESS_Write | FX_STREAMACCESS_Truncate)) { |
462 m_iLength = 0; | 448 m_iLength = 0; |
463 } else { | 449 } else { |
464 m_iLength = FileLength(m_hFile); | 450 m_iLength = FileLength(m_hFile); |
465 } | 451 } |
466 return TRUE; | 452 return true; |
467 } | 453 } |
468 int32_t CFX_FileStreamImp::GetLength() const { | 454 int32_t CFX_FileStreamImp::GetLength() const { |
469 ASSERT(m_hFile); | 455 ASSERT(m_hFile); |
470 return m_iLength; | 456 return m_iLength; |
471 } | 457 } |
472 int32_t CFX_FileStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 458 int32_t CFX_FileStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
473 ASSERT(m_hFile); | 459 ASSERT(m_hFile); |
474 FXSYS_fseek(m_hFile, iOffset, eSeek); | 460 FXSYS_fseek(m_hFile, iOffset, eSeek); |
475 return FXSYS_ftell(m_hFile); | 461 return FXSYS_ftell(m_hFile); |
476 } | 462 } |
477 int32_t CFX_FileStreamImp::GetPosition() { | 463 int32_t CFX_FileStreamImp::GetPosition() { |
478 ASSERT(m_hFile); | 464 ASSERT(m_hFile); |
479 return FXSYS_ftell(m_hFile); | 465 return FXSYS_ftell(m_hFile); |
480 } | 466 } |
481 FX_BOOL CFX_FileStreamImp::IsEOF() const { | 467 bool CFX_FileStreamImp::IsEOF() const { |
482 ASSERT(m_hFile); | 468 ASSERT(m_hFile); |
483 return FXSYS_ftell(m_hFile) >= m_iLength; | 469 return FXSYS_ftell(m_hFile) >= m_iLength; |
484 } | 470 } |
485 int32_t CFX_FileStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 471 int32_t CFX_FileStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
486 ASSERT(m_hFile); | 472 ASSERT(m_hFile); |
487 ASSERT(pBuffer && iBufferSize > 0); | 473 ASSERT(pBuffer && iBufferSize > 0); |
488 return FXSYS_fread(pBuffer, 1, iBufferSize, m_hFile); | 474 return FXSYS_fread(pBuffer, 1, iBufferSize, m_hFile); |
489 } | 475 } |
490 int32_t CFX_FileStreamImp::ReadString(FX_WCHAR* pStr, | 476 int32_t CFX_FileStreamImp::ReadString(FX_WCHAR* pStr, |
491 int32_t iMaxLength, | 477 int32_t iMaxLength, |
492 FX_BOOL& bEOS) { | 478 bool& bEOS) { |
493 ASSERT(m_hFile); | 479 ASSERT(m_hFile); |
494 ASSERT(pStr && iMaxLength > 0); | 480 ASSERT(pStr && iMaxLength > 0); |
495 if (m_iLength <= 0) { | 481 if (m_iLength <= 0) { |
496 return 0; | 482 return 0; |
497 } | 483 } |
498 int32_t iPosition = FXSYS_ftell(m_hFile); | 484 int32_t iPosition = FXSYS_ftell(m_hFile); |
499 int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength); | 485 int32_t iLen = std::min((m_iLength - iPosition) / 2, iMaxLength); |
500 if (iLen <= 0) { | 486 if (iLen <= 0) { |
501 return 0; | 487 return 0; |
502 } | 488 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 if (iPos > m_iLength) { | 520 if (iPos > m_iLength) { |
535 m_iLength = iPos; | 521 m_iLength = iPos; |
536 } | 522 } |
537 } | 523 } |
538 return iRet; | 524 return iRet; |
539 } | 525 } |
540 void CFX_FileStreamImp::Flush() { | 526 void CFX_FileStreamImp::Flush() { |
541 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 527 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
542 FXSYS_fflush(m_hFile); | 528 FXSYS_fflush(m_hFile); |
543 } | 529 } |
544 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { | 530 bool CFX_FileStreamImp::SetLength(int32_t iLength) { |
545 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 531 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
546 FX_BOOL bRet = FileSetSize(m_hFile, iLength); | 532 bool bRet = FileSetSize(m_hFile, iLength); |
547 m_iLength = FileLength(m_hFile); | 533 m_iLength = FileLength(m_hFile); |
548 return bRet; | 534 return bRet; |
549 } | 535 } |
550 CFX_FileReadStreamImp::CFX_FileReadStreamImp() | 536 CFX_FileReadStreamImp::CFX_FileReadStreamImp() |
551 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} | 537 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} |
552 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_SeekableReadStream* pFileRead, | 538 bool CFX_FileReadStreamImp::LoadFileRead(IFX_SeekableReadStream* pFileRead, |
553 uint32_t dwAccess) { | 539 uint32_t dwAccess) { |
554 ASSERT(!m_pFileRead && pFileRead); | 540 ASSERT(!m_pFileRead && pFileRead); |
555 if (dwAccess & FX_STREAMACCESS_Write) { | 541 if (dwAccess & FX_STREAMACCESS_Write) { |
556 return FALSE; | 542 return false; |
557 } | 543 } |
558 m_pFileRead = pFileRead; | 544 m_pFileRead = pFileRead; |
559 m_iLength = m_pFileRead->GetSize(); | 545 m_iLength = m_pFileRead->GetSize(); |
560 return TRUE; | 546 return true; |
561 } | 547 } |
562 int32_t CFX_FileReadStreamImp::GetLength() const { | 548 int32_t CFX_FileReadStreamImp::GetLength() const { |
563 return m_iLength; | 549 return m_iLength; |
564 } | 550 } |
565 int32_t CFX_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 551 int32_t CFX_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
566 switch (eSeek) { | 552 switch (eSeek) { |
567 case FX_STREAMSEEK_Begin: | 553 case FX_STREAMSEEK_Begin: |
568 m_iPosition = iOffset; | 554 m_iPosition = iOffset; |
569 break; | 555 break; |
570 case FX_STREAMSEEK_Current: | 556 case FX_STREAMSEEK_Current: |
571 m_iPosition += iOffset; | 557 m_iPosition += iOffset; |
572 break; | 558 break; |
573 case FX_STREAMSEEK_End: | 559 case FX_STREAMSEEK_End: |
574 m_iPosition = m_iLength + iOffset; | 560 m_iPosition = m_iLength + iOffset; |
575 break; | 561 break; |
576 } | 562 } |
577 if (m_iPosition < 0) { | 563 if (m_iPosition < 0) { |
578 m_iPosition = 0; | 564 m_iPosition = 0; |
579 } else if (m_iPosition >= m_iLength) { | 565 } else if (m_iPosition >= m_iLength) { |
580 m_iPosition = m_iLength; | 566 m_iPosition = m_iLength; |
581 } | 567 } |
582 return m_iPosition; | 568 return m_iPosition; |
583 } | 569 } |
584 FX_BOOL CFX_FileReadStreamImp::IsEOF() const { | 570 bool CFX_FileReadStreamImp::IsEOF() const { |
585 return m_iPosition >= m_iLength; | 571 return m_iPosition >= m_iLength; |
586 } | 572 } |
587 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 573 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
588 ASSERT(m_pFileRead); | 574 ASSERT(m_pFileRead); |
589 ASSERT(pBuffer && iBufferSize > 0); | 575 ASSERT(pBuffer && iBufferSize > 0); |
590 if (iBufferSize > m_iLength - m_iPosition) { | 576 if (iBufferSize > m_iLength - m_iPosition) { |
591 iBufferSize = m_iLength - m_iPosition; | 577 iBufferSize = m_iLength - m_iPosition; |
592 } | 578 } |
593 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { | 579 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { |
594 m_iPosition += iBufferSize; | 580 m_iPosition += iBufferSize; |
595 return iBufferSize; | 581 return iBufferSize; |
596 } | 582 } |
597 return 0; | 583 return 0; |
598 } | 584 } |
599 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, | 585 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, |
600 int32_t iMaxLength, | 586 int32_t iMaxLength, |
601 FX_BOOL& bEOS) { | 587 bool& bEOS) { |
602 ASSERT(m_pFileRead); | 588 ASSERT(m_pFileRead); |
603 ASSERT(pStr && iMaxLength > 0); | 589 ASSERT(pStr && iMaxLength > 0); |
604 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 590 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
605 if (iMaxLength <= 0) { | 591 if (iMaxLength <= 0) { |
606 return 0; | 592 return 0; |
607 } | 593 } |
608 int32_t i = 0; | 594 int32_t i = 0; |
609 while (i < iMaxLength && pStr[i] != L'\0') { | 595 while (i < iMaxLength && pStr[i] != L'\0') { |
610 ++i; | 596 ++i; |
611 } | 597 } |
612 bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; | 598 bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; |
613 return i; | 599 return i; |
614 } | 600 } |
615 CFX_BufferReadStreamImp::CFX_BufferReadStreamImp() | 601 CFX_BufferReadStreamImp::CFX_BufferReadStreamImp() |
616 : m_pBufferRead(nullptr), | 602 : m_pBufferRead(nullptr), |
617 m_bReleaseBufferRead(FALSE), | 603 m_bReleaseBufferRead(false), |
618 m_iPosition(0), | 604 m_iPosition(0), |
619 m_iBufferSize(0) {} | 605 m_iBufferSize(0) {} |
620 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { | 606 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { |
621 if (m_bReleaseBufferRead && m_pBufferRead) { | 607 if (m_bReleaseBufferRead && m_pBufferRead) { |
622 m_pBufferRead->Release(); | 608 m_pBufferRead->Release(); |
623 } | 609 } |
624 } | 610 } |
625 FX_BOOL CFX_BufferReadStreamImp::LoadBufferRead(IFX_BufferRead* pBufferRead, | 611 bool CFX_BufferReadStreamImp::LoadBufferRead(IFX_BufferRead* pBufferRead, |
626 int32_t iFileSize, | 612 int32_t iFileSize, |
627 uint32_t dwAccess, | 613 uint32_t dwAccess, |
628 FX_BOOL bReleaseBufferRead) { | 614 bool bReleaseBufferRead) { |
629 ASSERT(!m_pBufferRead && pBufferRead); | 615 ASSERT(!m_pBufferRead && pBufferRead); |
630 if (dwAccess & FX_STREAMACCESS_Write) { | 616 if (dwAccess & FX_STREAMACCESS_Write) { |
631 return FALSE; | 617 return false; |
632 } | 618 } |
633 m_bReleaseBufferRead = bReleaseBufferRead; | 619 m_bReleaseBufferRead = bReleaseBufferRead; |
634 m_pBufferRead = pBufferRead; | 620 m_pBufferRead = pBufferRead; |
635 m_iBufferSize = iFileSize; | 621 m_iBufferSize = iFileSize; |
636 if (m_iBufferSize >= 0) { | 622 if (m_iBufferSize >= 0) { |
637 return TRUE; | 623 return true; |
638 } | 624 } |
639 if (!m_pBufferRead->ReadNextBlock(TRUE)) { | 625 if (!m_pBufferRead->ReadNextBlock(true)) { |
640 return FALSE; | 626 return false; |
641 } | 627 } |
642 m_iBufferSize = m_pBufferRead->GetBlockSize(); | 628 m_iBufferSize = m_pBufferRead->GetBlockSize(); |
643 while (!m_pBufferRead->IsEOF()) { | 629 while (!m_pBufferRead->IsEOF()) { |
644 m_pBufferRead->ReadNextBlock(FALSE); | 630 m_pBufferRead->ReadNextBlock(false); |
645 m_iBufferSize += m_pBufferRead->GetBlockSize(); | 631 m_iBufferSize += m_pBufferRead->GetBlockSize(); |
646 } | 632 } |
647 return TRUE; | 633 return true; |
648 } | 634 } |
649 int32_t CFX_BufferReadStreamImp::GetLength() const { | 635 int32_t CFX_BufferReadStreamImp::GetLength() const { |
650 return m_iBufferSize; | 636 return m_iBufferSize; |
651 } | 637 } |
652 int32_t CFX_BufferReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 638 int32_t CFX_BufferReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
653 int32_t iLength = GetLength(); | 639 int32_t iLength = GetLength(); |
654 switch (eSeek) { | 640 switch (eSeek) { |
655 case FX_STREAMSEEK_Begin: | 641 case FX_STREAMSEEK_Begin: |
656 m_iPosition = iOffset; | 642 m_iPosition = iOffset; |
657 break; | 643 break; |
658 case FX_STREAMSEEK_Current: | 644 case FX_STREAMSEEK_Current: |
659 m_iPosition += iOffset; | 645 m_iPosition += iOffset; |
660 break; | 646 break; |
661 case FX_STREAMSEEK_End: | 647 case FX_STREAMSEEK_End: |
662 m_iPosition = iLength + iOffset; | 648 m_iPosition = iLength + iOffset; |
663 break; | 649 break; |
664 } | 650 } |
665 if (m_iPosition < 0) { | 651 if (m_iPosition < 0) { |
666 m_iPosition = 0; | 652 m_iPosition = 0; |
667 } else if (m_iPosition >= iLength) { | 653 } else if (m_iPosition >= iLength) { |
668 m_iPosition = iLength; | 654 m_iPosition = iLength; |
669 } | 655 } |
670 return m_iPosition; | 656 return m_iPosition; |
671 } | 657 } |
672 FX_BOOL CFX_BufferReadStreamImp::IsEOF() const { | 658 bool CFX_BufferReadStreamImp::IsEOF() const { |
673 return m_pBufferRead ? m_pBufferRead->IsEOF() : TRUE; | 659 return m_pBufferRead ? m_pBufferRead->IsEOF() : true; |
674 } | 660 } |
675 int32_t CFX_BufferReadStreamImp::ReadData(uint8_t* pBuffer, | 661 int32_t CFX_BufferReadStreamImp::ReadData(uint8_t* pBuffer, |
676 int32_t iBufferSize) { | 662 int32_t iBufferSize) { |
677 ASSERT(m_pBufferRead); | 663 ASSERT(m_pBufferRead); |
678 ASSERT(pBuffer && iBufferSize > 0); | 664 ASSERT(pBuffer && iBufferSize > 0); |
679 int32_t iLength = GetLength(); | 665 int32_t iLength = GetLength(); |
680 if (m_iPosition >= iLength) { | 666 if (m_iPosition >= iLength) { |
681 return 0; | 667 return 0; |
682 } | 668 } |
683 if (iBufferSize > iLength - m_iPosition) { | 669 if (iBufferSize > iLength - m_iPosition) { |
684 iBufferSize = iLength - m_iPosition; | 670 iBufferSize = iLength - m_iPosition; |
685 } | 671 } |
686 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 672 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
687 uint32_t dwBlockSize = m_pBufferRead->GetBlockSize(); | 673 uint32_t dwBlockSize = m_pBufferRead->GetBlockSize(); |
688 if (m_iPosition < (int32_t)dwBlockOffset) { | 674 if (m_iPosition < (int32_t)dwBlockOffset) { |
689 if (!m_pBufferRead->ReadNextBlock(TRUE)) { | 675 if (!m_pBufferRead->ReadNextBlock(true)) { |
690 return 0; | 676 return 0; |
691 } | 677 } |
692 dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 678 dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
693 dwBlockSize = m_pBufferRead->GetBlockSize(); | 679 dwBlockSize = m_pBufferRead->GetBlockSize(); |
694 } | 680 } |
695 while (m_iPosition < (int32_t)dwBlockOffset || | 681 while (m_iPosition < (int32_t)dwBlockOffset || |
696 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { | 682 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { |
697 if (m_pBufferRead->IsEOF() || !m_pBufferRead->ReadNextBlock(FALSE)) { | 683 if (m_pBufferRead->IsEOF() || !m_pBufferRead->ReadNextBlock(false)) { |
698 break; | 684 break; |
699 } | 685 } |
700 dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 686 dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
701 dwBlockSize = m_pBufferRead->GetBlockSize(); | 687 dwBlockSize = m_pBufferRead->GetBlockSize(); |
702 } | 688 } |
703 if (m_iPosition < (int32_t)dwBlockOffset || | 689 if (m_iPosition < (int32_t)dwBlockOffset || |
704 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { | 690 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { |
705 return 0; | 691 return 0; |
706 } | 692 } |
707 const uint8_t* pBufferTmp = m_pBufferRead->GetBlockBuffer(); | 693 const uint8_t* pBufferTmp = m_pBufferRead->GetBlockBuffer(); |
708 uint32_t dwOffsetTmp = m_iPosition - dwBlockOffset; | 694 uint32_t dwOffsetTmp = m_iPosition - dwBlockOffset; |
709 uint32_t dwCopySize = | 695 uint32_t dwCopySize = |
710 std::min(iBufferSize, (int32_t)(dwBlockSize - dwOffsetTmp)); | 696 std::min(iBufferSize, (int32_t)(dwBlockSize - dwOffsetTmp)); |
711 FXSYS_memcpy(pBuffer, pBufferTmp + dwOffsetTmp, dwCopySize); | 697 FXSYS_memcpy(pBuffer, pBufferTmp + dwOffsetTmp, dwCopySize); |
712 dwOffsetTmp = dwCopySize; | 698 dwOffsetTmp = dwCopySize; |
713 iBufferSize -= dwCopySize; | 699 iBufferSize -= dwCopySize; |
714 while (iBufferSize > 0) { | 700 while (iBufferSize > 0) { |
715 if (!m_pBufferRead->ReadNextBlock(FALSE)) { | 701 if (!m_pBufferRead->ReadNextBlock(false)) { |
716 break; | 702 break; |
717 } | 703 } |
718 dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 704 dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
719 dwBlockSize = m_pBufferRead->GetBlockSize(); | 705 dwBlockSize = m_pBufferRead->GetBlockSize(); |
720 pBufferTmp = m_pBufferRead->GetBlockBuffer(); | 706 pBufferTmp = m_pBufferRead->GetBlockBuffer(); |
721 dwCopySize = std::min((uint32_t)iBufferSize, dwBlockSize); | 707 dwCopySize = std::min((uint32_t)iBufferSize, dwBlockSize); |
722 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); | 708 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); |
723 dwOffsetTmp += dwCopySize; | 709 dwOffsetTmp += dwCopySize; |
724 iBufferSize -= dwCopySize; | 710 iBufferSize -= dwCopySize; |
725 } | 711 } |
726 m_iPosition += dwOffsetTmp; | 712 m_iPosition += dwOffsetTmp; |
727 return dwOffsetTmp; | 713 return dwOffsetTmp; |
728 } | 714 } |
729 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, | 715 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, |
730 int32_t iMaxLength, | 716 int32_t iMaxLength, |
731 FX_BOOL& bEOS) { | 717 bool& bEOS) { |
732 ASSERT(m_pBufferRead); | 718 ASSERT(m_pBufferRead); |
733 ASSERT(pStr && iMaxLength > 0); | 719 ASSERT(pStr && iMaxLength > 0); |
734 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 720 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
735 if (iMaxLength <= 0) { | 721 if (iMaxLength <= 0) { |
736 return 0; | 722 return 0; |
737 } | 723 } |
738 int32_t i = 0; | 724 int32_t i = 0; |
739 while (i < iMaxLength && pStr[i] != L'\0') { | 725 while (i < iMaxLength && pStr[i] != L'\0') { |
740 ++i; | 726 ++i; |
741 } | 727 } |
742 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; | 728 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; |
743 return i; | 729 return i; |
744 } | 730 } |
745 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() | 731 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() |
746 : m_pFileWrite(nullptr), m_iPosition(0) {} | 732 : m_pFileWrite(nullptr), m_iPosition(0) {} |
747 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite( | 733 bool CFX_FileWriteStreamImp::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, |
748 IFX_SeekableWriteStream* pFileWrite, | 734 uint32_t dwAccess) { |
749 uint32_t dwAccess) { | |
750 ASSERT(!m_pFileWrite && pFileWrite); | 735 ASSERT(!m_pFileWrite && pFileWrite); |
751 if (dwAccess & FX_STREAMACCESS_Read) { | 736 if (dwAccess & FX_STREAMACCESS_Read) { |
752 return FALSE; | 737 return false; |
753 } | 738 } |
754 if (dwAccess & FX_STREAMACCESS_Append) { | 739 if (dwAccess & FX_STREAMACCESS_Append) { |
755 m_iPosition = pFileWrite->GetSize(); | 740 m_iPosition = pFileWrite->GetSize(); |
756 } | 741 } |
757 m_pFileWrite = pFileWrite; | 742 m_pFileWrite = pFileWrite; |
758 return TRUE; | 743 return true; |
759 } | 744 } |
760 int32_t CFX_FileWriteStreamImp::GetLength() const { | 745 int32_t CFX_FileWriteStreamImp::GetLength() const { |
761 if (!m_pFileWrite) { | 746 if (!m_pFileWrite) { |
762 return 0; | 747 return 0; |
763 } | 748 } |
764 return (int32_t)m_pFileWrite->GetSize(); | 749 return (int32_t)m_pFileWrite->GetSize(); |
765 } | 750 } |
766 int32_t CFX_FileWriteStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 751 int32_t CFX_FileWriteStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
767 int32_t iLength = GetLength(); | 752 int32_t iLength = GetLength(); |
768 switch (eSeek) { | 753 switch (eSeek) { |
769 case FX_STREAMSEEK_Begin: | 754 case FX_STREAMSEEK_Begin: |
770 m_iPosition = iOffset; | 755 m_iPosition = iOffset; |
771 break; | 756 break; |
772 case FX_STREAMSEEK_Current: | 757 case FX_STREAMSEEK_Current: |
773 m_iPosition += iOffset; | 758 m_iPosition += iOffset; |
774 break; | 759 break; |
775 case FX_STREAMSEEK_End: | 760 case FX_STREAMSEEK_End: |
776 m_iPosition = iLength + iOffset; | 761 m_iPosition = iLength + iOffset; |
777 break; | 762 break; |
778 } | 763 } |
779 if (m_iPosition < 0) { | 764 if (m_iPosition < 0) { |
780 m_iPosition = 0; | 765 m_iPosition = 0; |
781 } else if (m_iPosition >= iLength) { | 766 } else if (m_iPosition >= iLength) { |
782 m_iPosition = iLength; | 767 m_iPosition = iLength; |
783 } | 768 } |
784 return m_iPosition; | 769 return m_iPosition; |
785 } | 770 } |
786 FX_BOOL CFX_FileWriteStreamImp::IsEOF() const { | 771 bool CFX_FileWriteStreamImp::IsEOF() const { |
787 return m_iPosition >= GetLength(); | 772 return m_iPosition >= GetLength(); |
788 } | 773 } |
789 int32_t CFX_FileWriteStreamImp::WriteData(const uint8_t* pBuffer, | 774 int32_t CFX_FileWriteStreamImp::WriteData(const uint8_t* pBuffer, |
790 int32_t iBufferSize) { | 775 int32_t iBufferSize) { |
791 if (!m_pFileWrite) { | 776 if (!m_pFileWrite) { |
792 return 0; | 777 return 0; |
793 } | 778 } |
794 if (m_pFileWrite->WriteBlock(pBuffer, m_iPosition, iBufferSize)) { | 779 if (m_pFileWrite->WriteBlock(pBuffer, m_iPosition, iBufferSize)) { |
795 m_iPosition += iBufferSize; | 780 m_iPosition += iBufferSize; |
796 } | 781 } |
797 return iBufferSize; | 782 return iBufferSize; |
798 } | 783 } |
799 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, | 784 int32_t CFX_FileWriteStreamImp::WriteString(const FX_WCHAR* pStr, |
800 int32_t iLength) { | 785 int32_t iLength) { |
801 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); | 786 return WriteData((const uint8_t*)pStr, iLength * sizeof(FX_WCHAR)); |
802 } | 787 } |
803 void CFX_FileWriteStreamImp::Flush() { | 788 void CFX_FileWriteStreamImp::Flush() { |
804 if (m_pFileWrite) { | 789 if (m_pFileWrite) { |
805 m_pFileWrite->Flush(); | 790 m_pFileWrite->Flush(); |
806 } | 791 } |
807 } | 792 } |
808 CFX_BufferStreamImp::CFX_BufferStreamImp() | 793 CFX_BufferStreamImp::CFX_BufferStreamImp() |
809 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {} | 794 : m_pData(nullptr), m_iTotalSize(0), m_iPosition(0), m_iLength(0) {} |
810 | 795 |
811 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, | 796 bool CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, |
812 int32_t iTotalSize, | 797 int32_t iTotalSize, |
813 uint32_t dwAccess) { | 798 uint32_t dwAccess) { |
814 ASSERT(!m_pData && pData && iTotalSize > 0); | 799 ASSERT(!m_pData && pData && iTotalSize > 0); |
815 SetAccessModes(dwAccess); | 800 SetAccessModes(dwAccess); |
816 m_pData = pData; | 801 m_pData = pData; |
817 m_iTotalSize = iTotalSize; | 802 m_iTotalSize = iTotalSize; |
818 m_iPosition = 0; | 803 m_iPosition = 0; |
819 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; | 804 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; |
820 return TRUE; | 805 return true; |
821 } | 806 } |
822 int32_t CFX_BufferStreamImp::GetLength() const { | 807 int32_t CFX_BufferStreamImp::GetLength() const { |
823 ASSERT(m_pData); | 808 ASSERT(m_pData); |
824 return m_iLength; | 809 return m_iLength; |
825 } | 810 } |
826 int32_t CFX_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 811 int32_t CFX_BufferStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
827 ASSERT(m_pData); | 812 ASSERT(m_pData); |
828 if (eSeek == FX_STREAMSEEK_Begin) { | 813 if (eSeek == FX_STREAMSEEK_Begin) { |
829 m_iPosition = iOffset; | 814 m_iPosition = iOffset; |
830 } else if (eSeek == FX_STREAMSEEK_Current) { | 815 } else if (eSeek == FX_STREAMSEEK_Current) { |
831 m_iPosition += iOffset; | 816 m_iPosition += iOffset; |
832 } else if (eSeek == FX_STREAMSEEK_End) { | 817 } else if (eSeek == FX_STREAMSEEK_End) { |
833 m_iPosition = m_iLength + iOffset; | 818 m_iPosition = m_iLength + iOffset; |
834 } | 819 } |
835 if (m_iPosition > m_iLength) { | 820 if (m_iPosition > m_iLength) { |
836 m_iPosition = m_iLength; | 821 m_iPosition = m_iLength; |
837 } | 822 } |
838 if (m_iPosition < 0) { | 823 if (m_iPosition < 0) { |
839 m_iPosition = 0; | 824 m_iPosition = 0; |
840 } | 825 } |
841 return m_iPosition; | 826 return m_iPosition; |
842 } | 827 } |
843 int32_t CFX_BufferStreamImp::GetPosition() { | 828 int32_t CFX_BufferStreamImp::GetPosition() { |
844 ASSERT(m_pData); | 829 ASSERT(m_pData); |
845 return m_iPosition; | 830 return m_iPosition; |
846 } | 831 } |
847 FX_BOOL CFX_BufferStreamImp::IsEOF() const { | 832 bool CFX_BufferStreamImp::IsEOF() const { |
848 ASSERT(m_pData); | 833 ASSERT(m_pData); |
849 return m_iPosition >= m_iLength; | 834 return m_iPosition >= m_iLength; |
850 } | 835 } |
851 int32_t CFX_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 836 int32_t CFX_BufferStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
852 ASSERT(m_pData); | 837 ASSERT(m_pData); |
853 ASSERT(pBuffer && iBufferSize > 0); | 838 ASSERT(pBuffer && iBufferSize > 0); |
854 int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize); | 839 int32_t iLen = std::min(m_iLength - m_iPosition, iBufferSize); |
855 if (iLen <= 0) { | 840 if (iLen <= 0) { |
856 return 0; | 841 return 0; |
857 } | 842 } |
858 FXSYS_memcpy(pBuffer, m_pData + m_iPosition, iLen); | 843 FXSYS_memcpy(pBuffer, m_pData + m_iPosition, iLen); |
859 m_iPosition += iLen; | 844 m_iPosition += iLen; |
860 return iLen; | 845 return iLen; |
861 } | 846 } |
862 int32_t CFX_BufferStreamImp::ReadString(FX_WCHAR* pStr, | 847 int32_t CFX_BufferStreamImp::ReadString(FX_WCHAR* pStr, |
863 int32_t iMaxLength, | 848 int32_t iMaxLength, |
864 FX_BOOL& bEOS) { | 849 bool& bEOS) { |
865 ASSERT(m_pData); | 850 ASSERT(m_pData); |
866 ASSERT(pStr && iMaxLength > 0); | 851 ASSERT(pStr && iMaxLength > 0); |
867 int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength); | 852 int32_t iLen = std::min((m_iLength - m_iPosition) / 2, iMaxLength); |
868 if (iLen <= 0) { | 853 if (iLen <= 0) { |
869 return 0; | 854 return 0; |
870 } | 855 } |
871 const FX_WCHAR* pSrc = (const FX_WCHAR*)(FX_CHAR*)(m_pData + m_iPosition); | 856 const FX_WCHAR* pSrc = (const FX_WCHAR*)(FX_CHAR*)(m_pData + m_iPosition); |
872 int32_t iCount = 0; | 857 int32_t iCount = 0; |
873 while (*pSrc && iCount < iLen) { | 858 while (*pSrc && iCount < iLen) { |
874 *pStr++ = *pSrc++; | 859 *pStr++ = *pSrc++; |
(...skipping 29 matching lines...) Expand all Loading... |
904 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); | 889 FXSYS_memcpy(m_pData + m_iPosition, pStr, iLen * 2); |
905 m_iPosition += iLen * 2; | 890 m_iPosition += iLen * 2; |
906 if (m_iPosition > m_iLength) { | 891 if (m_iPosition > m_iLength) { |
907 m_iLength = m_iPosition; | 892 m_iLength = m_iPosition; |
908 } | 893 } |
909 return iLen; | 894 return iLen; |
910 } | 895 } |
911 | 896 |
912 // static | 897 // static |
913 IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, | 898 IFX_Stream* IFX_Stream::CreateTextStream(IFX_Stream* pBaseStream, |
914 FX_BOOL bDeleteOnRelease) { | 899 bool bDeleteOnRelease) { |
915 ASSERT(pBaseStream); | 900 ASSERT(pBaseStream); |
916 return new CFX_TextStream(pBaseStream, bDeleteOnRelease); | 901 return new CFX_TextStream(pBaseStream, bDeleteOnRelease); |
917 } | 902 } |
918 | 903 |
919 CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream) | 904 CFX_TextStream::CFX_TextStream(IFX_Stream* pStream, bool bDelStream) |
920 : m_wCodePage(FX_CODEPAGE_DefANSI), | 905 : m_wCodePage(FX_CODEPAGE_DefANSI), |
921 m_wBOMLength(0), | 906 m_wBOMLength(0), |
922 m_dwBOM(0), | 907 m_dwBOM(0), |
923 m_pBuf(nullptr), | 908 m_pBuf(nullptr), |
924 m_iBufSize(0), | 909 m_iBufSize(0), |
925 m_bDelStream(bDelStream), | 910 m_bDelStream(bDelStream), |
926 m_pStreamImp(pStream), | 911 m_pStreamImp(pStream), |
927 m_iRefCount(1) { | 912 m_iRefCount(1) { |
928 ASSERT(m_pStreamImp); | 913 ASSERT(m_pStreamImp); |
929 m_pStreamImp->Retain(); | 914 m_pStreamImp->Retain(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 982 } |
998 int32_t CFX_TextStream::GetLength() const { | 983 int32_t CFX_TextStream::GetLength() const { |
999 return m_pStreamImp->GetLength(); | 984 return m_pStreamImp->GetLength(); |
1000 } | 985 } |
1001 int32_t CFX_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 986 int32_t CFX_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
1002 return m_pStreamImp->Seek(eSeek, iOffset); | 987 return m_pStreamImp->Seek(eSeek, iOffset); |
1003 } | 988 } |
1004 int32_t CFX_TextStream::GetPosition() { | 989 int32_t CFX_TextStream::GetPosition() { |
1005 return m_pStreamImp->GetPosition(); | 990 return m_pStreamImp->GetPosition(); |
1006 } | 991 } |
1007 FX_BOOL CFX_TextStream::IsEOF() const { | 992 bool CFX_TextStream::IsEOF() const { |
1008 return m_pStreamImp->IsEOF(); | 993 return m_pStreamImp->IsEOF(); |
1009 } | 994 } |
1010 int32_t CFX_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 995 int32_t CFX_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
1011 return m_pStreamImp->ReadData(pBuffer, iBufferSize); | 996 return m_pStreamImp->ReadData(pBuffer, iBufferSize); |
1012 } | 997 } |
1013 int32_t CFX_TextStream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 998 int32_t CFX_TextStream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
1014 return m_pStreamImp->WriteData(pBuffer, iBufferSize); | 999 return m_pStreamImp->WriteData(pBuffer, iBufferSize); |
1015 } | 1000 } |
1016 void CFX_TextStream::Flush() { | 1001 void CFX_TextStream::Flush() { |
1017 m_pStreamImp->Flush(); | 1002 m_pStreamImp->Flush(); |
1018 } | 1003 } |
1019 FX_BOOL CFX_TextStream::SetLength(int32_t iLength) { | 1004 bool CFX_TextStream::SetLength(int32_t iLength) { |
1020 return m_pStreamImp->SetLength(iLength); | 1005 return m_pStreamImp->SetLength(iLength); |
1021 } | 1006 } |
1022 uint16_t CFX_TextStream::GetCodePage() const { | 1007 uint16_t CFX_TextStream::GetCodePage() const { |
1023 return m_wCodePage; | 1008 return m_wCodePage; |
1024 } | 1009 } |
1025 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, | 1010 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, |
1026 int32_t iOffset, | 1011 int32_t iOffset, |
1027 int32_t iLength) { | 1012 int32_t iLength) { |
1028 IFX_Stream* pSR = | 1013 IFX_Stream* pSR = |
1029 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); | 1014 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); |
1030 if (!pSR) { | 1015 if (!pSR) { |
1031 return nullptr; | 1016 return nullptr; |
1032 } | 1017 } |
1033 if (dwAccess & FX_STREAMACCESS_Text) { | 1018 if (dwAccess & FX_STREAMACCESS_Text) { |
1034 return new CFX_TextStream(pSR, TRUE); | 1019 return new CFX_TextStream(pSR, true); |
1035 } | 1020 } |
1036 return pSR; | 1021 return pSR; |
1037 } | 1022 } |
1038 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { | 1023 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { |
1039 if (m_wBOMLength < 1) { | 1024 if (m_wBOMLength < 1) { |
1040 return 0; | 1025 return 0; |
1041 } | 1026 } |
1042 *(uint32_t*)bom = m_dwBOM; | 1027 *(uint32_t*)bom = m_dwBOM; |
1043 return m_wBOMLength; | 1028 return m_wBOMLength; |
1044 } | 1029 } |
1045 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { | 1030 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { |
1046 if (m_wBOMLength > 0) { | 1031 if (m_wBOMLength > 0) { |
1047 return m_wCodePage; | 1032 return m_wCodePage; |
1048 } | 1033 } |
1049 uint16_t v = m_wCodePage; | 1034 uint16_t v = m_wCodePage; |
1050 m_wCodePage = wCodePage; | 1035 m_wCodePage = wCodePage; |
1051 return v; | 1036 return v; |
1052 } | 1037 } |
1053 int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, | 1038 int32_t CFX_TextStream::ReadString(FX_WCHAR* pStr, |
1054 int32_t iMaxLength, | 1039 int32_t iMaxLength, |
1055 FX_BOOL& bEOS) { | 1040 bool& bEOS) { |
1056 ASSERT(pStr && iMaxLength > 0); | 1041 ASSERT(pStr && iMaxLength > 0); |
1057 if (!m_pStreamImp) { | 1042 if (!m_pStreamImp) { |
1058 return -1; | 1043 return -1; |
1059 } | 1044 } |
1060 int32_t iLen; | 1045 int32_t iLen; |
1061 if (m_wCodePage == FX_CODEPAGE_UTF16LE || | 1046 if (m_wCodePage == FX_CODEPAGE_UTF16LE || |
1062 m_wCodePage == FX_CODEPAGE_UTF16BE) { | 1047 m_wCodePage == FX_CODEPAGE_UTF16BE) { |
1063 int32_t iBytes = iMaxLength * 2; | 1048 int32_t iBytes = iMaxLength * 2; |
1064 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); | 1049 iLen = m_pStreamImp->ReadData((uint8_t*)pStr, iBytes); |
1065 iMaxLength = iLen / 2; | 1050 iMaxLength = iLen / 2; |
(...skipping 17 matching lines...) Expand all Loading... |
1083 if (!m_pBuf) { | 1068 if (!m_pBuf) { |
1084 m_pBuf = FX_Alloc(uint8_t, iBytes); | 1069 m_pBuf = FX_Alloc(uint8_t, iBytes); |
1085 m_iBufSize = iBytes; | 1070 m_iBufSize = iBytes; |
1086 } else if (iBytes > m_iBufSize) { | 1071 } else if (iBytes > m_iBufSize) { |
1087 m_pBuf = FX_Realloc(uint8_t, m_pBuf, iBytes); | 1072 m_pBuf = FX_Realloc(uint8_t, m_pBuf, iBytes); |
1088 m_iBufSize = iBytes; | 1073 m_iBufSize = iBytes; |
1089 } | 1074 } |
1090 iLen = m_pStreamImp->ReadData(m_pBuf, iBytes); | 1075 iLen = m_pStreamImp->ReadData(m_pBuf, iBytes); |
1091 int32_t iSrc = iLen; | 1076 int32_t iSrc = iLen; |
1092 int32_t iDecode = FX_DecodeString(m_wCodePage, (const FX_CHAR*)m_pBuf, | 1077 int32_t iDecode = FX_DecodeString(m_wCodePage, (const FX_CHAR*)m_pBuf, |
1093 &iSrc, pStr, &iMaxLength, TRUE); | 1078 &iSrc, pStr, &iMaxLength, true); |
1094 m_pStreamImp->Seek(FX_STREAMSEEK_Current, iSrc - iLen); | 1079 m_pStreamImp->Seek(FX_STREAMSEEK_Current, iSrc - iLen); |
1095 if (iDecode < 1) { | 1080 if (iDecode < 1) { |
1096 return -1; | 1081 return -1; |
1097 } | 1082 } |
1098 } else { | 1083 } else { |
1099 iMaxLength = 0; | 1084 iMaxLength = 0; |
1100 } | 1085 } |
1101 } | 1086 } |
1102 bEOS = m_pStreamImp->IsEOF(); | 1087 bEOS = m_pStreamImp->IsEOF(); |
1103 return iMaxLength; | 1088 return iMaxLength; |
(...skipping 23 matching lines...) Expand all Loading... |
1127 m_iPosition(0), | 1112 m_iPosition(0), |
1128 m_iStart(0), | 1113 m_iStart(0), |
1129 m_iLength(0), | 1114 m_iLength(0), |
1130 m_iRefCount(1) {} | 1115 m_iRefCount(1) {} |
1131 | 1116 |
1132 CFX_Stream::~CFX_Stream() { | 1117 CFX_Stream::~CFX_Stream() { |
1133 if (m_eStreamType != FX_STREAMTYPE_Stream) | 1118 if (m_eStreamType != FX_STREAMTYPE_Stream) |
1134 delete m_pStreamImp; | 1119 delete m_pStreamImp; |
1135 } | 1120 } |
1136 | 1121 |
1137 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, | 1122 bool CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess) { |
1138 uint32_t dwAccess) { | |
1139 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1123 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1140 return FALSE; | 1124 return false; |
1141 | 1125 |
1142 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1) | 1126 if (!pszSrcFileName || FXSYS_wcslen(pszSrcFileName) < 1) |
1143 return FALSE; | 1127 return false; |
1144 | 1128 |
1145 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp()); | 1129 std::unique_ptr<CFX_FileStreamImp> pImp(new CFX_FileStreamImp()); |
1146 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) | 1130 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) |
1147 return FALSE; | 1131 return false; |
1148 | 1132 |
1149 m_pStreamImp = pImp.release(); | 1133 m_pStreamImp = pImp.release(); |
1150 m_eStreamType = FX_STREAMTYPE_File; | 1134 m_eStreamType = FX_STREAMTYPE_File; |
1151 m_dwAccess = dwAccess; | 1135 m_dwAccess = dwAccess; |
1152 m_iLength = m_pStreamImp->GetLength(); | 1136 m_iLength = m_pStreamImp->GetLength(); |
1153 return TRUE; | 1137 return true; |
1154 } | 1138 } |
1155 | 1139 |
1156 FX_BOOL CFX_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, | 1140 bool CFX_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, |
1157 uint32_t dwAccess) { | 1141 uint32_t dwAccess) { |
1158 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1142 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1159 return FALSE; | 1143 return false; |
1160 | 1144 |
1161 if (!pFileRead) | 1145 if (!pFileRead) |
1162 return FALSE; | 1146 return false; |
1163 | 1147 |
1164 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); | 1148 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); |
1165 if (!pImp->LoadFileRead(pFileRead, dwAccess)) | 1149 if (!pImp->LoadFileRead(pFileRead, dwAccess)) |
1166 return FALSE; | 1150 return false; |
1167 | 1151 |
1168 m_pStreamImp = pImp.release(); | 1152 m_pStreamImp = pImp.release(); |
1169 m_eStreamType = FX_STREAMTYPE_File; | 1153 m_eStreamType = FX_STREAMTYPE_File; |
1170 m_dwAccess = dwAccess; | 1154 m_dwAccess = dwAccess; |
1171 m_iLength = m_pStreamImp->GetLength(); | 1155 m_iLength = m_pStreamImp->GetLength(); |
1172 return TRUE; | 1156 return true; |
1173 } | 1157 } |
1174 | 1158 |
1175 FX_BOOL CFX_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, | 1159 bool CFX_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, |
1176 uint32_t dwAccess) { | 1160 uint32_t dwAccess) { |
1177 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1161 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1178 return FALSE; | 1162 return false; |
1179 | 1163 |
1180 if (!pFileWrite) | 1164 if (!pFileWrite) |
1181 return FALSE; | 1165 return false; |
1182 | 1166 |
1183 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); | 1167 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); |
1184 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) | 1168 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) |
1185 return FALSE; | 1169 return false; |
1186 | 1170 |
1187 m_pStreamImp = pImp.release(); | 1171 m_pStreamImp = pImp.release(); |
1188 m_eStreamType = FX_STREAMTYPE_File; | 1172 m_eStreamType = FX_STREAMTYPE_File; |
1189 m_dwAccess = dwAccess; | 1173 m_dwAccess = dwAccess; |
1190 m_iLength = m_pStreamImp->GetLength(); | 1174 m_iLength = m_pStreamImp->GetLength(); |
1191 return TRUE; | 1175 return true; |
1192 } | 1176 } |
1193 | 1177 |
1194 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, | 1178 bool CFX_Stream::LoadBuffer(uint8_t* pData, |
1195 int32_t iTotalSize, | 1179 int32_t iTotalSize, |
1196 uint32_t dwAccess) { | 1180 uint32_t dwAccess) { |
1197 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1181 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1198 return FALSE; | 1182 return false; |
1199 | 1183 |
1200 if (!pData || iTotalSize < 1) | 1184 if (!pData || iTotalSize < 1) |
1201 return FALSE; | 1185 return false; |
1202 | 1186 |
1203 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp()); | 1187 std::unique_ptr<CFX_BufferStreamImp> pImp(new CFX_BufferStreamImp()); |
1204 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess)) | 1188 if (!pImp->LoadBuffer(pData, iTotalSize, dwAccess)) |
1205 return FALSE; | 1189 return false; |
1206 | 1190 |
1207 m_pStreamImp = pImp.release(); | 1191 m_pStreamImp = pImp.release(); |
1208 m_eStreamType = FX_STREAMTYPE_Buffer; | 1192 m_eStreamType = FX_STREAMTYPE_Buffer; |
1209 m_dwAccess = dwAccess; | 1193 m_dwAccess = dwAccess; |
1210 m_iLength = m_pStreamImp->GetLength(); | 1194 m_iLength = m_pStreamImp->GetLength(); |
1211 return TRUE; | 1195 return true; |
1212 } | 1196 } |
1213 | 1197 |
1214 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, | 1198 bool CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, |
1215 int32_t iFileSize, | 1199 int32_t iFileSize, |
1216 uint32_t dwAccess, | 1200 uint32_t dwAccess, |
1217 FX_BOOL bReleaseBufferRead) { | 1201 bool bReleaseBufferRead) { |
1218 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1202 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1219 return FALSE; | 1203 return false; |
1220 | 1204 |
1221 if (!pBufferRead) | 1205 if (!pBufferRead) |
1222 return FALSE; | 1206 return false; |
1223 | 1207 |
1224 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp); | 1208 std::unique_ptr<CFX_BufferReadStreamImp> pImp(new CFX_BufferReadStreamImp); |
1225 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, | 1209 if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, |
1226 bReleaseBufferRead)) | 1210 bReleaseBufferRead)) |
1227 return FALSE; | 1211 return false; |
1228 | 1212 |
1229 m_pStreamImp = pImp.release(); | 1213 m_pStreamImp = pImp.release(); |
1230 m_eStreamType = FX_STREAMTYPE_BufferRead; | 1214 m_eStreamType = FX_STREAMTYPE_BufferRead; |
1231 m_dwAccess = dwAccess; | 1215 m_dwAccess = dwAccess; |
1232 m_iLength = m_pStreamImp->GetLength(); | 1216 m_iLength = m_pStreamImp->GetLength(); |
1233 return TRUE; | 1217 return true; |
1234 } | 1218 } |
1235 | 1219 |
1236 void CFX_Stream::Release() { | 1220 void CFX_Stream::Release() { |
1237 if (--m_iRefCount < 1) { | 1221 if (--m_iRefCount < 1) { |
1238 delete this; | 1222 delete this; |
1239 } | 1223 } |
1240 } | 1224 } |
1241 IFX_Stream* CFX_Stream::Retain() { | 1225 IFX_Stream* CFX_Stream::Retain() { |
1242 m_iRefCount++; | 1226 m_iRefCount++; |
1243 return this; | 1227 return this; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 int32_t CFX_Stream::GetPosition() { | 1269 int32_t CFX_Stream::GetPosition() { |
1286 if (!m_pStreamImp) { | 1270 if (!m_pStreamImp) { |
1287 return -1; | 1271 return -1; |
1288 } | 1272 } |
1289 if (m_eStreamType == FX_STREAMTYPE_File || | 1273 if (m_eStreamType == FX_STREAMTYPE_File || |
1290 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1274 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1291 return m_iPosition = m_pStreamImp->GetPosition(); | 1275 return m_iPosition = m_pStreamImp->GetPosition(); |
1292 } | 1276 } |
1293 return m_iPosition - m_iStart; | 1277 return m_iPosition - m_iStart; |
1294 } | 1278 } |
1295 FX_BOOL CFX_Stream::IsEOF() const { | 1279 bool CFX_Stream::IsEOF() const { |
1296 if (!m_pStreamImp) { | 1280 if (!m_pStreamImp) { |
1297 return TRUE; | 1281 return true; |
1298 } | 1282 } |
1299 if (m_eStreamType == FX_STREAMTYPE_File || | 1283 if (m_eStreamType == FX_STREAMTYPE_File || |
1300 m_eStreamType == FX_STREAMTYPE_Buffer) { | 1284 m_eStreamType == FX_STREAMTYPE_Buffer) { |
1301 return m_pStreamImp->IsEOF(); | 1285 return m_pStreamImp->IsEOF(); |
1302 } | 1286 } |
1303 return m_iPosition >= m_iStart + m_iLength; | 1287 return m_iPosition >= m_iStart + m_iLength; |
1304 } | 1288 } |
1305 int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 1289 int32_t CFX_Stream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
1306 ASSERT(pBuffer && iBufferSize > 0); | 1290 ASSERT(pBuffer && iBufferSize > 0); |
1307 if (!m_pStreamImp) { | 1291 if (!m_pStreamImp) { |
1308 return -1; | 1292 return -1; |
1309 } | 1293 } |
1310 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); | 1294 int32_t iLen = std::min(m_iStart + m_iLength - m_iPosition, iBufferSize); |
1311 if (iLen <= 0) { | 1295 if (iLen <= 0) { |
1312 return 0; | 1296 return 0; |
1313 } | 1297 } |
1314 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1298 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1315 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1299 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1316 } | 1300 } |
1317 iLen = m_pStreamImp->ReadData(pBuffer, iLen); | 1301 iLen = m_pStreamImp->ReadData(pBuffer, iLen); |
1318 m_iPosition = m_pStreamImp->GetPosition(); | 1302 m_iPosition = m_pStreamImp->GetPosition(); |
1319 return iLen; | 1303 return iLen; |
1320 } | 1304 } |
1321 int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, | 1305 int32_t CFX_Stream::ReadString(FX_WCHAR* pStr, int32_t iMaxLength, bool& bEOS) { |
1322 int32_t iMaxLength, | |
1323 FX_BOOL& bEOS) { | |
1324 ASSERT(pStr && iMaxLength > 0); | 1306 ASSERT(pStr && iMaxLength > 0); |
1325 if (!m_pStreamImp) { | 1307 if (!m_pStreamImp) { |
1326 return -1; | 1308 return -1; |
1327 } | 1309 } |
1328 int32_t iEnd = m_iStart + m_iLength; | 1310 int32_t iEnd = m_iStart + m_iLength; |
1329 int32_t iLen = iEnd - m_iPosition; | 1311 int32_t iLen = iEnd - m_iPosition; |
1330 iLen = std::min(iEnd / 2, iMaxLength); | 1312 iLen = std::min(iEnd / 2, iMaxLength); |
1331 if (iLen <= 0) { | 1313 if (iLen <= 0) { |
1332 return 0; | 1314 return 0; |
1333 } | 1315 } |
1334 if (m_pStreamImp->GetPosition() != m_iPosition) { | 1316 if (m_pStreamImp->GetPosition() != m_iPosition) { |
1335 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); | 1317 m_pStreamImp->Seek(FX_STREAMSEEK_Begin, m_iPosition); |
1336 } | 1318 } |
1337 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); | 1319 iLen = m_pStreamImp->ReadString(pStr, iLen, bEOS); |
1338 m_iPosition = m_pStreamImp->GetPosition(); | 1320 m_iPosition = m_pStreamImp->GetPosition(); |
1339 if (iLen > 0 && m_iPosition >= iEnd) { | 1321 if (iLen > 0 && m_iPosition >= iEnd) { |
1340 bEOS = TRUE; | 1322 bEOS = true; |
1341 } | 1323 } |
1342 return iLen; | 1324 return iLen; |
1343 } | 1325 } |
1344 | 1326 |
1345 int32_t CFX_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 1327 int32_t CFX_Stream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
1346 ASSERT(pBuffer && iBufferSize > 0); | 1328 ASSERT(pBuffer && iBufferSize > 0); |
1347 if (!m_pStreamImp) { | 1329 if (!m_pStreamImp) { |
1348 return -1; | 1330 return -1; |
1349 } | 1331 } |
1350 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1332 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 } | 1378 } |
1397 void CFX_Stream::Flush() { | 1379 void CFX_Stream::Flush() { |
1398 if (!m_pStreamImp) { | 1380 if (!m_pStreamImp) { |
1399 return; | 1381 return; |
1400 } | 1382 } |
1401 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1383 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1402 return; | 1384 return; |
1403 } | 1385 } |
1404 m_pStreamImp->Flush(); | 1386 m_pStreamImp->Flush(); |
1405 } | 1387 } |
1406 FX_BOOL CFX_Stream::SetLength(int32_t iLength) { | 1388 bool CFX_Stream::SetLength(int32_t iLength) { |
1407 if (!m_pStreamImp) { | 1389 if (!m_pStreamImp) { |
1408 return FALSE; | 1390 return false; |
1409 } | 1391 } |
1410 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { | 1392 if ((m_dwAccess & FX_STREAMACCESS_Write) == 0) { |
1411 return FALSE; | 1393 return false; |
1412 } | 1394 } |
1413 return m_pStreamImp->SetLength(iLength); | 1395 return m_pStreamImp->SetLength(iLength); |
1414 } | 1396 } |
1415 int32_t CFX_Stream::GetBOM(uint8_t bom[4]) const { | 1397 int32_t CFX_Stream::GetBOM(uint8_t bom[4]) const { |
1416 if (!m_pStreamImp) { | 1398 if (!m_pStreamImp) { |
1417 return -1; | 1399 return -1; |
1418 } | 1400 } |
1419 return 0; | 1401 return 0; |
1420 } | 1402 } |
1421 uint16_t CFX_Stream::GetCodePage() const { | 1403 uint16_t CFX_Stream::GetCodePage() const { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 } | 1440 } |
1459 CFX_Stream* pShared = new CFX_Stream; | 1441 CFX_Stream* pShared = new CFX_Stream; |
1460 pShared->m_eStreamType = FX_STREAMTYPE_Stream; | 1442 pShared->m_eStreamType = FX_STREAMTYPE_Stream; |
1461 pShared->m_pStreamImp = m_pStreamImp; | 1443 pShared->m_pStreamImp = m_pStreamImp; |
1462 pShared->m_dwAccess = dwAccess; | 1444 pShared->m_dwAccess = dwAccess; |
1463 pShared->m_iTotalSize = iLength; | 1445 pShared->m_iTotalSize = iLength; |
1464 pShared->m_iPosition = iStart; | 1446 pShared->m_iPosition = iStart; |
1465 pShared->m_iStart = iStart; | 1447 pShared->m_iStart = iStart; |
1466 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; | 1448 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; |
1467 if (dwAccess & FX_STREAMACCESS_Text) { | 1449 if (dwAccess & FX_STREAMACCESS_Text) { |
1468 return IFX_Stream::CreateTextStream(pShared, TRUE); | 1450 return IFX_Stream::CreateTextStream(pShared, true); |
1469 } | 1451 } |
1470 return pShared; | 1452 return pShared; |
1471 } | 1453 } |
1472 | 1454 |
1473 IFX_SeekableReadStream* FX_CreateFileRead(IFX_Stream* pBaseStream, | 1455 IFX_SeekableReadStream* FX_CreateFileRead(IFX_Stream* pBaseStream, |
1474 bool bReleaseStream) { | 1456 bool bReleaseStream) { |
1475 ASSERT(pBaseStream); | 1457 ASSERT(pBaseStream); |
1476 return new CFGAS_FileRead(pBaseStream, bReleaseStream); | 1458 return new CFGAS_FileRead(pBaseStream, bReleaseStream); |
1477 } | 1459 } |
1478 | 1460 |
(...skipping 12 matching lines...) Expand all Loading... |
1491 | 1473 |
1492 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { | 1474 bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { |
1493 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1475 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
1494 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1476 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
1495 return iLen == (int32_t)size; | 1477 return iLen == (int32_t)size; |
1496 } | 1478 } |
1497 | 1479 |
1498 void CFGAS_FileRead::Release() { | 1480 void CFGAS_FileRead::Release() { |
1499 delete this; | 1481 delete this; |
1500 } | 1482 } |
OLD | NEW |