license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 4 | |
| 5 | #include "chrome/app/client_util.h" |
[email protected] | 48d4387 | 2008-11-04 23:38:32 | [diff] [blame] | 6 | #include "chrome/installer/util/install_util.h" |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 7 | |
[email protected] | 2414e84 | 2008-11-07 01:27:57 | [diff] [blame] | 8 | #include "chrome/installer/util/google_update_constants.h" |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame^] | 9 | #include "chrome/installer/util/util_constants.h" |
| 10 | |
| 11 | namespace { |
| 12 | bool ReadStrValueFromRegistry(const HKEY reg_key, |
| 13 | const wchar_t* const value_name, |
| 14 | wchar_t** value) { |
| 15 | DWORD size = 0; |
| 16 | if (::RegQueryValueEx(reg_key, value_name, NULL, NULL, NULL, |
| 17 | &size) != ERROR_SUCCESS) { |
| 18 | return false; |
| 19 | } |
| 20 | |
| 21 | *value = new wchar_t[1 + (size / sizeof(wchar_t))]; |
| 22 | if (::RegQueryValueEx(reg_key, value_name, NULL, NULL, |
| 23 | reinterpret_cast<BYTE*>(*value), |
| 24 | &size) != ERROR_SUCCESS) { |
| 25 | delete[] *value; |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | return true; |
| 30 | } |
| 31 | } |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 32 | |
[email protected] | 2414e84 | 2008-11-07 01:27:57 | [diff] [blame] | 33 | namespace client_util { |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 34 | bool FileExists(const wchar_t* const file_path) { |
| 35 | WIN32_FILE_ATTRIBUTE_DATA attrs; |
| 36 | return ::GetFileAttributesEx(file_path, GetFileExInfoStandard, &attrs) != 0; |
| 37 | } |
| 38 | |
| 39 | bool GetChromiumVersion(const wchar_t* const exe_path, |
| 40 | const wchar_t* const reg_key_path, |
| 41 | wchar_t** version) { |
[email protected] | 48d4387 | 2008-11-04 23:38:32 | [diff] [blame] | 42 | HKEY reg_root = InstallUtil::IsPerUserInstall(exe_path) ? HKEY_CURRENT_USER : |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame^] | 43 | HKEY_LOCAL_MACHINE; |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 44 | HKEY reg_key; |
| 45 | if (::RegOpenKeyEx(reg_root, reg_key_path, 0, |
| 46 | KEY_READ, ®_key) != ERROR_SUCCESS) { |
| 47 | return false; |
| 48 | } |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame^] | 49 | |
| 50 | std::wstring new_chrome_exe(exe_path); |
| 51 | new_chrome_exe.append(installer_util::kChromeNewExe); |
| 52 | if (FileExists(new_chrome_exe.c_str()) && |
| 53 | ReadStrValueFromRegistry(reg_key, google_update::kRegOldVersionField, |
| 54 | version)) { |
[email protected] | 2414e84 | 2008-11-07 01:27:57 | [diff] [blame] | 55 | ::RegCloseKey(reg_key); |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame^] | 56 | return true; |
[email protected] | 2414e84 | 2008-11-07 01:27:57 | [diff] [blame] | 57 | } |
| 58 | |
[email protected] | 28c1969 | 2008-11-07 23:40:38 | [diff] [blame^] | 59 | bool ret = ReadStrValueFromRegistry(reg_key, |
| 60 | google_update::kRegVersionField, |
| 61 | version); |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 62 | ::RegCloseKey(reg_key); |
| 63 | return ret; |
| 64 | } |
| 65 | |
[email protected] | 4522cfd | 2008-08-29 23:58:10 | [diff] [blame] | 66 | std::wstring GetDLLPath(const std::wstring dll_name, |
| 67 | const std::wstring dll_path) { |
| 68 | if (!dll_path.empty() && FileExists(dll_path.c_str())) |
| 69 | return dll_path + L"\\" + dll_name; |
| 70 | |
| 71 | // This is not an official build. Find the dll using the default |
| 72 | // path order in LoadLibrary. |
| 73 | wchar_t path[MAX_PATH] = {0}; |
| 74 | wchar_t* file_part = NULL; |
| 75 | DWORD result = ::SearchPath(NULL, dll_name.c_str(), NULL, MAX_PATH, |
| 76 | path, &file_part); |
| 77 | if (result == 0 || result > MAX_PATH) |
| 78 | return std::wstring(); |
| 79 | |
| 80 | return path; |
| 81 | } |
| 82 | |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 83 | void GetExecutablePath(wchar_t* exe_path) { |
| 84 | DWORD len = ::GetModuleFileName(NULL, exe_path, MAX_PATH); |
| 85 | wchar_t* tmp = exe_path + len - 1; |
| 86 | while (tmp >= exe_path && *tmp != L'\\') |
| 87 | tmp--; |
| 88 | if (tmp > exe_path) { |
| 89 | tmp++; |
| 90 | *tmp = 0; |
| 91 | } |
| 92 | } |
| 93 | |
[email protected] | c9349d08 | 2008-08-22 21:16:47 | [diff] [blame] | 94 | } // namespace client_util |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 95 | |