| 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/include/fx_basic.h" | 7 #include "core/fxcrt/include/fx_basic.h" |
| 8 #include "core/fxcrt/include/fx_ext.h" | 8 #include "core/fxcrt/include/fx_ext.h" |
| 9 | 9 |
| 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 10 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 11 #include <dirent.h> | 11 #include <dirent.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #else | 13 #else |
| 14 #include <direct.h> | 14 #include <direct.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #include <algorithm> | 17 #include <algorithm> |
| 18 #include <cctype> | 18 #include <cctype> |
| 19 #include <memory> |
| 19 | 20 |
| 20 #ifdef PDF_ENABLE_XFA | 21 #ifdef PDF_ENABLE_XFA |
| 21 CFX_PrivateData::CFX_PrivateData() {} | 22 CFX_PrivateData::CFX_PrivateData() {} |
| 22 | 23 |
| 23 CFX_PrivateData::~CFX_PrivateData() { | 24 CFX_PrivateData::~CFX_PrivateData() { |
| 24 ClearAll(); | 25 ClearAll(); |
| 25 } | 26 } |
| 26 void FX_PRIVATEDATA::FreeData() { | 27 void FX_PRIVATEDATA::FreeData() { |
| 27 if (!m_pData) { | 28 if (!m_pData) { |
| 28 return; | 29 return; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 public: | 202 public: |
| 202 virtual ~CFindFileDataA() {} | 203 virtual ~CFindFileDataA() {} |
| 203 WIN32_FIND_DATAA m_FindData; | 204 WIN32_FIND_DATAA m_FindData; |
| 204 }; | 205 }; |
| 205 class CFindFileDataW : public CFindFileData { | 206 class CFindFileDataW : public CFindFileData { |
| 206 public: | 207 public: |
| 207 virtual ~CFindFileDataW() {} | 208 virtual ~CFindFileDataW() {} |
| 208 WIN32_FIND_DATAW m_FindData; | 209 WIN32_FIND_DATAW m_FindData; |
| 209 }; | 210 }; |
| 210 #endif | 211 #endif |
| 212 |
| 211 void* FX_OpenFolder(const FX_CHAR* path) { | 213 void* FX_OpenFolder(const FX_CHAR* path) { |
| 212 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 214 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 213 #ifndef _WIN32_WCE | 215 std::unique_ptr<CFindFileDataA> pData(new CFindFileDataA); |
| 214 CFindFileDataA* pData = new CFindFileDataA; | |
| 215 pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), | 216 pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), |
| 216 FindExInfoStandard, &pData->m_FindData, | 217 FindExInfoStandard, &pData->m_FindData, |
| 217 FindExSearchNameMatch, NULL, 0); | 218 FindExSearchNameMatch, nullptr, 0); |
| 218 #else | 219 if (pData->m_Handle == INVALID_HANDLE_VALUE) |
| 219 CFindFileDataW* pData = new CFindFileDataW; | 220 return nullptr; |
| 220 pData->m_Handle = FindFirstFileW(CFX_WideString::FromLocal(path) + L"/*.*", | 221 |
| 221 &pData->m_FindData); | |
| 222 #endif | |
| 223 if (pData->m_Handle == INVALID_HANDLE_VALUE) { | |
| 224 delete pData; | |
| 225 return NULL; | |
| 226 } | |
| 227 pData->m_bEnd = FALSE; | 222 pData->m_bEnd = FALSE; |
| 228 return pData; | 223 return pData.release(); |
| 229 #else | 224 #else |
| 230 DIR* dir = opendir(path); | 225 DIR* dir = opendir(path); |
| 231 return dir; | 226 return dir; |
| 232 #endif | 227 #endif |
| 233 } | 228 } |
| 229 |
| 234 void* FX_OpenFolder(const FX_WCHAR* path) { | 230 void* FX_OpenFolder(const FX_WCHAR* path) { |
| 235 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 231 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 236 CFindFileDataW* pData = new CFindFileDataW; | 232 std::unique_ptr<CFindFileDataW> pData(new CFindFileDataW); |
| 237 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), | 233 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), |
| 238 FindExInfoStandard, &pData->m_FindData, | 234 FindExInfoStandard, &pData->m_FindData, |
| 239 FindExSearchNameMatch, NULL, 0); | 235 FindExSearchNameMatch, nullptr, 0); |
| 240 if (pData->m_Handle == INVALID_HANDLE_VALUE) { | 236 if (pData->m_Handle == INVALID_HANDLE_VALUE) |
| 241 delete pData; | 237 return nullptr; |
| 242 return NULL; | 238 |
| 243 } | |
| 244 pData->m_bEnd = FALSE; | 239 pData->m_bEnd = FALSE; |
| 245 return pData; | 240 return pData.release(); |
| 246 #else | 241 #else |
| 247 DIR* dir = opendir(CFX_ByteString::FromUnicode(path).c_str()); | 242 DIR* dir = opendir(CFX_ByteString::FromUnicode(path).c_str()); |
| 248 return dir; | 243 return dir; |
| 249 #endif | 244 #endif |
| 250 } | 245 } |
| 251 FX_BOOL FX_GetNextFile(void* handle, | 246 FX_BOOL FX_GetNextFile(void* handle, |
| 252 CFX_ByteString& filename, | 247 CFX_ByteString& filename, |
| 253 FX_BOOL& bFolder) { | 248 FX_BOOL& bFolder) { |
| 254 if (!handle) { | 249 if (!handle) { |
| 255 return FALSE; | 250 return FALSE; |
| 256 } | 251 } |
| 257 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 252 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 258 #ifndef _WIN32_WCE | |
| 259 CFindFileDataA* pData = (CFindFileDataA*)handle; | 253 CFindFileDataA* pData = (CFindFileDataA*)handle; |
| 260 if (pData->m_bEnd) { | 254 if (pData->m_bEnd) |
| 261 return FALSE; | 255 return FALSE; |
| 262 } | 256 |
| 263 filename = pData->m_FindData.cFileName; | 257 filename = pData->m_FindData.cFileName; |
| 264 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 258 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
| 265 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) { | 259 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) |
| 266 pData->m_bEnd = TRUE; | 260 pData->m_bEnd = TRUE; |
| 267 } | |
| 268 return TRUE; | 261 return TRUE; |
| 269 #else | |
| 270 CFindFileDataW* pData = (CFindFileDataW*)handle; | |
| 271 if (pData->m_bEnd) { | |
| 272 return FALSE; | |
| 273 } | |
| 274 filename = CFX_ByteString::FromUnicode(pData->m_FindData.cFileName); | |
| 275 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | |
| 276 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { | |
| 277 pData->m_bEnd = TRUE; | |
| 278 } | |
| 279 return TRUE; | |
| 280 #endif | |
| 281 #elif defined(__native_client__) | 262 #elif defined(__native_client__) |
| 282 abort(); | 263 abort(); |
| 283 return FALSE; | 264 return FALSE; |
| 284 #else | 265 #else |
| 285 struct dirent* de = readdir((DIR*)handle); | 266 struct dirent* de = readdir((DIR*)handle); |
| 286 if (!de) { | 267 if (!de) { |
| 287 return FALSE; | 268 return FALSE; |
| 288 } | 269 } |
| 289 filename = de->d_name; | 270 filename = de->d_name; |
| 290 bFolder = de->d_type == DT_DIR; | 271 bFolder = de->d_type == DT_DIR; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 dstShift -= 8; | 371 dstShift -= 8; |
| 391 result |= *dataPtr++ << dstShift; | 372 result |= *dataPtr++ << dstShift; |
| 392 } | 373 } |
| 393 if (dstShift > 0) { | 374 if (dstShift > 0) { |
| 394 bitShift = 8 - dstShift; | 375 bitShift = 8 - dstShift; |
| 395 bitMask = (1 << dstShift) - 1; | 376 bitMask = (1 << dstShift) - 1; |
| 396 result |= *dataPtr++ >> bitShift & bitMask; | 377 result |= *dataPtr++ >> bitShift & bitMask; |
| 397 } | 378 } |
| 398 return result; | 379 return result; |
| 399 } | 380 } |
| OLD | NEW |