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/base_paths_win.h" | 5 #include "base/base_paths_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <shlobj.h> | 8 #include <shlobj.h> |
9 | 9 |
| 10 #include "base/file_path.h" |
10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
12 #include "base/win_util.h" | 13 #include "base/win_util.h" |
13 | 14 |
14 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 15 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
15 extern "C" IMAGE_DOS_HEADER __ImageBase; | 16 extern "C" IMAGE_DOS_HEADER __ImageBase; |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 | 19 |
19 bool PathProviderWin(int key, std::wstring* result) { | 20 bool PathProviderWin(int key, FilePath* result) { |
20 | 21 |
21 // We need to go compute the value. It would be nice to support paths with | 22 // We need to go compute the value. It would be nice to support paths with |
22 // names longer than MAX_PATH, but the system functions don't seem to be | 23 // names longer than MAX_PATH, but the system functions don't seem to be |
23 // designed for it either, with the exception of GetTempPath (but other | 24 // designed for it either, with the exception of GetTempPath (but other |
24 // things will surely break if the temp path is too long, so we don't bother | 25 // things will surely break if the temp path is too long, so we don't bother |
25 // handling it. | 26 // handling it. |
26 wchar_t system_buffer[MAX_PATH]; | 27 wchar_t system_buffer[MAX_PATH]; |
27 system_buffer[0] = 0; | 28 system_buffer[0] = 0; |
28 | 29 |
29 std::wstring cur; | 30 FilePath cur; |
| 31 std::wstring wstring_path; |
30 switch (key) { | 32 switch (key) { |
31 case base::FILE_EXE: | 33 case base::FILE_EXE: |
32 GetModuleFileName(NULL, system_buffer, MAX_PATH); | 34 GetModuleFileName(NULL, system_buffer, MAX_PATH); |
33 cur = system_buffer; | 35 cur = FilePath(system_buffer); |
34 break; | 36 break; |
35 case base::FILE_MODULE: { | 37 case base::FILE_MODULE: { |
36 // the resource containing module is assumed to be the one that | 38 // the resource containing module is assumed to be the one that |
37 // this code lives in, whether that's a dll or exe | 39 // this code lives in, whether that's a dll or exe |
38 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); | 40 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); |
39 GetModuleFileName(this_module, system_buffer, MAX_PATH); | 41 GetModuleFileName(this_module, system_buffer, MAX_PATH); |
40 cur = system_buffer; | 42 cur = FilePath(system_buffer); |
41 break; | 43 break; |
42 } | 44 } |
43 case base::DIR_WINDOWS: | 45 case base::DIR_WINDOWS: |
44 GetWindowsDirectory(system_buffer, MAX_PATH); | 46 GetWindowsDirectory(system_buffer, MAX_PATH); |
45 cur = system_buffer; | 47 cur = FilePath(system_buffer); |
46 break; | 48 break; |
47 case base::DIR_SYSTEM: | 49 case base::DIR_SYSTEM: |
48 GetSystemDirectory(system_buffer, MAX_PATH); | 50 GetSystemDirectory(system_buffer, MAX_PATH); |
49 cur = system_buffer; | 51 cur = FilePath(system_buffer); |
50 break; | 52 break; |
51 case base::DIR_PROGRAM_FILES: | 53 case base::DIR_PROGRAM_FILES: |
52 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, | 54 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
53 SHGFP_TYPE_CURRENT, system_buffer))) | 55 SHGFP_TYPE_CURRENT, system_buffer))) |
54 return false; | 56 return false; |
55 cur = system_buffer; | 57 cur = FilePath(system_buffer); |
56 break; | 58 break; |
57 case base::DIR_IE_INTERNET_CACHE: | 59 case base::DIR_IE_INTERNET_CACHE: |
58 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, | 60 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, |
59 SHGFP_TYPE_CURRENT, system_buffer))) | 61 SHGFP_TYPE_CURRENT, system_buffer))) |
60 return false; | 62 return false; |
61 cur = system_buffer; | 63 cur = FilePath(system_buffer); |
62 break; | 64 break; |
63 case base::DIR_COMMON_START_MENU: | 65 case base::DIR_COMMON_START_MENU: |
64 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, | 66 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, |
65 SHGFP_TYPE_CURRENT, system_buffer))) | 67 SHGFP_TYPE_CURRENT, system_buffer))) |
66 return false; | 68 return false; |
67 cur = system_buffer; | 69 cur = FilePath(system_buffer); |
68 break; | 70 break; |
69 case base::DIR_START_MENU: | 71 case base::DIR_START_MENU: |
70 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL, | 72 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAMS, NULL, |
71 SHGFP_TYPE_CURRENT, system_buffer))) | 73 SHGFP_TYPE_CURRENT, system_buffer))) |
72 return false; | 74 return false; |
73 cur = system_buffer; | 75 cur = FilePath(system_buffer); |
74 break; | 76 break; |
75 case base::DIR_APP_DATA: | 77 case base::DIR_APP_DATA: |
76 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, | 78 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |
77 system_buffer))) | 79 system_buffer))) |
78 return false; | 80 return false; |
79 cur = system_buffer; | 81 cur = FilePath(system_buffer); |
80 break; | 82 break; |
81 case base::DIR_LOCAL_APP_DATA_LOW: | 83 case base::DIR_LOCAL_APP_DATA_LOW: |
82 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { | 84 if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { |
83 return false; | 85 return false; |
84 } | 86 } |
85 // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128 | 87 // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128 |
86 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, | 88 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |
87 system_buffer))) | 89 system_buffer))) |
88 return false; | 90 return false; |
89 cur = system_buffer; | 91 wstring_path = system_buffer; |
90 file_util::UpOneDirectory(&cur); | 92 file_util::UpOneDirectory(&wstring_path); |
91 file_util::AppendToPath(&cur, L"LocalLow"); | 93 file_util::AppendToPath(&wstring_path, L"LocalLow"); |
| 94 cur = FilePath(wstring_path); |
92 break; | 95 break; |
93 case base::DIR_LOCAL_APP_DATA: | 96 case base::DIR_LOCAL_APP_DATA: |
94 if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, | 97 if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, |
95 SHGFP_TYPE_CURRENT, system_buffer))) | 98 SHGFP_TYPE_CURRENT, system_buffer))) |
96 return false; | 99 return false; |
97 cur = system_buffer; | 100 cur = FilePath(system_buffer); |
98 break; | 101 break; |
99 case base::DIR_SOURCE_ROOT: | 102 case base::DIR_SOURCE_ROOT: |
100 // On Windows, unit tests execute two levels deep from the source root. | 103 // On Windows, unit tests execute two levels deep from the source root. |
101 // For example: chrome/{Debug|Release}/ui_tests.exe | 104 // For example: chrome/{Debug|Release}/ui_tests.exe |
102 PathService::Get(base::DIR_EXE, &cur); | 105 PathService::Get(base::DIR_EXE, &wstring_path); |
103 file_util::UpOneDirectory(&cur); | 106 file_util::UpOneDirectory(&wstring_path); |
104 file_util::UpOneDirectory(&cur); | 107 file_util::UpOneDirectory(&wstring_path); |
| 108 cur = FilePath(wstring_path); |
105 break; | 109 break; |
106 default: | 110 default: |
107 return false; | 111 return false; |
108 } | 112 } |
109 | 113 |
110 result->swap(cur); | 114 *result = cur; |
111 return true; | 115 return true; |
112 } | 116 } |
113 | 117 |
114 } // namespace base | 118 } // namespace base |
115 | 119 |
OLD | NEW |