blob: 42230cd6fdb26a84d58a6ca4665ff320c4f9481b [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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]c9349d082008-08-22 21:16:474
5#include "chrome/app/client_util.h"
[email protected]48d43872008-11-04 23:38:326#include "chrome/installer/util/install_util.h"
[email protected]c9349d082008-08-22 21:16:477
[email protected]2414e842008-11-07 01:27:578#include "chrome/installer/util/google_update_constants.h"
[email protected]28c19692008-11-07 23:40:389#include "chrome/installer/util/util_constants.h"
10
11namespace {
12bool 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]c9349d082008-08-22 21:16:4732
[email protected]2414e842008-11-07 01:27:5733namespace client_util {
[email protected]c9349d082008-08-22 21:16:4734bool FileExists(const wchar_t* const file_path) {
35 WIN32_FILE_ATTRIBUTE_DATA attrs;
36 return ::GetFileAttributesEx(file_path, GetFileExInfoStandard, &attrs) != 0;
37}
38
39bool GetChromiumVersion(const wchar_t* const exe_path,
40 const wchar_t* const reg_key_path,
41 wchar_t** version) {
[email protected]48d43872008-11-04 23:38:3242 HKEY reg_root = InstallUtil::IsPerUserInstall(exe_path) ? HKEY_CURRENT_USER :
[email protected]28c19692008-11-07 23:40:3843 HKEY_LOCAL_MACHINE;
[email protected]c9349d082008-08-22 21:16:4744 HKEY reg_key;
45 if (::RegOpenKeyEx(reg_root, reg_key_path, 0,
46 KEY_READ, &reg_key) != ERROR_SUCCESS) {
47 return false;
48 }
[email protected]28c19692008-11-07 23:40:3849
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]2414e842008-11-07 01:27:5755 ::RegCloseKey(reg_key);
[email protected]28c19692008-11-07 23:40:3856 return true;
[email protected]2414e842008-11-07 01:27:5757 }
58
[email protected]28c19692008-11-07 23:40:3859 bool ret = ReadStrValueFromRegistry(reg_key,
60 google_update::kRegVersionField,
61 version);
[email protected]c9349d082008-08-22 21:16:4762 ::RegCloseKey(reg_key);
63 return ret;
64}
65
[email protected]4522cfd2008-08-29 23:58:1066std::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]c9349d082008-08-22 21:16:4783void 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]c9349d082008-08-22 21:16:4794} // namespace client_util
license.botbf09a502008-08-24 00:55:5595