| 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 #ifndef CORE_SRC_FXCRT_EXTENSION_H_ | 7 #ifndef CORE_SRC_FXCRT_EXTENSION_H_ |
| 8 #define CORE_SRC_FXCRT_EXTENSION_H_ | 8 #define CORE_SRC_FXCRT_EXTENSION_H_ |
| 9 | 9 |
| 10 #include "../../include/fxcrt/fx_basic.h" | 10 #include "../../include/fxcrt/fx_basic.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) { | 55 virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) { |
| 56 return FX_CreateFileStream(m_path, dwModes); | 56 return FX_CreateFileStream(m_path, dwModes); |
| 57 } | 57 } |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 CFX_WideString m_path; | 60 CFX_WideString m_path; |
| 61 FX_DWORD m_RefCount; | 61 FX_DWORD m_RefCount; |
| 62 }; | 62 }; |
| 63 class CFX_CRTFileStream final : public IFX_FileStream { | 63 class CFX_CRTFileStream final : public IFX_FileStream { |
| 64 public: | 64 public: |
| 65 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) | 65 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {} |
| 66 : m_pFile(pFA), | |
| 67 m_dwCount(1) { | |
| 68 } | |
| 69 ~CFX_CRTFileStream() { | 66 ~CFX_CRTFileStream() { |
| 70 if (m_pFile) { | 67 if (m_pFile) { |
| 71 m_pFile->Release(); | 68 m_pFile->Release(); |
| 72 } | 69 } |
| 73 } | 70 } |
| 74 virtual IFX_FileStream* Retain() override { | 71 virtual IFX_FileStream* Retain() override { |
| 75 m_dwCount++; | 72 m_dwCount++; |
| 76 return this; | 73 return this; |
| 77 } | 74 } |
| 78 virtual void Release() override { | 75 virtual void Release() override { |
| 79 FX_DWORD nCount = --m_dwCount; | 76 FX_DWORD nCount = --m_dwCount; |
| 80 if (!nCount) { | 77 if (!nCount) { |
| 81 delete this; | 78 delete this; |
| 82 } | 79 } |
| 83 } | 80 } |
| 84 virtual FX_FILESIZE GetSize() override { | 81 virtual FX_FILESIZE GetSize() override { return m_pFile->GetSize(); } |
| 85 return m_pFile->GetSize(); | |
| 86 } | |
| 87 virtual FX_BOOL IsEOF() override { return GetPosition() >= GetSize(); } | 82 virtual FX_BOOL IsEOF() override { return GetPosition() >= GetSize(); } |
| 88 virtual FX_FILESIZE GetPosition() override { | 83 virtual FX_FILESIZE GetPosition() override { return m_pFile->GetPosition(); } |
| 89 return m_pFile->GetPosition(); | |
| 90 } | |
| 91 virtual FX_BOOL ReadBlock(void* buffer, | 84 virtual FX_BOOL ReadBlock(void* buffer, |
| 92 FX_FILESIZE offset, | 85 FX_FILESIZE offset, |
| 93 size_t size) override { | 86 size_t size) override { |
| 94 return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset); | 87 return (FX_BOOL)m_pFile->ReadPos(buffer, size, offset); |
| 95 } | 88 } |
| 96 virtual size_t ReadBlock(void* buffer, size_t size) override { | 89 virtual size_t ReadBlock(void* buffer, size_t size) override { |
| 97 return m_pFile->Read(buffer, size); | 90 return m_pFile->Read(buffer, size); |
| 98 } | 91 } |
| 99 virtual FX_BOOL WriteBlock(const void* buffer, | 92 virtual FX_BOOL WriteBlock(const void* buffer, |
| 100 FX_FILESIZE offset, | 93 FX_FILESIZE offset, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 m_dwCount++; | 136 m_dwCount++; |
| 144 return this; | 137 return this; |
| 145 } | 138 } |
| 146 virtual void Release() override { | 139 virtual void Release() override { |
| 147 FX_DWORD nCount = --m_dwCount; | 140 FX_DWORD nCount = --m_dwCount; |
| 148 if (nCount) { | 141 if (nCount) { |
| 149 return; | 142 return; |
| 150 } | 143 } |
| 151 delete this; | 144 delete this; |
| 152 } | 145 } |
| 153 virtual FX_FILESIZE GetSize() override { | 146 virtual FX_FILESIZE GetSize() override { return (FX_FILESIZE)m_nCurSize; } |
| 154 return (FX_FILESIZE)m_nCurSize; | |
| 155 } | |
| 156 virtual FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } | 147 virtual FX_BOOL IsEOF() override { return m_nCurPos >= (size_t)GetSize(); } |
| 157 virtual FX_FILESIZE GetPosition() override { | 148 virtual FX_FILESIZE GetPosition() override { return (FX_FILESIZE)m_nCurPos; } |
| 158 return (FX_FILESIZE)m_nCurPos; | |
| 159 } | |
| 160 virtual FX_BOOL ReadBlock(void* buffer, | 149 virtual FX_BOOL ReadBlock(void* buffer, |
| 161 FX_FILESIZE offset, | 150 FX_FILESIZE offset, |
| 162 size_t size) override { | 151 size_t size) override { |
| 163 if (!buffer || !size) { | 152 if (!buffer || !size) { |
| 164 return FALSE; | 153 return FALSE; |
| 165 } | 154 } |
| 166 | 155 |
| 167 FX_SAFE_SIZE_T newPos = size; | 156 FX_SAFE_SIZE_T newPos = size; |
| 168 newPos += offset; | 157 newPos += offset; |
| 169 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || | 158 if (!newPos.IsValid() || newPos.ValueOrDefault(0) == 0 || |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; | 336 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; |
| 348 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; | 337 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; |
| 349 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 338 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 350 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); | 339 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); |
| 351 #endif | 340 #endif |
| 352 #ifdef __cplusplus | 341 #ifdef __cplusplus |
| 353 } | 342 } |
| 354 #endif | 343 #endif |
| 355 | 344 |
| 356 #endif // CORE_SRC_FXCRT_EXTENSION_H_ | 345 #endif // CORE_SRC_FXCRT_EXTENSION_H_ |
| OLD | NEW |