OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
6 #include <shlobj.h> | 6 #include <shlobj.h> |
7 | 7 |
8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/win/scoped_co_mem.h" | 11 #include "base/win/scoped_co_mem.h" |
12 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
13 | 13 |
14 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 14 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
15 extern "C" IMAGE_DOS_HEADER __ImageBase; | 15 extern "C" IMAGE_DOS_HEADER __ImageBase; |
16 | 16 |
17 using base::FilePath; | 17 using base::FilePath; |
18 | 18 |
19 namespace { | |
20 | |
21 bool GetQuickLaunchPath(bool default_user, FilePath* result) { | |
22 if (default_user) { | |
23 wchar_t system_buffer[MAX_PATH]; | |
24 system_buffer[0] = 0; | |
25 // As per MSDN, passing -1 for |hToken| indicates the Default user: | |
26 // http://msdn.microsoft.com/library/windows/desktop/bb762181.aspx | |
27 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, | |
28 reinterpret_cast<HANDLE>(-1), SHGFP_TYPE_CURRENT, | |
29 system_buffer))) { | |
30 return false; | |
31 } | |
32 *result = FilePath(system_buffer); | |
33 } else if (!PathService::Get(base::DIR_APP_DATA, result)) { | |
34 // For the current user, grab the APPDATA directory directly from the | |
35 // PathService cache. | |
36 return false; | |
37 } | |
38 // According to various sources, appending | |
39 // "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only | |
40 // reliable way to get the quick launch folder across all versions of Windows. | |
41 // http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-quick- | |
42 // http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/hey090
1.mspx | |
43 *result = result->AppendASCII("Microsoft"); | |
44 *result = result->AppendASCII("Internet Explorer"); | |
45 *result = result->AppendASCII("Quick Launch"); | |
46 return true; | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 namespace base { | 19 namespace base { |
52 | 20 |
53 bool PathProviderWin(int key, FilePath* result) { | 21 bool PathProviderWin(int key, FilePath* result) { |
54 // 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 |
55 // 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 |
56 // designed for it either, with the exception of GetTempPath (but other | 24 // designed for it either, with the exception of GetTempPath (but other |
57 // 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 |
58 // handling it. | 26 // handling it. |
59 wchar_t system_buffer[MAX_PATH]; | 27 wchar_t system_buffer[MAX_PATH]; |
60 system_buffer[0] = 0; | 28 system_buffer[0] = 0; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 cur = FilePath(system_buffer); | 139 cur = FilePath(system_buffer); |
172 break; | 140 break; |
173 case base::DIR_COMMON_DESKTOP: | 141 case base::DIR_COMMON_DESKTOP: |
174 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, | 142 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, |
175 SHGFP_TYPE_CURRENT, system_buffer))) { | 143 SHGFP_TYPE_CURRENT, system_buffer))) { |
176 return false; | 144 return false; |
177 } | 145 } |
178 cur = FilePath(system_buffer); | 146 cur = FilePath(system_buffer); |
179 break; | 147 break; |
180 case base::DIR_USER_QUICK_LAUNCH: | 148 case base::DIR_USER_QUICK_LAUNCH: |
181 if (!GetQuickLaunchPath(false, &cur)) | 149 if (!PathService::Get(base::DIR_APP_DATA, &cur)) |
182 return false; | 150 return false; |
183 break; | 151 // According to various sources, appending |
184 case base::DIR_DEFAULT_USER_QUICK_LAUNCH: | 152 // "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only |
185 if (!GetQuickLaunchPath(true, &cur)) | 153 // reliable way to get the quick launch folder across all versions of |
186 return false; | 154 // Windows. |
| 155 // http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-qu
ick- |
| 156 // http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/he
y0901.mspx |
| 157 cur = cur.AppendASCII("Microsoft") |
| 158 .AppendASCII("Internet Explorer") |
| 159 .AppendASCII("Quick Launch"); |
187 break; | 160 break; |
188 case base::DIR_TASKBAR_PINS: | 161 case base::DIR_TASKBAR_PINS: |
189 if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur)) | 162 if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur)) |
190 return false; | 163 return false; |
191 cur = cur.AppendASCII("User Pinned"); | 164 cur = cur.AppendASCII("User Pinned"); |
192 cur = cur.AppendASCII("TaskBar"); | 165 cur = cur.AppendASCII("TaskBar"); |
193 break; | 166 break; |
194 case base::DIR_WINDOWS_FONTS: | 167 case base::DIR_WINDOWS_FONTS: |
195 if (FAILED(SHGetFolderPath( | 168 if (FAILED(SHGetFolderPath( |
196 NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, system_buffer))) { | 169 NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, system_buffer))) { |
197 return false; | 170 return false; |
198 } | 171 } |
199 cur = FilePath(system_buffer); | 172 cur = FilePath(system_buffer); |
200 break; | 173 break; |
201 default: | 174 default: |
202 return false; | 175 return false; |
203 } | 176 } |
204 | 177 |
205 *result = cur; | 178 *result = cur; |
206 return true; | 179 return true; |
207 } | 180 } |
208 | 181 |
209 } // namespace base | 182 } // namespace base |
OLD | NEW |