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 10 matching lines...) Expand all Loading... |
21 | 21 |
22 std::wstring GetDirectoryFromPath(const std::wstring& path) { | 22 std::wstring GetDirectoryFromPath(const std::wstring& path) { |
23 wchar_t path_buffer[MAX_PATH]; | 23 wchar_t path_buffer[MAX_PATH]; |
24 wchar_t* file_ptr = NULL; | 24 wchar_t* file_ptr = NULL; |
25 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0) | 25 if (GetFullPathName(path.c_str(), MAX_PATH, path_buffer, &file_ptr) == 0) |
26 return L""; | 26 return L""; |
27 | 27 |
28 std::wstring::size_type length = | 28 std::wstring::size_type length = |
29 file_ptr ? file_ptr - path_buffer : path.length(); | 29 file_ptr ? file_ptr - path_buffer : path.length(); |
30 std::wstring directory(path, 0, length); | 30 std::wstring directory(path, 0, length); |
31 TrimTrailingSeparator(&directory); | 31 return FilePath(directory).StripTrailingSeparators().value(); |
32 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 |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 bool GetCurrentDirectory(FilePath* dir) { | 640 bool GetCurrentDirectory(FilePath* dir) { |
642 wchar_t system_buffer[MAX_PATH]; | 641 wchar_t system_buffer[MAX_PATH]; |
643 system_buffer[0] = 0; | 642 system_buffer[0] = 0; |
644 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); | 643 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); |
645 if (len == 0 || len > MAX_PATH) | 644 if (len == 0 || len > MAX_PATH) |
646 return false; | 645 return false; |
647 // TODO(evanm): the old behavior of this function was to always strip the | 646 // TODO(evanm): the old behavior of this function was to always strip the |
648 // trailing slash. We duplicate this here, but it shouldn't be necessary | 647 // trailing slash. We duplicate this here, but it shouldn't be necessary |
649 // when everyone is using the appropriate FilePath APIs. | 648 // when everyone is using the appropriate FilePath APIs. |
650 std::wstring dir_str(system_buffer); | 649 std::wstring dir_str(system_buffer); |
651 file_util::TrimTrailingSeparator(&dir_str); | 650 *dir = FilePath(dir_str).StripTrailingSeparators(); |
652 *dir = FilePath(dir_str); | |
653 return true; | 651 return true; |
654 } | 652 } |
655 | 653 |
656 // Sets the current working directory for the process. | 654 // Sets the current working directory for the process. |
657 bool SetCurrentDirectory(const FilePath& directory) { | 655 bool SetCurrentDirectory(const FilePath& directory) { |
658 BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); | 656 BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); |
659 return ret != 0; | 657 return ret != 0; |
660 } | 658 } |
661 | 659 |
662 /////////////////////////////////////////////// | 660 /////////////////////////////////////////////// |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 ::CloseHandle(file_mapping_); | 798 ::CloseHandle(file_mapping_); |
801 if (file_ != INVALID_HANDLE_VALUE) | 799 if (file_ != INVALID_HANDLE_VALUE) |
802 ::CloseHandle(file_); | 800 ::CloseHandle(file_); |
803 | 801 |
804 data_ = NULL; | 802 data_ = NULL; |
805 file_mapping_ = file_ = INVALID_HANDLE_VALUE; | 803 file_mapping_ = file_ = INVALID_HANDLE_VALUE; |
806 length_ = INVALID_FILE_SIZE; | 804 length_ = INVALID_FILE_SIZE; |
807 } | 805 } |
808 | 806 |
809 } // namespace file_util | 807 } // namespace file_util |
OLD | NEW |