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 |
21 bool PathProviderWin(int key, FilePath* result) { | 23 bool PathProviderWin(int key, FilePath* result) { |
22 // We need to go compute the value. It would be nice to support paths with | 24 // We need to go compute the value. It would be nice to support paths with |
23 // names longer than MAX_PATH, but the system functions don't seem to be | 25 // names longer than MAX_PATH, but the system functions don't seem to be |
24 // designed for it either, with the exception of GetTempPath (but other | 26 // designed for it either, with the exception of GetTempPath (but other |
25 // things will surely break if the temp path is too long, so we don't bother | 27 // things will surely break if the temp path is too long, so we don't bother |
26 // handling it. | 28 // handling it. |
27 wchar_t system_buffer[MAX_PATH]; | 29 wchar_t system_buffer[MAX_PATH]; |
28 system_buffer[0] = 0; | 30 system_buffer[0] = 0; |
31 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
grt (UTC plus 2)
2015/03/12 13:34:44
move these down into a block in the base::DIR_PROG
Will Harris
2015/03/12 20:34:29
Done.
| |
32 std::string programfiles_w6432; | |
29 | 33 |
30 FilePath cur; | 34 FilePath cur; |
31 switch (key) { | 35 switch (key) { |
32 case base::FILE_EXE: | 36 case base::FILE_EXE: |
33 GetModuleFileName(NULL, system_buffer, MAX_PATH); | 37 GetModuleFileName(NULL, system_buffer, MAX_PATH); |
34 cur = FilePath(system_buffer); | 38 cur = FilePath(system_buffer); |
35 break; | 39 break; |
36 case base::FILE_MODULE: { | 40 case base::FILE_MODULE: { |
37 // the resource containing module is assumed to be the one that | 41 // the resource containing module is assumed to be the one that |
38 // this code lives in, whether that's a dll or exe | 42 // this code lives in, whether that's a dll or exe |
(...skipping 19 matching lines...) Expand all Loading... | |
58 cur = FilePath(system_buffer); | 62 cur = FilePath(system_buffer); |
59 break; | 63 break; |
60 } | 64 } |
61 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. | 65 // Fall through to base::DIR_PROGRAM_FILES if we're on an X86 machine. |
62 case base::DIR_PROGRAM_FILES: | 66 case base::DIR_PROGRAM_FILES: |
63 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, | 67 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, |
64 SHGFP_TYPE_CURRENT, system_buffer))) | 68 SHGFP_TYPE_CURRENT, system_buffer))) |
65 return false; | 69 return false; |
66 cur = FilePath(system_buffer); | 70 cur = FilePath(system_buffer); |
67 break; | 71 break; |
72 case base::DIR_PROGRAM_FILES6432: | |
73 #if !defined(_WIN64) | |
74 // 32-bit process running in WOW64 sets ProgramW6432 environment variable. | |
grt (UTC plus 2)
2015/03/12 13:34:44
How about reducing the dependence on the variable
Will Harris
2015/03/12 20:34:29
Done.
| |
75 // See https://msdn.microsoft.com/library/windows/desktop/aa384274.aspx | |
76 if (env->GetVar("ProgramW6432", &programfiles_w6432)) { | |
77 // GetVar returns UTF8 - convert back to Wide. | |
78 cur = FilePath(UTF8ToWide(programfiles_w6432)); | |
79 break; | |
80 } | |
81 #endif | |
82 if (FAILED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, | |
83 SHGFP_TYPE_CURRENT, system_buffer))) | |
84 return false; | |
85 cur = FilePath(system_buffer); | |
86 break; | |
68 case base::DIR_IE_INTERNET_CACHE: | 87 case base::DIR_IE_INTERNET_CACHE: |
69 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, | 88 if (FAILED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, |
70 SHGFP_TYPE_CURRENT, system_buffer))) | 89 SHGFP_TYPE_CURRENT, system_buffer))) |
71 return false; | 90 return false; |
72 cur = FilePath(system_buffer); | 91 cur = FilePath(system_buffer); |
73 break; | 92 break; |
74 case base::DIR_COMMON_START_MENU: | 93 case base::DIR_COMMON_START_MENU: |
75 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, | 94 if (FAILED(SHGetFolderPath(NULL, CSIDL_COMMON_PROGRAMS, NULL, |
76 SHGFP_TYPE_CURRENT, system_buffer))) | 95 SHGFP_TYPE_CURRENT, system_buffer))) |
77 return false; | 96 return false; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 break; | 182 break; |
164 default: | 183 default: |
165 return false; | 184 return false; |
166 } | 185 } |
167 | 186 |
168 *result = cur; | 187 *result = cur; |
169 return true; | 188 return true; |
170 } | 189 } |
171 | 190 |
172 } // namespace base | 191 } // namespace base |
OLD | NEW |