| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium 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 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #include <time.h> | 10 #include <time.h> |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 169 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 170 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 170 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
| 171 | 171 |
| 172 if (dir == INVALID_HANDLE_VALUE) | 172 if (dir == INVALID_HANDLE_VALUE) |
| 173 return false; | 173 return false; |
| 174 | 174 |
| 175 CloseHandle(dir); | 175 CloseHandle(dir); |
| 176 return true; | 176 return true; |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool DirectoryExists(const std::wstring& path) { |
| 180 DWORD fileattr = GetFileAttributes(path.c_str()); |
| 181 if (fileattr != INVALID_FILE_ATTRIBUTES) |
| 182 return (fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 183 return false; |
| 184 } |
| 185 |
| 179 bool GetFileCreationLocalTimeFromHandle(HANDLE file_handle, | 186 bool GetFileCreationLocalTimeFromHandle(HANDLE file_handle, |
| 180 LPSYSTEMTIME creation_time) { | 187 LPSYSTEMTIME creation_time) { |
| 181 if (!file_handle) | 188 if (!file_handle) |
| 182 return false; | 189 return false; |
| 183 | 190 |
| 184 FILETIME utc_filetime; | 191 FILETIME utc_filetime; |
| 185 if (!GetFileTime(file_handle, &utc_filetime, NULL, NULL)) | 192 if (!GetFileTime(file_handle, &utc_filetime, NULL, NULL)) |
| 186 return false; | 193 return false; |
| 187 | 194 |
| 188 FILETIME local_filetime; | 195 FILETIME local_filetime; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 419 |
| 413 if (count == 50) { | 420 if (count == 50) { |
| 414 return false; | 421 return false; |
| 415 } | 422 } |
| 416 | 423 |
| 417 new_temp_path->assign(path_to_create); | 424 new_temp_path->assign(path_to_create); |
| 418 return true; | 425 return true; |
| 419 } | 426 } |
| 420 | 427 |
| 421 bool CreateDirectory(const std::wstring& full_path) { | 428 bool CreateDirectory(const std::wstring& full_path) { |
| 422 if (PathExists(full_path)) | 429 if (DirectoryExists(full_path)) |
| 423 return true; | 430 return true; |
| 424 int err = SHCreateDirectoryEx(NULL, full_path.c_str(), NULL); | 431 int err = SHCreateDirectoryEx(NULL, full_path.c_str(), NULL); |
| 425 return err == ERROR_SUCCESS; | 432 return err == ERROR_SUCCESS; |
| 426 } | 433 } |
| 427 | 434 |
| 428 bool GetFileSize(const std::wstring& file_path, int64* file_size) { | 435 bool GetFileSize(const std::wstring& file_path, int64* file_size) { |
| 429 ScopedHandle file_handle( | 436 ScopedHandle file_handle( |
| 430 CreateFile(file_path.c_str(), GENERIC_READ, | 437 CreateFile(file_path.c_str(), GENERIC_READ, |
| 431 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 438 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
| 432 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); | 439 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); | 645 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); |
| 639 } | 646 } |
| 640 | 647 |
| 641 if ((file_type_ & FileEnumerator::DIRECTORIES) == 0) | 648 if ((file_type_ & FileEnumerator::DIRECTORIES) == 0) |
| 642 return Next(); | 649 return Next(); |
| 643 } | 650 } |
| 644 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); | 651 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); |
| 645 } | 652 } |
| 646 | 653 |
| 647 } // namespace file_util | 654 } // namespace file_util |
| OLD | NEW |