| 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 "../../include/fxcrt/fx_ext.h" | 7 #include "../../include/fxcrt/fx_ext.h" |
| 8 #include "fxcrt_windows.h" | 8 #include "fxcrt_windows.h" |
| 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 9 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 10 FX_BOOL FX_File_Exist(FX_BSTR fileName) | 10 FX_BOOL FX_File_Exist(FX_BSTR fileName) |
| 11 { | 11 { |
| 12 FX_DWORD dwAttri = ::GetFileAttributesA(fileName.GetCStr()); | 12 FX_DWORD dwAttri = ::GetFileAttributesA(fileName.GetCStr()); |
| 13 if (dwAttri == -1) { | 13 if (dwAttri == -1) { |
| 14 return FALSE; | 14 return FALSE; |
| 15 } | 15 } |
| 16 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; | 16 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; |
| 17 } | 17 } |
| 18 FX_BOOL FX_File_Exist(FX_WSTR fileName) | 18 FX_BOOL FX_File_Exist(FX_WSTR fileName) |
| 19 { | 19 { |
| 20 FX_DWORD dwAttri = ::GetFileAttributesW((LPCWSTR)fileName.GetPtr()); | 20 FX_DWORD dwAttri = ::GetFileAttributesW((LPCWSTR)fileName.GetPtr()); |
| 21 if (dwAttri == -1) { | 21 if (dwAttri == -1) { |
| 22 return FALSE; | 22 return FALSE; |
| 23 } | 23 } |
| 24 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; | 24 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; |
| 25 } | 25 } |
| 26 IFXCRT_FileAccess* FXCRT_FileAccess_Create(IFX_Allocator* pAllocator) | 26 IFXCRT_FileAccess* FXCRT_FileAccess_Create() |
| 27 { | 27 { |
| 28 if (pAllocator) { | 28 return FX_NEW CFXCRT_FileAccess_Win64; |
| 29 return FX_NewAtAllocator(pAllocator) CFXCRT_FileAccess_Win64; | |
| 30 } else { | |
| 31 return FX_NEW CFXCRT_FileAccess_Win64; | |
| 32 } | |
| 33 } | 29 } |
| 34 void FXCRT_Windows_GetFileMode(FX_DWORD dwMode, FX_DWORD &dwAccess, FX_DWORD &dw
Share, FX_DWORD &dwCreation) | 30 void FXCRT_Windows_GetFileMode(FX_DWORD dwMode, FX_DWORD &dwAccess, FX_DWORD &dw
Share, FX_DWORD &dwCreation) |
| 35 { | 31 { |
| 36 dwAccess = GENERIC_READ; | 32 dwAccess = GENERIC_READ; |
| 37 dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE; | 33 dwShare = FILE_SHARE_READ | FILE_SHARE_WRITE; |
| 38 if (!(dwMode & FX_FILEMODE_ReadOnly)) { | 34 if (!(dwMode & FX_FILEMODE_ReadOnly)) { |
| 39 dwAccess |= GENERIC_WRITE; | 35 dwAccess |= GENERIC_WRITE; |
| 40 dwCreation = (dwMode & FX_FILEMODE_Truncate) ? CREATE_ALWAYS : OPEN_ALWA
YS; | 36 dwCreation = (dwMode & FX_FILEMODE_Truncate) ? CREATE_ALWAYS : OPEN_ALWA
YS; |
| 41 } else { | 37 } else { |
| 42 dwCreation = OPEN_EXISTING; | 38 dwCreation = OPEN_EXISTING; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 return m_hFile != NULL; | 81 return m_hFile != NULL; |
| 86 } | 82 } |
| 87 void CFXCRT_FileAccess_Win64::Close() | 83 void CFXCRT_FileAccess_Win64::Close() |
| 88 { | 84 { |
| 89 if (!m_hFile) { | 85 if (!m_hFile) { |
| 90 return; | 86 return; |
| 91 } | 87 } |
| 92 ::CloseHandle(m_hFile); | 88 ::CloseHandle(m_hFile); |
| 93 m_hFile = NULL; | 89 m_hFile = NULL; |
| 94 } | 90 } |
| 95 void CFXCRT_FileAccess_Win64::Release(IFX_Allocator* pAllocator) | 91 void CFXCRT_FileAccess_Win64::Release() |
| 96 { | 92 { |
| 97 if (pAllocator) { | 93 delete this; |
| 98 FX_DeleteAtAllocator(this, pAllocator, CFXCRT_FileAccess_Win64); | |
| 99 } else { | |
| 100 delete this; | |
| 101 } | |
| 102 } | 94 } |
| 103 FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const | 95 FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const |
| 104 { | 96 { |
| 105 if (!m_hFile) { | 97 if (!m_hFile) { |
| 106 return 0; | 98 return 0; |
| 107 } | 99 } |
| 108 LARGE_INTEGER size = {0, 0}; | 100 LARGE_INTEGER size = {0, 0}; |
| 109 if (!::GetFileSizeEx(m_hFile, &size)) { | 101 if (!::GetFileSizeEx(m_hFile, &size)) { |
| 110 return 0; | 102 return 0; |
| 111 } | 103 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 205 } |
| 214 FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) | 206 FX_BOOL FX_File_Move(FX_BSTR fileNameSrc, FX_BSTR fileNameDst) |
| 215 { | 207 { |
| 216 return ::MoveFileA(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); | 208 return ::MoveFileA(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); |
| 217 } | 209 } |
| 218 FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) | 210 FX_BOOL FX_File_Move(FX_WSTR fileNameSrc, FX_WSTR fileNameDst) |
| 219 { | 211 { |
| 220 return ::MoveFileW((LPCWSTR)fileNameSrc.GetPtr(), (LPCWSTR)fileNameDst.GetPt
r()); | 212 return ::MoveFileW((LPCWSTR)fileNameSrc.GetPtr(), (LPCWSTR)fileNameDst.GetPt
r()); |
| 221 } | 213 } |
| 222 #endif | 214 #endif |
| OLD | NEW |