OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <propvarutil.h> | 8 #include <propvarutil.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return file_count; | 120 return file_count; |
121 } | 121 } |
122 | 122 |
123 bool Delete(const FilePath& path, bool recursive) { | 123 bool Delete(const FilePath& path, bool recursive) { |
124 if (path.value().length() >= MAX_PATH) | 124 if (path.value().length() >= MAX_PATH) |
125 return false; | 125 return false; |
126 | 126 |
127 if (!recursive) { | 127 if (!recursive) { |
128 // If not recursing, then first check to see if |path| is a directory. | 128 // If not recursing, then first check to see if |path| is a directory. |
129 // If it is, then remove it with RemoveDirectory. | 129 // If it is, then remove it with RemoveDirectory. |
130 FileInfo file_info; | 130 base::PlatformFileInfo file_info; |
131 if (GetFileInfo(path, &file_info) && file_info.is_directory) | 131 if (GetFileInfo(path, &file_info) && file_info.is_directory) |
132 return RemoveDirectory(path.value().c_str()) != 0; | 132 return RemoveDirectory(path.value().c_str()) != 0; |
133 | 133 |
134 // Otherwise, it's a file, wildcard or non-existant. Try DeleteFile first | 134 // Otherwise, it's a file, wildcard or non-existant. Try DeleteFile first |
135 // because it should be faster. If DeleteFile fails, then we fall through | 135 // because it should be faster. If DeleteFile fails, then we fall through |
136 // to SHFileOperation, which will do the right thing. | 136 // to SHFileOperation, which will do the right thing. |
137 if (DeleteFile(path.value().c_str()) != 0) | 137 if (DeleteFile(path.value().c_str()) != 0) |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 log << "GetLastError() for DirectoryExists() is " | 668 log << "GetLastError() for DirectoryExists() is " |
669 << dir_exists_error << std::endl; | 669 << dir_exists_error << std::endl; |
670 return false; | 670 return false; |
671 } | 671 } |
672 } else { | 672 } else { |
673 log << "::CreateDirectory() succeeded." << std::endl; | 673 log << "::CreateDirectory() succeeded." << std::endl; |
674 return true; | 674 return true; |
675 } | 675 } |
676 } | 676 } |
677 | 677 |
678 bool GetFileInfo(const FilePath& file_path, FileInfo* results) { | 678 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { |
679 WIN32_FILE_ATTRIBUTE_DATA attr; | 679 WIN32_FILE_ATTRIBUTE_DATA attr; |
680 if (!GetFileAttributesEx(file_path.value().c_str(), | 680 if (!GetFileAttributesEx(file_path.value().c_str(), |
681 GetFileExInfoStandard, &attr)) { | 681 GetFileExInfoStandard, &attr)) { |
682 return false; | 682 return false; |
683 } | 683 } |
684 | 684 |
685 ULARGE_INTEGER size; | 685 ULARGE_INTEGER size; |
686 size.HighPart = attr.nFileSizeHigh; | 686 size.HighPart = attr.nFileSizeHigh; |
687 size.LowPart = attr.nFileSizeLow; | 687 size.LowPart = attr.nFileSizeLow; |
688 results->size = size.QuadPart; | 688 results->size = size.QuadPart; |
689 | 689 |
690 results->is_directory = | 690 results->is_directory = |
691 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; | 691 (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
692 results->last_modified = base::Time::FromFileTime(attr.ftLastWriteTime); | 692 results->last_modified = base::Time::FromFileTime(attr.ftLastWriteTime); |
| 693 results->last_accessed = base::Time::FromFileTime(attr.ftLastAccessTime); |
| 694 results->creation_time = base::Time::FromFileTime(attr.ftCreationTime); |
693 | 695 |
694 return true; | 696 return true; |
695 } | 697 } |
696 | 698 |
697 bool SetLastModifiedTime(const FilePath& file_path, base::Time last_modified) { | 699 bool SetLastModifiedTime(const FilePath& file_path, base::Time last_modified) { |
698 FILETIME timestamp(last_modified.ToFileTime()); | 700 FILETIME timestamp(last_modified.ToFileTime()); |
699 ScopedHandle file_handle( | 701 ScopedHandle file_handle( |
700 CreateFile(file_path.value().c_str(), FILE_WRITE_ATTRIBUTES, | 702 CreateFile(file_path.value().c_str(), FILE_WRITE_ATTRIBUTES, |
701 kFileShareAll, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); | 703 kFileShareAll, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); |
702 BOOL ret = SetFileTime(file_handle.Get(), NULL, ×tamp, ×tamp); | 704 BOOL ret = SetFileTime(file_handle.Get(), NULL, ×tamp, ×tamp); |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 uint8 unused = *(touch + offset); | 1094 uint8 unused = *(touch + offset); |
1093 offset += step_size; | 1095 offset += step_size; |
1094 } | 1096 } |
1095 FreeLibrary(dll_module); | 1097 FreeLibrary(dll_module); |
1096 } | 1098 } |
1097 | 1099 |
1098 return true; | 1100 return true; |
1099 } | 1101 } |
1100 | 1102 |
1101 } // namespace file_util | 1103 } // namespace file_util |
OLD | NEW |