Chromium Code Reviews| 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)) { |
| 150 // For the current user, grab the APPDATA directory directly from the | |
|
grt (UTC plus 2)
2014/08/04 18:27:07
nit: move this comment up above the "if" and nix t
gab
2014/08/04 18:57:07
Actually I'll just remove this comment, it's no lo
| |
| 151 // PathService cache. | |
| 182 return false; | 152 return false; |
| 183 break; | 153 } |
| 184 case base::DIR_DEFAULT_USER_QUICK_LAUNCH: | 154 // According to various sources, appending |
| 185 if (!GetQuickLaunchPath(true, &cur)) | 155 // "Microsoft\Internet Explorer\Quick Launch" to %appdata% is the only |
| 186 return false; | 156 // reliable way to get the quick launch folder across all versions of |
| 157 // Windows. | |
| 158 // http://stackoverflow.com/questions/76080/how-do-you-reliably-get-the-qu ick- | |
| 159 // http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept05/he y0901.mspx | |
| 160 cur = cur.AppendASCII("Microsoft") | |
| 161 .AppendASCII("Internet Explorer") | |
|
grt (UTC plus 2)
2014/08/04 18:27:08
is this how git cl format does things? shouldn't t
gab
2014/08/04 18:57:08
Yes it is, I like it as-is personally.
| |
| 162 .AppendASCII("Quick Launch"); | |
| 187 break; | 163 break; |
| 188 case base::DIR_TASKBAR_PINS: | 164 case base::DIR_TASKBAR_PINS: |
| 189 if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur)) | 165 if (!PathService::Get(base::DIR_USER_QUICK_LAUNCH, &cur)) |
| 190 return false; | 166 return false; |
| 191 cur = cur.AppendASCII("User Pinned"); | 167 cur = cur.AppendASCII("User Pinned"); |
| 192 cur = cur.AppendASCII("TaskBar"); | 168 cur = cur.AppendASCII("TaskBar"); |
| 193 break; | 169 break; |
| 194 case base::DIR_WINDOWS_FONTS: | 170 case base::DIR_WINDOWS_FONTS: |
| 195 if (FAILED(SHGetFolderPath( | 171 if (FAILED(SHGetFolderPath( |
| 196 NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, system_buffer))) { | 172 NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, system_buffer))) { |
| 197 return false; | 173 return false; |
| 198 } | 174 } |
| 199 cur = FilePath(system_buffer); | 175 cur = FilePath(system_buffer); |
| 200 break; | 176 break; |
| 201 default: | 177 default: |
| 202 return false; | 178 return false; |
| 203 } | 179 } |
| 204 | 180 |
| 205 *result = cur; | 181 *result = cur; |
| 206 return true; | 182 return true; |
| 207 } | 183 } |
| 208 | 184 |
| 209 } // namespace base | 185 } // namespace base |
| OLD | NEW |