| 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 <utility> |
| 8 |
| 7 #include "core/fxcrt/extension.h" | 9 #include "core/fxcrt/extension.h" |
| 8 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
| 9 #include "core/fxcrt/include/fx_ext.h" | 11 #include "core/fxcrt/include/fx_ext.h" |
| 10 | 12 |
| 11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 13 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 12 #include <wincrypt.h> | 14 #include <wincrypt.h> |
| 13 #else | 15 #else |
| 14 #include <ctime> | 16 #include <ctime> |
| 15 #endif | 17 #endif |
| 16 | 18 |
| 17 CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA) | 19 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) |
| 18 : m_pFile(pFA), m_dwCount(1) {} | 20 : m_pFile(std::move(pFA)), m_dwCount(1) {} |
| 19 | 21 |
| 20 CFX_CRTFileStream::~CFX_CRTFileStream() { | 22 CFX_CRTFileStream::~CFX_CRTFileStream() {} |
| 21 if (m_pFile) { | |
| 22 m_pFile->Release(); | |
| 23 } | |
| 24 } | |
| 25 | 23 |
| 26 IFX_FileStream* CFX_CRTFileStream::Retain() { | 24 IFX_FileStream* CFX_CRTFileStream::Retain() { |
| 27 m_dwCount++; | 25 m_dwCount++; |
| 28 return this; | 26 return this; |
| 29 } | 27 } |
| 30 | 28 |
| 31 void CFX_CRTFileStream::Release() { | 29 void CFX_CRTFileStream::Release() { |
| 32 uint32_t nCount = --m_dwCount; | 30 uint32_t nCount = --m_dwCount; |
| 33 if (!nCount) { | 31 if (!nCount) { |
| 34 delete this; | 32 delete this; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 pFA = new CFX_CRTFileAccess; | 74 pFA = new CFX_CRTFileAccess; |
| 77 if (NULL == pFA) | 75 if (NULL == pFA) |
| 78 return NULL; | 76 return NULL; |
| 79 | 77 |
| 80 pFA->Init(wsPath); | 78 pFA->Init(wsPath); |
| 81 return pFA; | 79 return pFA; |
| 82 } | 80 } |
| 83 #endif // PDF_ENABLE_XFA | 81 #endif // PDF_ENABLE_XFA |
| 84 | 82 |
| 85 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { | 83 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { |
| 86 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); | 84 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); |
| 87 if (!pFA) { | 85 if (!pFA->Open(filename, dwModes)) |
| 88 return NULL; | 86 return nullptr; |
| 89 } | 87 return new CFX_CRTFileStream(std::move(pFA)); |
| 90 if (!pFA->Open(filename, dwModes)) { | |
| 91 pFA->Release(); | |
| 92 return NULL; | |
| 93 } | |
| 94 return new CFX_CRTFileStream(pFA); | |
| 95 } | 88 } |
| 89 |
| 96 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, | 90 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, |
| 97 uint32_t dwModes) { | 91 uint32_t dwModes) { |
| 98 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); | 92 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); |
| 99 if (!pFA) { | 93 if (!pFA->Open(filename, dwModes)) |
| 100 return NULL; | 94 return nullptr; |
| 101 } | 95 return new CFX_CRTFileStream(std::move(pFA)); |
| 102 if (!pFA->Open(filename, dwModes)) { | |
| 103 pFA->Release(); | |
| 104 return NULL; | |
| 105 } | |
| 106 return new CFX_CRTFileStream(pFA); | |
| 107 } | 96 } |
| 108 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename) { | 97 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename) { |
| 109 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); | 98 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); |
| 110 } | 99 } |
| 111 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename) { | 100 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename) { |
| 112 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); | 101 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); |
| 113 } | 102 } |
| 114 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, | 103 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, |
| 115 size_t dwSize, | 104 size_t dwSize, |
| 116 FX_BOOL bTakeOver) { | 105 FX_BOOL bTakeOver) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 b = ((const uint8_t*)pGUID)[i]; | 352 b = ((const uint8_t*)pGUID)[i]; |
| 364 *pBuf++ = gs_FX_pHexChars[b >> 4]; | 353 *pBuf++ = gs_FX_pHexChars[b >> 4]; |
| 365 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; | 354 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; |
| 366 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { | 355 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { |
| 367 *pBuf++ = L'-'; | 356 *pBuf++ = L'-'; |
| 368 } | 357 } |
| 369 } | 358 } |
| 370 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); | 359 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); |
| 371 } | 360 } |
| 372 #endif // PDF_ENABLE_XFA | 361 #endif // PDF_ENABLE_XFA |
| OLD | NEW |