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