| 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 "base/base_paths_win.h" | 
|    5  |    6  | 
|    6 #include <windows.h> |    7 #include <windows.h> | 
|    7 #include <shlobj.h> |    8 #include <shlobj.h> | 
|    8  |    9  | 
|    9 #include "base/base_paths.h" |  | 
|   10 #include "base/file_path.h" |   10 #include "base/file_path.h" | 
|   11 #include "base/file_util.h" |   11 #include "base/file_util.h" | 
|   12 #include "base/path_service.h" |   12 #include "base/path_service.h" | 
|   13 #include "base/win/scoped_co_mem.h" |   13 #include "base/win/scoped_co_mem.h" | 
|   14 #include "base/win/windows_version.h" |   14 #include "base/win/windows_version.h" | 
|   15  |   15  | 
|   16 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |   16 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 
|   17 extern "C" IMAGE_DOS_HEADER __ImageBase; |   17 extern "C" IMAGE_DOS_HEADER __ImageBase; | 
|   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  |   22  | 
|   55   // We need to go compute the value. It would be nice to support paths with |   23   // We need to go compute the value. It would be nice to support paths with | 
|   56   // names longer than MAX_PATH, but the system functions don't seem to be |   24   // names longer than MAX_PATH, but the system functions don't seem to be | 
|   57   // designed for it either, with the exception of GetTempPath (but other |   25   // designed for it either, with the exception of GetTempPath (but other | 
|   58   // things will surely break if the temp path is too long, so we don't bother |   26   // things will surely break if the temp path is too long, so we don't bother | 
|   59   // handling it. |   27   // handling it. | 
|   60   wchar_t system_buffer[MAX_PATH]; |   28   wchar_t system_buffer[MAX_PATH]; | 
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  128         return false; |   96         return false; | 
|  129       cur = FilePath(system_buffer); |   97       cur = FilePath(system_buffer); | 
|  130       break; |   98       break; | 
|  131     case base::DIR_PROFILE: |   99     case base::DIR_PROFILE: | 
|  132       if (FAILED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, |  100       if (FAILED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, | 
|  133                                  system_buffer))) |  101                                  system_buffer))) | 
|  134         return false; |  102         return false; | 
|  135       cur = FilePath(system_buffer); |  103       cur = FilePath(system_buffer); | 
|  136       break; |  104       break; | 
|  137     case base::DIR_LOCAL_APP_DATA_LOW: |  105     case base::DIR_LOCAL_APP_DATA_LOW: | 
|  138       if (win::GetVersion() < win::VERSION_VISTA) |  106       if (win::GetVersion() < win::VERSION_VISTA) { | 
|  139         return false; |  107         return false; | 
|  140  |  108       } | 
|  141       // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128 |  109       // TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128 | 
|  142       if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |  110       if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, | 
|  143                                  system_buffer))) |  111                                  system_buffer))) | 
|  144         return false; |  112         return false; | 
|  145       cur = FilePath(system_buffer).DirName().AppendASCII("LocalLow"); |  113       cur = FilePath(system_buffer).DirName().AppendASCII("LocalLow"); | 
|  146       break; |  114       break; | 
|  147     case base::DIR_LOCAL_APP_DATA: |  115     case base::DIR_LOCAL_APP_DATA: | 
|  148       if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, |  116       if (FAILED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, | 
|  149                                  SHGFP_TYPE_CURRENT, system_buffer))) |  117                                  SHGFP_TYPE_CURRENT, system_buffer))) | 
|  150         return false; |  118         return false; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  163         return false; |  131         return false; | 
|  164  |  132  | 
|  165       base::win::ScopedCoMem<wchar_t> path_buf; |  133       base::win::ScopedCoMem<wchar_t> path_buf; | 
|  166       if (FAILED(SHGetKnownFolderPath(FOLDERID_ApplicationShortcuts, 0, NULL, |  134       if (FAILED(SHGetKnownFolderPath(FOLDERID_ApplicationShortcuts, 0, NULL, | 
|  167                                       &path_buf))) |  135                                       &path_buf))) | 
|  168         return false; |  136         return false; | 
|  169  |  137  | 
|  170       cur = FilePath(string16(path_buf)); |  138       cur = FilePath(string16(path_buf)); | 
|  171       break; |  139       break; | 
|  172     } |  140     } | 
|  173     case base::DIR_USER_DESKTOP: |  | 
|  174       if (FAILED(SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL, |  | 
|  175                                  SHGFP_TYPE_CURRENT, system_buffer))) { |  | 
|  176         return false; |  | 
|  177       } |  | 
|  178       cur = FilePath(system_buffer); |  | 
|  179       break; |  | 
|  180     case base::DIR_COMMON_DESKTOP: |  | 
|  181       if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_DESKTOPDIRECTORY, NULL, |  | 
|  182                                  SHGFP_TYPE_CURRENT, system_buffer))) { |  | 
|  183         return false; |  | 
|  184       } |  | 
|  185       cur = FilePath(system_buffer); |  | 
|  186       break; |  | 
|  187     case base::DIR_USER_QUICK_LAUNCH: |  | 
|  188       if (!GetQuickLaunchPath(false, &cur)) |  | 
|  189         return false; |  | 
|  190       break; |  | 
|  191     case base::DIR_DEFAULT_USER_QUICK_LAUNCH: |  | 
|  192       if (!GetQuickLaunchPath(true, &cur)) |  | 
|  193         return false; |  | 
|  194       break; |  | 
|  195     default: |  141     default: | 
|  196       return false; |  142       return false; | 
|  197   } |  143   } | 
|  198  |  144  | 
|  199   *result = cur; |  145   *result = cur; | 
|  200   return true; |  146   return true; | 
|  201 } |  147 } | 
|  202  |  148  | 
|  203 }  // namespace base |  149 }  // namespace base | 
| OLD | NEW |