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_string.h" | 7 #include "../../include/fxcrt/fx_string.h" |
8 #include "fxcrt_windows.h" | 8 #include "fxcrt_windows.h" |
9 | 9 |
10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
11 FX_BOOL FX_File_Exist(const CFX_ByteStringC& fileName) | 11 bool FX_File_Exist(const CFX_ByteStringC& fileName) |
12 { | 12 { |
13 FX_DWORD dwAttri = ::GetFileAttributesA(fileName.GetCStr()); | 13 FX_DWORD dwAttri = ::GetFileAttributesA(fileName.GetCStr()); |
14 if (dwAttri == -1) { | 14 if (dwAttri == -1) { |
15 return FALSE; | 15 return false; |
16 } | 16 } |
17 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; | 17 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; |
18 } | 18 } |
19 FX_BOOL FX_File_Exist(const CFX_WideStringC& fileName) | 19 bool FX_File_Exist(const CFX_WideStringC& fileName) |
20 { | 20 { |
21 FX_DWORD dwAttri = ::GetFileAttributesW((LPCWSTR)fileName.GetPtr()); | 21 FX_DWORD dwAttri = ::GetFileAttributesW((LPCWSTR)fileName.GetPtr()); |
22 if (dwAttri == -1) { | 22 if (dwAttri == -1) { |
23 return FALSE; | 23 return false; |
24 } | 24 } |
25 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; | 25 return (dwAttri & FILE_ATTRIBUTE_DIRECTORY) == 0; |
26 } | 26 } |
27 IFXCRT_FileAccess* FXCRT_FileAccess_Create() | 27 IFXCRT_FileAccess* FXCRT_FileAccess_Create() |
28 { | 28 { |
29 return new CFXCRT_FileAccess_Win64; | 29 return new CFXCRT_FileAccess_Win64; |
30 } | 30 } |
31 void FXCRT_Windows_GetFileMode(FX_DWORD dwMode, FX_DWORD &dwAccess, FX_DWORD &dw
Share, FX_DWORD &dwCreation) | 31 void FXCRT_Windows_GetFileMode(FX_DWORD dwMode, FX_DWORD &dwAccess, FX_DWORD &dw
Share, FX_DWORD &dwCreation) |
32 { | 32 { |
33 dwAccess = GENERIC_READ; | 33 dwAccess = GENERIC_READ; |
(...skipping 14 matching lines...) Expand all Loading... |
48 } | 48 } |
49 #endif | 49 #endif |
50 CFXCRT_FileAccess_Win64::CFXCRT_FileAccess_Win64() | 50 CFXCRT_FileAccess_Win64::CFXCRT_FileAccess_Win64() |
51 : m_hFile(NULL) | 51 : m_hFile(NULL) |
52 { | 52 { |
53 } | 53 } |
54 CFXCRT_FileAccess_Win64::~CFXCRT_FileAccess_Win64() | 54 CFXCRT_FileAccess_Win64::~CFXCRT_FileAccess_Win64() |
55 { | 55 { |
56 Close(); | 56 Close(); |
57 } | 57 } |
58 FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName, FX_DWORD
dwMode) | 58 bool CFXCRT_FileAccess_Win64::Open(const CFX_ByteStringC& fileName, FX_DWORD dwM
ode) |
59 { | 59 { |
60 if (m_hFile) { | 60 if (m_hFile) { |
61 return FALSE; | 61 return false; |
62 } | 62 } |
63 FX_DWORD dwAccess, dwShare, dwCreation; | 63 FX_DWORD dwAccess, dwShare, dwCreation; |
64 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); | 64 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); |
65 m_hFile = ::CreateFileA(fileName.GetCStr(), dwAccess, dwShare, NULL, dwCreat
ion, FILE_ATTRIBUTE_NORMAL, NULL); | 65 m_hFile = ::CreateFileA(fileName.GetCStr(), dwAccess, dwShare, NULL, dwCreat
ion, FILE_ATTRIBUTE_NORMAL, NULL); |
66 if (m_hFile == INVALID_HANDLE_VALUE) { | 66 if (m_hFile == INVALID_HANDLE_VALUE) { |
67 m_hFile = NULL; | 67 m_hFile = NULL; |
68 } | 68 } |
69 return m_hFile != NULL; | 69 return m_hFile != NULL; |
70 } | 70 } |
71 FX_BOOL CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName, FX_DWORD
dwMode) | 71 bool CFXCRT_FileAccess_Win64::Open(const CFX_WideStringC& fileName, FX_DWORD dwM
ode) |
72 { | 72 { |
73 if (m_hFile) { | 73 if (m_hFile) { |
74 return FALSE; | 74 return false; |
75 } | 75 } |
76 FX_DWORD dwAccess, dwShare, dwCreation; | 76 FX_DWORD dwAccess, dwShare, dwCreation; |
77 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); | 77 FXCRT_Windows_GetFileMode(dwMode, dwAccess, dwShare, dwCreation); |
78 m_hFile = ::CreateFileW((LPCWSTR)fileName.GetPtr(), dwAccess, dwShare, NULL,
dwCreation, FILE_ATTRIBUTE_NORMAL, NULL); | 78 m_hFile = ::CreateFileW((LPCWSTR)fileName.GetPtr(), dwAccess, dwShare, NULL,
dwCreation, FILE_ATTRIBUTE_NORMAL, NULL); |
79 if (m_hFile == INVALID_HANDLE_VALUE) { | 79 if (m_hFile == INVALID_HANDLE_VALUE) { |
80 m_hFile = NULL; | 80 m_hFile = NULL; |
81 } | 81 } |
82 return m_hFile != NULL; | 82 return m_hFile != NULL; |
83 } | 83 } |
84 void CFXCRT_FileAccess_Win64::Close() | 84 void CFXCRT_FileAccess_Win64::Close() |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 size_t CFXCRT_FileAccess_Win64::WritePos(const void* pBuffer, size_t szBuffer, F
X_FILESIZE pos) | 167 size_t CFXCRT_FileAccess_Win64::WritePos(const void* pBuffer, size_t szBuffer, F
X_FILESIZE pos) |
168 { | 168 { |
169 if (!m_hFile) { | 169 if (!m_hFile) { |
170 return 0; | 170 return 0; |
171 } | 171 } |
172 if (SetPosition(pos) == (FX_FILESIZE) - 1) { | 172 if (SetPosition(pos) == (FX_FILESIZE) - 1) { |
173 return 0; | 173 return 0; |
174 } | 174 } |
175 return Write(pBuffer, szBuffer); | 175 return Write(pBuffer, szBuffer); |
176 } | 176 } |
177 FX_BOOL CFXCRT_FileAccess_Win64::Flush() | 177 bool CFXCRT_FileAccess_Win64::Flush() |
178 { | 178 { |
179 if (!m_hFile) { | 179 if (!m_hFile) { |
180 return FALSE; | 180 return false; |
181 } | 181 } |
182 return ::FlushFileBuffers(m_hFile); | 182 return ::FlushFileBuffers(m_hFile); |
183 } | 183 } |
184 FX_BOOL CFXCRT_FileAccess_Win64::Truncate(FX_FILESIZE szFile) | 184 bool CFXCRT_FileAccess_Win64::Truncate(FX_FILESIZE szFile) |
185 { | 185 { |
186 if (SetPosition(szFile) == (FX_FILESIZE) - 1) { | 186 if (SetPosition(szFile) == (FX_FILESIZE) - 1) { |
187 return FALSE; | 187 return false; |
188 } | 188 } |
189 return ::SetEndOfFile(m_hFile); | 189 return ::SetEndOfFile(m_hFile); |
190 } | 190 } |
191 FX_BOOL FX_File_Delete(const CFX_ByteStringC& fileName) | 191 bool FX_File_Delete(const CFX_ByteStringC& fileName) |
192 { | 192 { |
193 return ::DeleteFileA(fileName.GetCStr()); | 193 return ::DeleteFileA(fileName.GetCStr()); |
194 } | 194 } |
195 FX_BOOL FX_File_Delete(const CFX_WideStringC& fileName) | 195 bool FX_File_Delete(const CFX_WideStringC& fileName) |
196 { | 196 { |
197 return ::DeleteFileW((LPCWSTR)fileName.GetPtr()); | 197 return ::DeleteFileW((LPCWSTR)fileName.GetPtr()); |
198 } | 198 } |
199 FX_BOOL FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC&
fileNameDst) | 199 bool FX_File_Copy(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fil
eNameDst) |
200 { | 200 { |
201 return ::CopyFileA(fileNameSrc.GetCStr(), fileNameDst.GetCStr(), FALSE); | 201 return ::CopyFileA(fileNameSrc.GetCStr(), fileNameDst.GetCStr(), false); |
202 } | 202 } |
203 FX_BOOL FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC&
fileNameDst) | 203 bool FX_File_Copy(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fil
eNameDst) |
204 { | 204 { |
205 return ::CopyFileW((LPCWSTR)fileNameSrc.GetPtr(), (LPCWSTR)fileNameDst.GetPt
r(), FALSE); | 205 return ::CopyFileW((LPCWSTR)fileNameSrc.GetPtr(), (LPCWSTR)fileNameDst.GetPt
r(), false); |
206 } | 206 } |
207 FX_BOOL FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC&
fileNameDst) | 207 bool FX_File_Move(const CFX_ByteStringC& fileNameSrc, const CFX_ByteStringC& fil
eNameDst) |
208 { | 208 { |
209 return ::MoveFileA(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); | 209 return ::MoveFileA(fileNameSrc.GetCStr(), fileNameDst.GetCStr()); |
210 } | 210 } |
211 FX_BOOL FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC&
fileNameDst) | 211 bool FX_File_Move(const CFX_WideStringC& fileNameSrc, const CFX_WideStringC& fil
eNameDst) |
212 { | 212 { |
213 return ::MoveFileW((LPCWSTR)fileNameSrc.GetPtr(), (LPCWSTR)fileNameDst.GetPt
r()); | 213 return ::MoveFileW((LPCWSTR)fileNameSrc.GetPtr(), (LPCWSTR)fileNameDst.GetPt
r()); |
214 } | 214 } |
215 #endif | 215 #endif |
OLD | NEW |