| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/win/current_module.h" |
| 13 #include "base/win/scoped_co_mem.h" | 14 #include "base/win/scoped_co_mem.h" |
| 14 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
| 15 | 16 |
| 16 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx | |
| 17 extern "C" IMAGE_DOS_HEADER __ImageBase; | |
| 18 | |
| 19 using base::FilePath; | 17 using base::FilePath; |
| 20 | 18 |
| 21 namespace base { | 19 namespace base { |
| 22 | 20 |
| 23 bool PathProviderWin(int key, FilePath* result) { | 21 bool PathProviderWin(int key, FilePath* result) { |
| 24 // 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 |
| 25 // 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 |
| 26 // designed for it either, with the exception of GetTempPath (but other | 24 // 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 | 25 // things will surely break if the temp path is too long, so we don't bother |
| 28 // handling it. | 26 // handling it. |
| 29 wchar_t system_buffer[MAX_PATH]; | 27 wchar_t system_buffer[MAX_PATH]; |
| 30 system_buffer[0] = 0; | 28 system_buffer[0] = 0; |
| 31 | 29 |
| 32 FilePath cur; | 30 FilePath cur; |
| 33 switch (key) { | 31 switch (key) { |
| 34 case base::FILE_EXE: | 32 case base::FILE_EXE: |
| 35 if (GetModuleFileName(NULL, system_buffer, MAX_PATH) == 0) | 33 if (GetModuleFileName(NULL, system_buffer, MAX_PATH) == 0) |
| 36 return false; | 34 return false; |
| 37 cur = FilePath(system_buffer); | 35 cur = FilePath(system_buffer); |
| 38 break; | 36 break; |
| 39 case base::FILE_MODULE: { | 37 case base::FILE_MODULE: { |
| 40 // the resource containing module is assumed to be the one that | 38 // the resource containing module is assumed to be the one that |
| 41 // this code lives in, whether that's a dll or exe | 39 // this code lives in, whether that's a dll or exe |
| 42 HMODULE this_module = reinterpret_cast<HMODULE>(&__ImageBase); | 40 if (GetModuleFileName(CURRENT_MODULE(), system_buffer, MAX_PATH) == 0) |
| 43 if (GetModuleFileName(this_module, system_buffer, MAX_PATH) == 0) | |
| 44 return false; | 41 return false; |
| 45 cur = FilePath(system_buffer); | 42 cur = FilePath(system_buffer); |
| 46 break; | 43 break; |
| 47 } | 44 } |
| 48 case base::DIR_WINDOWS: | 45 case base::DIR_WINDOWS: |
| 49 GetWindowsDirectory(system_buffer, MAX_PATH); | 46 GetWindowsDirectory(system_buffer, MAX_PATH); |
| 50 cur = FilePath(system_buffer); | 47 cur = FilePath(system_buffer); |
| 51 break; | 48 break; |
| 52 case base::DIR_SYSTEM: | 49 case base::DIR_SYSTEM: |
| 53 GetSystemDirectory(system_buffer, MAX_PATH); | 50 GetSystemDirectory(system_buffer, MAX_PATH); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 break; | 185 break; |
| 189 default: | 186 default: |
| 190 return false; | 187 return false; |
| 191 } | 188 } |
| 192 | 189 |
| 193 *result = cur; | 190 *result = cur; |
| 194 return true; | 191 return true; |
| 195 } | 192 } |
| 196 | 193 |
| 197 } // namespace base | 194 } // namespace base |
| OLD | NEW |