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/environment.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // 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 |
26 // designed for it either, with the exception of GetTempPath (but other | 26 // designed for it either, with the exception of GetTempPath (but other |
27 // 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 |
28 // handling it. | 28 // handling it. |
29 wchar_t system_buffer[MAX_PATH]; | 29 wchar_t system_buffer[MAX_PATH]; |
30 system_buffer[0] = 0; | 30 system_buffer[0] = 0; |
31 | 31 |
32 FilePath cur; | 32 FilePath cur; |
33 switch (key) { | 33 switch (key) { |
34 case base::FILE_EXE: | 34 case base::FILE_EXE: |
35 GetModuleFileName(NULL, system_buffer, MAX_PATH); | 35 if (GetModuleFileName(NULL, system_buffer, MAX_PATH) == 0) |
| 36 return false; |
36 cur = FilePath(system_buffer); | 37 cur = FilePath(system_buffer); |
37 break; | 38 break; |
38 case base::FILE_MODULE: { | 39 case base::FILE_MODULE: { |
39 // the resource containing module is assumed to be the one that | 40 // the resource containing module is assumed to be the one that |
40 // this code lives in, whether that's a dll or exe | 41 // this code lives in, whether that's a dll or exe |
41 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); | 42 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); |
42 GetModuleFileName(this_module, system_buffer, MAX_PATH); | 43 if (GetModuleFileName(this_module, system_buffer, MAX_PATH) == 0) |
| 44 return false; |
43 cur = FilePath(system_buffer); | 45 cur = FilePath(system_buffer); |
44 break; | 46 break; |
45 } | 47 } |
46 case base::DIR_WINDOWS: | 48 case base::DIR_WINDOWS: |
47 GetWindowsDirectory(system_buffer, MAX_PATH); | 49 GetWindowsDirectory(system_buffer, MAX_PATH); |
48 cur = FilePath(system_buffer); | 50 cur = FilePath(system_buffer); |
49 break; | 51 break; |
50 case base::DIR_SYSTEM: | 52 case base::DIR_SYSTEM: |
51 GetSystemDirectory(system_buffer, MAX_PATH); | 53 GetSystemDirectory(system_buffer, MAX_PATH); |
52 cur = FilePath(system_buffer); | 54 cur = FilePath(system_buffer); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 break; | 188 break; |
187 default: | 189 default: |
188 return false; | 190 return false; |
189 } | 191 } |
190 | 192 |
191 *result = cur; | 193 *result = cur; |
192 return true; | 194 return true; |
193 } | 195 } |
194 | 196 |
195 } // namespace base | 197 } // namespace base |
OLD | NEW |