Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: base/file_util_win.cc

Issue 73084: Reverting 13748. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/test/automated_ui_tests/automated_ui_tests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/scoped_handle.h" 15 #include "base/scoped_handle.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/time.h"
18 #include "base/win_util.h" 17 #include "base/win_util.h"
19 18
20 namespace file_util { 19 namespace file_util {
21 20
22 std::wstring GetDirectoryFromPath(const std::wstring& path) { 21 std::wstring GetDirectoryFromPath(const std::wstring& path) {
23 wchar_t path_buffer[MAX_PATH]; 22 wchar_t path_buffer[MAX_PATH];
24 wchar_t* file_ptr = NULL; 23 wchar_t* file_ptr = NULL;
25 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0) 24 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0)
26 return L""; 25 return L"";
27 26
28 std::wstring::size_type length = 27 std::wstring::size_type length =
29 file_ptr ? file_ptr - path_buffer : path.length(); 28 file_ptr ? file_ptr - path_buffer : path.length();
30 std::wstring directory(path, 0, length); 29 std::wstring directory(path, 0, length);
31 TrimTrailingSeparator(&directory); 30 TrimTrailingSeparator(&directory);
32 return directory; 31 return directory;
33 } 32 }
34 33
35 bool AbsolutePath(FilePath* path) { 34 bool AbsolutePath(FilePath* path) {
36 wchar_t file_path_buf[MAX_PATH]; 35 wchar_t file_path_buf[MAX_PATH];
37 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH)) 36 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH))
38 return false; 37 return false;
39 *path = FilePath(file_path_buf); 38 *path = FilePath(file_path_buf);
40 return true; 39 return true;
41 } 40 }
42 41
43 int CountFilesCreatedAfter(const FilePath& path, 42 int CountFilesCreatedAfter(const std::wstring& path,
44 const base::Time& comparison_time) { 43 const FILETIME& comparison_time) {
45 int file_count = 0; 44 int file_count = 0;
46 FILETIME comparison_filetime(comparison_time.ToFileTime());
47 45
48 WIN32_FIND_DATA find_file_data; 46 WIN32_FIND_DATA find_file_data;
49 // All files in given dir 47 std::wstring filename_spec = path + L"\\*"; // All files in given dir
50 std::wstring filename_spec = path.Append(L"*").value();
51 HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data); 48 HANDLE find_handle = FindFirstFile(filename_spec.c_str(), &find_file_data);
52 if (find_handle != INVALID_HANDLE_VALUE) { 49 if (find_handle != INVALID_HANDLE_VALUE) {
53 do { 50 do {
54 // Don't count current or parent directories. 51 // Don't count current or parent directories.
55 if ((wcscmp(find_file_data.cFileName, L"..") == 0) || 52 if ((wcscmp(find_file_data.cFileName, L"..") == 0) ||
56 (wcscmp(find_file_data.cFileName, L".") == 0)) 53 (wcscmp(find_file_data.cFileName, L".") == 0))
57 continue; 54 continue;
58 55
59 long result = CompareFileTime(&find_file_data.ftCreationTime, 56 long result = CompareFileTime(&find_file_data.ftCreationTime,
60 &comparison_filetime); 57 &comparison_time);
61 // File was created after or on comparison time 58 // File was created after or on comparison time
62 if ((result == 1) || (result == 0)) 59 if ((result == 1) || (result == 0))
63 ++file_count; 60 ++file_count;
64 } while (FindNextFile(find_handle, &find_file_data)); 61 } while (FindNextFile(find_handle, &find_file_data));
65 FindClose(find_handle); 62 FindClose(find_handle);
66 } 63 }
67 64
68 return file_count; 65 return file_count;
69 } 66 }
70 67
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 void PathComponents(const std::wstring& path, 801 void PathComponents(const std::wstring& path,
805 std::vector<std::wstring>* components) { 802 std::vector<std::wstring>* components) {
806 PathComponents(FilePath(path), components); 803 PathComponents(FilePath(path), components);
807 } 804 }
808 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) { 805 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
809 FilePath path(*file_name); 806 FilePath path(*file_name);
810 ReplaceExtension(&path, extension); 807 ReplaceExtension(&path, extension);
811 file_name->assign(path.value()); 808 file_name->assign(path.value());
812 } 809 }
813 } // namespace file_util 810 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/test/automated_ui_tests/automated_ui_tests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698