| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 void InitStream(); | 289 void InitStream(); |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 class CFGAS_FileRead : public IFX_FileRead { | 292 class CFGAS_FileRead : public IFX_FileRead { |
| 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_FileRead |
| 298 void Release() override; | 298 void Release() override; |
| 299 FX_BOOL IsEOF() override; |
| 299 FX_FILESIZE GetSize() override; | 300 FX_FILESIZE GetSize() override; |
| 300 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 301 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
| 301 | 302 |
| 302 protected: | 303 protected: |
| 303 FX_BOOL m_bReleaseStream; | 304 FX_BOOL m_bReleaseStream; |
| 304 IFX_Stream* m_pStream; | 305 IFX_Stream* m_pStream; |
| 306 FX_FILESIZE m_nCurPos; |
| 305 }; | 307 }; |
| 306 | 308 |
| 307 int32_t FileLength(FXSYS_FILE* file) { | 309 int32_t FileLength(FXSYS_FILE* file) { |
| 308 ASSERT(file); | 310 ASSERT(file); |
| 309 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ | 311 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ |
| 310 return _filelength(_fileno(file)); | 312 return _filelength(_fileno(file)); |
| 311 #else | 313 #else |
| 312 int32_t iPos = FXSYS_ftell(file); | 314 int32_t iPos = FXSYS_ftell(file); |
| 313 FXSYS_fseek(file, 0, FXSYS_SEEK_END); | 315 FXSYS_fseek(file, 0, FXSYS_SEEK_END); |
| 314 int32_t iLen = FXSYS_ftell(file); | 316 int32_t iLen = FXSYS_ftell(file); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } | 585 } |
| 584 FX_BOOL CFX_FileReadStreamImp::IsEOF() const { | 586 FX_BOOL CFX_FileReadStreamImp::IsEOF() const { |
| 585 return m_iPosition >= m_iLength; | 587 return m_iPosition >= m_iLength; |
| 586 } | 588 } |
| 587 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 589 int32_t CFX_FileReadStreamImp::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
| 588 ASSERT(m_pFileRead); | 590 ASSERT(m_pFileRead); |
| 589 ASSERT(pBuffer && iBufferSize > 0); | 591 ASSERT(pBuffer && iBufferSize > 0); |
| 590 if (iBufferSize > m_iLength - m_iPosition) { | 592 if (iBufferSize > m_iLength - m_iPosition) { |
| 591 iBufferSize = m_iLength - m_iPosition; | 593 iBufferSize = m_iLength - m_iPosition; |
| 592 } | 594 } |
| 593 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize)) { | 595 if (m_pFileRead->ReadBlock(pBuffer, m_iPosition, iBufferSize) == |
| 596 iBufferSize || |
| 597 m_pFileRead->IsEOF()) { |
| 594 m_iPosition += iBufferSize; | 598 m_iPosition += iBufferSize; |
| 595 return iBufferSize; | 599 return iBufferSize; |
| 596 } | 600 } |
| 597 return 0; | 601 return 0; |
| 598 } | 602 } |
| 599 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, | 603 int32_t CFX_FileReadStreamImp::ReadString(FX_WCHAR* pStr, |
| 600 int32_t iMaxLength, | 604 int32_t iMaxLength, |
| 601 FX_BOOL& bEOS) { | 605 FX_BOOL& bEOS) { |
| 602 ASSERT(m_pFileRead); | 606 ASSERT(m_pFileRead); |
| 603 ASSERT(pStr && iMaxLength > 0); | 607 ASSERT(pStr && iMaxLength > 0); |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 return IFX_Stream::CreateTextStream(pShared, TRUE); | 1470 return IFX_Stream::CreateTextStream(pShared, TRUE); |
| 1467 } | 1471 } |
| 1468 return pShared; | 1472 return pShared; |
| 1469 } | 1473 } |
| 1470 IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, | 1474 IFX_FileRead* FX_CreateFileRead(IFX_Stream* pBaseStream, |
| 1471 FX_BOOL bReleaseStream) { | 1475 FX_BOOL bReleaseStream) { |
| 1472 ASSERT(pBaseStream); | 1476 ASSERT(pBaseStream); |
| 1473 return new CFGAS_FileRead(pBaseStream, bReleaseStream); | 1477 return new CFGAS_FileRead(pBaseStream, bReleaseStream); |
| 1474 } | 1478 } |
| 1475 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream) | 1479 CFGAS_FileRead::CFGAS_FileRead(IFX_Stream* pStream, FX_BOOL bReleaseStream) |
| 1476 : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { | 1480 : m_bReleaseStream(bReleaseStream), m_pStream(pStream), m_nCurPos(0) { |
| 1477 ASSERT(m_pStream); | 1481 ASSERT(m_pStream); |
| 1478 } | 1482 } |
| 1479 CFGAS_FileRead::~CFGAS_FileRead() { | 1483 CFGAS_FileRead::~CFGAS_FileRead() { |
| 1480 if (m_bReleaseStream) { | 1484 if (m_bReleaseStream) { |
| 1481 m_pStream->Release(); | 1485 m_pStream->Release(); |
| 1482 } | 1486 } |
| 1483 } | 1487 } |
| 1488 FX_BOOL CFGAS_FileRead::IsEOF() { |
| 1489 return m_nCurPos >= (FX_FILESIZE)m_pStream->GetLength(); |
| 1490 } |
| 1484 FX_FILESIZE CFGAS_FileRead::GetSize() { | 1491 FX_FILESIZE CFGAS_FileRead::GetSize() { |
| 1485 return (FX_FILESIZE)m_pStream->GetLength(); | 1492 return (FX_FILESIZE)m_pStream->GetLength(); |
| 1486 } | 1493 } |
| 1487 FX_BOOL CFGAS_FileRead::ReadBlock(void* buffer, | 1494 size_t CFGAS_FileRead::ReadBlock(void* buffer, |
| 1488 FX_FILESIZE offset, | 1495 FX_FILESIZE offset, |
| 1489 size_t size) { | 1496 size_t size) { |
| 1490 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); | 1497 m_pStream->Seek(FX_STREAMSEEK_Begin, (int32_t)offset); |
| 1491 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); | 1498 int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); |
| 1492 return iLen == (int32_t)size; | 1499 m_nCurPos = offset + iLen; |
| 1500 return iLen; |
| 1493 } | 1501 } |
| 1494 | 1502 |
| 1495 void CFGAS_FileRead::Release() { | 1503 void CFGAS_FileRead::Release() { |
| 1496 delete this; | 1504 delete this; |
| 1497 } | 1505 } |
| OLD | NEW |