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_ |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 int32_t m_iTotalSize; | 97 int32_t m_iTotalSize; |
98 int32_t m_iPosition; | 98 int32_t m_iPosition; |
99 int32_t m_iLength; | 99 int32_t m_iLength; |
100 }; | 100 }; |
101 | 101 |
102 class CFX_FileReadStreamImp : public IFX_StreamImp { | 102 class CFX_FileReadStreamImp : public IFX_StreamImp { |
103 public: | 103 public: |
104 CFX_FileReadStreamImp(); | 104 CFX_FileReadStreamImp(); |
105 ~CFX_FileReadStreamImp() override {} | 105 ~CFX_FileReadStreamImp() override {} |
106 | 106 |
107 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); | 107 FX_BOOL LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); |
108 | 108 |
109 // IFX_StreamImp: | 109 // IFX_StreamImp: |
110 int32_t GetLength() const override; | 110 int32_t GetLength() const override; |
111 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 111 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
112 int32_t GetPosition() override { return m_iPosition; } | 112 int32_t GetPosition() override { return m_iPosition; } |
113 FX_BOOL IsEOF() const override; | 113 FX_BOOL IsEOF() const override; |
114 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; | 114 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override; |
115 int32_t ReadString(FX_WCHAR* pStr, | 115 int32_t ReadString(FX_WCHAR* pStr, |
116 int32_t iMaxLength, | 116 int32_t iMaxLength, |
117 FX_BOOL& bEOS) override; | 117 FX_BOOL& bEOS) override; |
118 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { | 118 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override { |
119 return 0; | 119 return 0; |
120 } | 120 } |
121 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { | 121 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override { |
122 return 0; | 122 return 0; |
123 } | 123 } |
124 void Flush() override {} | 124 void Flush() override {} |
125 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | 125 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } |
126 | 126 |
127 protected: | 127 protected: |
128 IFX_FileRead* m_pFileRead; | 128 IFX_SeekableReadStream* m_pFileRead; |
129 int32_t m_iPosition; | 129 int32_t m_iPosition; |
130 int32_t m_iLength; | 130 int32_t m_iLength; |
131 }; | 131 }; |
132 | 132 |
133 class CFX_BufferReadStreamImp : public IFX_StreamImp { | 133 class CFX_BufferReadStreamImp : public IFX_StreamImp { |
134 public: | 134 public: |
135 CFX_BufferReadStreamImp(); | 135 CFX_BufferReadStreamImp(); |
136 ~CFX_BufferReadStreamImp() override; | 136 ~CFX_BufferReadStreamImp() override; |
137 | 137 |
138 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 138 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, |
(...skipping 24 matching lines...) Expand all Loading... |
163 FX_BOOL m_bReleaseBufferRead; | 163 FX_BOOL m_bReleaseBufferRead; |
164 int32_t m_iPosition; | 164 int32_t m_iPosition; |
165 int32_t m_iBufferSize; | 165 int32_t m_iBufferSize; |
166 }; | 166 }; |
167 | 167 |
168 class CFX_FileWriteStreamImp : public IFX_StreamImp { | 168 class CFX_FileWriteStreamImp : public IFX_StreamImp { |
169 public: | 169 public: |
170 CFX_FileWriteStreamImp(); | 170 CFX_FileWriteStreamImp(); |
171 ~CFX_FileWriteStreamImp() override {} | 171 ~CFX_FileWriteStreamImp() override {} |
172 | 172 |
173 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); | 173 FX_BOOL LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); |
174 | 174 |
175 // IFX_StreamImp: | 175 // IFX_StreamImp: |
176 int32_t GetLength() const override; | 176 int32_t GetLength() const override; |
177 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; | 177 int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override; |
178 int32_t GetPosition() override { return m_iPosition; } | 178 int32_t GetPosition() override { return m_iPosition; } |
179 FX_BOOL IsEOF() const override; | 179 FX_BOOL IsEOF() const override; |
180 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } | 180 int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override { return 0; } |
181 int32_t ReadString(FX_WCHAR* pStr, | 181 int32_t ReadString(FX_WCHAR* pStr, |
182 int32_t iMaxLength, | 182 int32_t iMaxLength, |
183 FX_BOOL& bEOS) override { | 183 FX_BOOL& bEOS) override { |
184 return 0; | 184 return 0; |
185 } | 185 } |
186 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; | 186 int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override; |
187 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; | 187 int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) override; |
188 void Flush() override; | 188 void Flush() override; |
189 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } | 189 FX_BOOL SetLength(int32_t iLength) override { return FALSE; } |
190 | 190 |
191 protected: | 191 protected: |
192 IFX_FileWrite* m_pFileWrite; | 192 IFX_SeekableWriteStream* m_pFileWrite; |
193 int32_t m_iPosition; | 193 int32_t m_iPosition; |
194 }; | 194 }; |
195 | 195 |
196 enum FX_STREAMTYPE { | 196 enum FX_STREAMTYPE { |
197 FX_SREAMTYPE_Unknown = 0, | 197 FX_SREAMTYPE_Unknown = 0, |
198 FX_STREAMTYPE_File, | 198 FX_STREAMTYPE_File, |
199 FX_STREAMTYPE_Buffer, | 199 FX_STREAMTYPE_Buffer, |
200 FX_STREAMTYPE_Stream, | 200 FX_STREAMTYPE_Stream, |
201 FX_STREAMTYPE_BufferRead, | 201 FX_STREAMTYPE_BufferRead, |
202 }; | 202 }; |
203 | 203 |
204 class CFX_Stream : public IFX_Stream { | 204 class CFX_Stream : public IFX_Stream { |
205 public: | 205 public: |
206 CFX_Stream(); | 206 CFX_Stream(); |
207 ~CFX_Stream() override; | 207 ~CFX_Stream() override; |
208 | 208 |
209 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); | 209 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
210 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); | 210 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
211 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); | 211 FX_BOOL LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); |
212 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); | 212 FX_BOOL LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); |
213 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 213 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, |
214 int32_t iFileSize, | 214 int32_t iFileSize, |
215 uint32_t dwAccess, | 215 uint32_t dwAccess, |
216 FX_BOOL bReleaseBufferRead); | 216 FX_BOOL bReleaseBufferRead); |
217 | 217 |
218 // IFX_Stream | 218 // IFX_Stream |
219 void Release() override; | 219 void Release() override; |
220 IFX_Stream* Retain() override; | 220 IFX_Stream* Retain() override; |
221 uint32_t GetAccessModes() const override; | 221 uint32_t GetAccessModes() const override; |
222 int32_t GetLength() const override; | 222 int32_t GetLength() const override; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 int32_t m_wBOMLength; | 282 int32_t m_wBOMLength; |
283 uint32_t m_dwBOM; | 283 uint32_t m_dwBOM; |
284 uint8_t* m_pBuf; | 284 uint8_t* m_pBuf; |
285 int32_t m_iBufSize; | 285 int32_t m_iBufSize; |
286 FX_BOOL m_bDelStream; | 286 FX_BOOL m_bDelStream; |
287 IFX_Stream* m_pStreamImp; | 287 IFX_Stream* m_pStreamImp; |
288 int32_t m_iRefCount; | 288 int32_t m_iRefCount; |
289 void InitStream(); | 289 void InitStream(); |
290 }; | 290 }; |
291 | 291 |
292 class CFGAS_FileRead : public IFX_FileRead { | 292 class CFGAS_FileRead : public IFX_SeekableReadStream { |
293 public: | 293 public: |
294 CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream); | 294 CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream); |
295 ~CFGAS_FileRead() override; | 295 ~CFGAS_FileRead() override; |
296 | 296 |
297 // IFX_FileRead | 297 // IFX_SeekableReadStream |
298 void Release() override; | 298 void Release() override; |
299 FX_FILESIZE GetSize() override; | 299 FX_FILESIZE GetSize() override; |
300 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 300 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
301 | 301 |
302 protected: | 302 protected: |
303 FX_BOOL m_bReleaseStream; | 303 FX_BOOL m_bReleaseStream; |
304 IFX_Stream* m_pStream; | 304 IFX_Stream* m_pStream; |
305 }; | 305 }; |
306 | 306 |
307 int32_t FileLength(FXSYS_FILE* file) { | 307 int32_t FileLength(FXSYS_FILE* file) { |
(...skipping 21 matching lines...) Expand all Loading... |
329 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); | 329 ::SetFilePointer(hFile, (int32_t)dwPos, 0, FILE_BEGIN); |
330 return bRet; | 330 return bRet; |
331 #else | 331 #else |
332 return FALSE; | 332 return FALSE; |
333 #endif | 333 #endif |
334 } | 334 } |
335 | 335 |
336 } // namespace | 336 } // namespace |
337 | 337 |
338 // static | 338 // static |
339 IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, | 339 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, |
340 uint32_t dwAccess) { | 340 uint32_t dwAccess) { |
341 CFX_Stream* pSR = new CFX_Stream; | 341 CFX_Stream* pSR = new CFX_Stream; |
342 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { | 342 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { |
343 pSR->Release(); | 343 pSR->Release(); |
344 return nullptr; | 344 return nullptr; |
345 } | 345 } |
346 if (dwAccess & FX_STREAMACCESS_Text) { | 346 if (dwAccess & FX_STREAMACCESS_Text) { |
347 return new CFX_TextStream(pSR, TRUE); | 347 return new CFX_TextStream(pSR, TRUE); |
348 } | 348 } |
349 return pSR; | 349 return pSR; |
350 } | 350 } |
351 | 351 |
352 // static | 352 // static |
353 IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, | 353 IFX_Stream* IFX_Stream::CreateStream(IFX_SeekableWriteStream* pFileWrite, |
354 uint32_t dwAccess) { | 354 uint32_t dwAccess) { |
355 CFX_Stream* pSR = new CFX_Stream; | 355 CFX_Stream* pSR = new CFX_Stream; |
356 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { | 356 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { |
357 pSR->Release(); | 357 pSR->Release(); |
358 return nullptr; | 358 return nullptr; |
359 } | 359 } |
360 if (dwAccess & FX_STREAMACCESS_Text) { | 360 if (dwAccess & FX_STREAMACCESS_Text) { |
361 return new CFX_TextStream(pSR, TRUE); | 361 return new CFX_TextStream(pSR, TRUE); |
362 } | 362 } |
363 return pSR; | 363 return pSR; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 FXSYS_fflush(m_hFile); | 542 FXSYS_fflush(m_hFile); |
543 } | 543 } |
544 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { | 544 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { |
545 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); | 545 ASSERT(m_hFile && (GetAccessModes() & FX_STREAMACCESS_Write) != 0); |
546 FX_BOOL bRet = FileSetSize(m_hFile, iLength); | 546 FX_BOOL bRet = FileSetSize(m_hFile, iLength); |
547 m_iLength = FileLength(m_hFile); | 547 m_iLength = FileLength(m_hFile); |
548 return bRet; | 548 return bRet; |
549 } | 549 } |
550 CFX_FileReadStreamImp::CFX_FileReadStreamImp() | 550 CFX_FileReadStreamImp::CFX_FileReadStreamImp() |
551 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} | 551 : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} |
552 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead, | 552 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_SeekableReadStream* pFileRead, |
553 uint32_t dwAccess) { | 553 uint32_t dwAccess) { |
554 ASSERT(!m_pFileRead && pFileRead); | 554 ASSERT(!m_pFileRead && pFileRead); |
555 if (dwAccess & FX_STREAMACCESS_Write) { | 555 if (dwAccess & FX_STREAMACCESS_Write) { |
556 return FALSE; | 556 return FALSE; |
557 } | 557 } |
558 m_pFileRead = pFileRead; | 558 m_pFileRead = pFileRead; |
559 m_iLength = m_pFileRead->GetSize(); | 559 m_iLength = m_pFileRead->GetSize(); |
560 return TRUE; | 560 return TRUE; |
561 } | 561 } |
562 int32_t CFX_FileReadStreamImp::GetLength() const { | 562 int32_t CFX_FileReadStreamImp::GetLength() const { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } | 737 } |
738 int32_t i = 0; | 738 int32_t i = 0; |
739 while (i < iMaxLength && pStr[i] != L'\0') { | 739 while (i < iMaxLength && pStr[i] != L'\0') { |
740 ++i; | 740 ++i; |
741 } | 741 } |
742 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; | 742 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; |
743 return i; | 743 return i; |
744 } | 744 } |
745 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() | 745 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() |
746 : m_pFileWrite(nullptr), m_iPosition(0) {} | 746 : m_pFileWrite(nullptr), m_iPosition(0) {} |
747 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite(IFX_FileWrite* pFileWrite, | 747 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite( |
748 uint32_t dwAccess) { | 748 IFX_SeekableWriteStream* pFileWrite, |
| 749 uint32_t dwAccess) { |
749 ASSERT(!m_pFileWrite && pFileWrite); | 750 ASSERT(!m_pFileWrite && pFileWrite); |
750 if (dwAccess & FX_STREAMACCESS_Read) { | 751 if (dwAccess & FX_STREAMACCESS_Read) { |
751 return FALSE; | 752 return FALSE; |
752 } | 753 } |
753 if (dwAccess & FX_STREAMACCESS_Append) { | 754 if (dwAccess & FX_STREAMACCESS_Append) { |
754 m_iPosition = pFileWrite->GetSize(); | 755 m_iPosition = pFileWrite->GetSize(); |
755 } | 756 } |
756 m_pFileWrite = pFileWrite; | 757 m_pFileWrite = pFileWrite; |
757 return TRUE; | 758 return TRUE; |
758 } | 759 } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) | 1146 if (!pImp->LoadFile(pszSrcFileName, dwAccess)) |
1146 return FALSE; | 1147 return FALSE; |
1147 | 1148 |
1148 m_pStreamImp = pImp.release(); | 1149 m_pStreamImp = pImp.release(); |
1149 m_eStreamType = FX_STREAMTYPE_File; | 1150 m_eStreamType = FX_STREAMTYPE_File; |
1150 m_dwAccess = dwAccess; | 1151 m_dwAccess = dwAccess; |
1151 m_iLength = m_pStreamImp->GetLength(); | 1152 m_iLength = m_pStreamImp->GetLength(); |
1152 return TRUE; | 1153 return TRUE; |
1153 } | 1154 } |
1154 | 1155 |
1155 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) { | 1156 FX_BOOL CFX_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, |
| 1157 uint32_t dwAccess) { |
1156 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1158 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1157 return FALSE; | 1159 return FALSE; |
1158 | 1160 |
1159 if (!pFileRead) | 1161 if (!pFileRead) |
1160 return FALSE; | 1162 return FALSE; |
1161 | 1163 |
1162 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); | 1164 std::unique_ptr<CFX_FileReadStreamImp> pImp(new CFX_FileReadStreamImp()); |
1163 if (!pImp->LoadFileRead(pFileRead, dwAccess)) | 1165 if (!pImp->LoadFileRead(pFileRead, dwAccess)) |
1164 return FALSE; | 1166 return FALSE; |
1165 | 1167 |
1166 m_pStreamImp = pImp.release(); | 1168 m_pStreamImp = pImp.release(); |
1167 m_eStreamType = FX_STREAMTYPE_File; | 1169 m_eStreamType = FX_STREAMTYPE_File; |
1168 m_dwAccess = dwAccess; | 1170 m_dwAccess = dwAccess; |
1169 m_iLength = m_pStreamImp->GetLength(); | 1171 m_iLength = m_pStreamImp->GetLength(); |
1170 return TRUE; | 1172 return TRUE; |
1171 } | 1173 } |
1172 | 1174 |
1173 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, | 1175 FX_BOOL CFX_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, |
1174 uint32_t dwAccess) { | 1176 uint32_t dwAccess) { |
1175 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) | 1177 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) |
1176 return FALSE; | 1178 return FALSE; |
1177 | 1179 |
1178 if (!pFileWrite) | 1180 if (!pFileWrite) |
1179 return FALSE; | 1181 return FALSE; |
1180 | 1182 |
1181 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); | 1183 std::unique_ptr<CFX_FileWriteStreamImp> pImp(new CFX_FileWriteStreamImp()); |
1182 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) | 1184 if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) |
1183 return FALSE; | 1185 return FALSE; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1460 pShared->m_dwAccess = dwAccess; | 1462 pShared->m_dwAccess = dwAccess; |
1461 pShared->m_iTotalSize = iLength; | 1463 pShared->m_iTotalSize = iLength; |
1462 pShared->m_iPosition = iStart; | 1464 pShared->m_iPosition = iStart; |
1463 pShared->m_iStart = iStart; | 1465 pShared->m_iStart = iStart; |
1464 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; | 1466 pShared->m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iLength; |
1465 if (dwAccess & FX_STREAMACCESS_Text) { | 1467 if (dwAccess & FX_STREAMACCESS_Text) { |
1466 return IFX_Stream::CreateTextStream(pShared, TRUE); | 1468 return IFX_Stream::CreateTextStream(pShared, TRUE); |
1467 } | 1469 } |
1468 return pShared; | 1470 return pShared; |
1469 } | 1471 } |
1470 IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, | 1472 IFX_SeekableReadStream* FX_CreateFileRead(IFX_Stream* pBaseStream, |
1471 FX_BOOL bReleaseStream) { | 1473 FX_BOOL bReleaseStream) { |
1472 ASSERT(pBaseStream); | 1474 ASSERT(pBaseStream); |
1473 return new CFGAS_FileRead(pBaseStream, bReleaseStream); | 1475 return new CFGAS_FileRead(pBaseStream, bReleaseStream); |
1474 } | 1476 } |
1475 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream) | 1477 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream) |
1476 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { | 1478 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { |
1477 ASSERT(m_pStream); | 1479 ASSERT(m_pStream); |
1478 } | 1480 } |
1479 CFGAS_FileRead::~CFGAS_FileRead() { | 1481 CFGAS_FileRead::~CFGAS_FileRead() { |
1480 if (m_bReleaseStream) { | 1482 if (m_bReleaseStream) { |
1481 m_pStream->Release(); | 1483 m_pStream->Release(); |
1482 } | 1484 } |
1483 } | 1485 } |
1484 FX_FILESIZE CFGAS_FileRead::GetSize() { | 1486 FX_FILESIZE CFGAS_FileRead::GetSize() { |
1485 return (FX_FILESIZE)m_pStream->GetLength(); | 1487 return (FX_FILESIZE)m_pStream->GetLength(); |
1486 } | 1488 } |
1487 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, | 1489 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, |
1488 FX_FILESIZE offset, | 1490 FX_FILESIZE offset, |
1489 size_t size) { | 1491 size_t size) { |
1490 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1492 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
1491 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1493 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
1492 return iLen == (int32_t)size; | 1494 return iLen == (int32_t)size; |
1493 } | 1495 } |
1494 | 1496 |
1495 void CFGAS_FileRead::Release() { | 1497 void CFGAS_FileRead::Release() { |
1496 delete this; | 1498 delete this; |
1497 } | 1499 } |
OLD | NEW |