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/environment.h" |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
11 #include "base/win/scoped_co_mem.h" | 13 #include "base/win/scoped_co_mem.h" |
12 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
13 | 15 |
14 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | 16 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
15 extern "C" IMAGE_DOS_HEADER __ImageBase; | 17 extern "C" IMAGE_DOS_HEADER __ImageBase; |
16 | 18 |
17 using base::FilePath; | 19 using base::FilePath; |
18 | 20 |
19 namespace base { | 21 namespace base { |
20 | 22 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 cur = FilePath(system_buffer); | 60 cur = FilePath(system_buffer); |
59 break; | 61 break; |
60 } | 62 } |
61 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. | 63 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. |
62 case base::DIR_PROGRAM_FILES: | 64 case base::DIR_PROGRAM_FILES: |
63 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, | 65 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
64 SHGFP_TYPE_CURRENT, system_buffer))) | 66 SHGFP_TYPE_CURRENT, system_buffer))) |
65 return false; | 67 return false; |
66 cur = FilePath(system_buffer); | 68 cur = FilePath(system_buffer); |
67 break; | 69 break; |
| 70 case base::DIR_PROGRAM_FILES6432: |
| 71 #if !defined(_WIN64) |
| 72 if (base::win::OSInfo::GetInstance()->wow64_status() == |
| 73 base::win::OSInfo::WOW64_ENABLED) { |
| 74 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 75 std::string programfiles_w6432; |
| 76 // 32-bit process running in WOW64 sets ProgramW6432 environment |
| 77 // variable. See |
| 78 // https://msdn.microsoft.com/library/windows/desktop/aa384274.aspx. |
| 79 if (!env->GetVar("ProgramW6432", &programfiles_w6432)) |
| 80 return false; |
| 81 // GetVar returns UTF8 - convert back to Wide. |
| 82 cur = FilePath(UTF8ToWide(programfiles_w6432)); |
| 83 break; |
| 84 } |
| 85 #endif |
| 86 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
| 87 SHGFP_TYPE_CURRENT, system_buffer))) |
| 88 return false; |
| 89 cur = FilePath(system_buffer); |
| 90 break; |
68 case base::DIR_IE_INTERNET_CACHE: | 91 case base::DIR_IE_INTERNET_CACHE: |
69 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, | 92 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, |
70 SHGFP_TYPE_CURRENT, system_buffer))) | 93 SHGFP_TYPE_CURRENT, system_buffer))) |
71 return false; | 94 return false; |
72 cur = FilePath(system_buffer); | 95 cur = FilePath(system_buffer); |
73 break; | 96 break; |
74 case base::DIR_COMMON_START_MENU: | 97 case base::DIR_COMMON_START_MENU: |
75 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, | 98 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, |
76 SHGFP_TYPE_CURRENT, system_buffer))) | 99 SHGFP_TYPE_CURRENT, system_buffer))) |
77 return false; | 100 return false; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 break; | 186 break; |
164 default: | 187 default: |
165 return false; | 188 return false; |
166 } | 189 } |
167 | 190 |
168 *result = cur; | 191 *result = cur; |
169 return true; | 192 return true; |
170 } | 193 } |
171 | 194 |
172 } // namespace base | 195 } // namespace base |
OLD | NEW |