Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 // mini_installer.exe is the first exe that is run when chrome is being | 5 // mini_installer.exe is the first exe that is run when chrome is being |
| 6 // installed or upgraded. It is designed to be extremely small (~5KB with no | 6 // installed or upgraded. It is designed to be extremely small (~5KB with no |
| 7 // extra resources linked) and it has two main jobs: | 7 // extra resources linked) and it has two main jobs: |
| 8 // 1) unpack the resources (possibly decompressing some) | 8 // 1) unpack the resources (possibly decompressing some) |
| 9 // 2) run the real installer (setup.exe) with appropiate flags. | 9 // 2) run the real installer (setup.exe) with appropiate flags. |
| 10 // | 10 // |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 KEY_READ, &key) == ERROR_SUCCESS) && | 136 KEY_READ, &key) == ERROR_SUCCESS) && |
| 137 (::RegQueryValueEx(key, value_name, NULL, NULL, | 137 (::RegQueryValueEx(key, value_name, NULL, NULL, |
| 138 reinterpret_cast<LPBYTE>(value), | 138 reinterpret_cast<LPBYTE>(value), |
| 139 reinterpret_cast<LPDWORD>(&size)) == ERROR_SUCCESS)) { | 139 reinterpret_cast<LPDWORD>(&size)) == ERROR_SUCCESS)) { |
| 140 ::RegCloseKey(key); | 140 ::RegCloseKey(key); |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // This function sets the flag in registry to indicate that Google Update | |
| 147 // should try full installer next time. If the current installer works, this | |
| 148 // flag is cleared by setup.exe at the end of install. | |
| 149 void SetFullInstallerFlag(HKEY root_key) { | |
| 150 HKEY key; | |
| 151 if (::RegOpenKeyEx(root_key, kApRegistryKey, NULL, | |
| 152 KEY_READ | KEY_SET_VALUE, &key) != ERROR_SUCCESS) | |
|
sra
2009/06/15 21:20:52
Does RegOpenKeyEx allow subkeys to be a path with
kuchhal
2009/06/15 22:05:31
It works fine with the full path. I tested the new
| |
| 153 return; | |
|
sra
2009/06/15 21:20:52
Who initially creates the key? Open will fail if
kuchhal
2009/06/15 22:05:31
Yes it should fail in that case. If it is first in
| |
| 154 | |
| 155 wchar_t value[128]; | |
| 156 size_t size = _countof(value); | |
| 157 if ((::RegQueryValueEx(key, kApRegistryValueName, NULL, NULL, | |
| 158 reinterpret_cast<LPBYTE>(value), | |
| 159 reinterpret_cast<LPDWORD>(&size)) == ERROR_SUCCESS) && | |
| 160 (!StrEndsWith(value, kFullInstallerSuffix)) && | |
| 161 (SafeStrCat(value, size, kFullInstallerSuffix))) { | |
| 162 ::RegSetValueEx(key, kApRegistryValueName, 0, REG_SZ, | |
| 163 reinterpret_cast<LPBYTE>(value), | |
| 164 lstrlen(value) * sizeof(wchar_t)); | |
| 165 } | |
| 166 | |
| 167 ::RegCloseKey(key); | |
| 168 } | |
| 146 | 169 |
| 147 // Gets the setup.exe path from Registry by looking the value of Uninstall | 170 // Gets the setup.exe path from Registry by looking the value of Uninstall |
| 148 // string, strips the arguments for uninstall and returns only the full path | 171 // string, strips the arguments for uninstall and returns only the full path |
| 149 // to setup.exe. | 172 // to setup.exe. |
| 150 bool GetSetupExePathFromRegistry(wchar_t *path, size_t size) { | 173 bool GetSetupExePathFromRegistry(wchar_t *path, size_t size) { |
| 151 if (!ReadValueFromRegistry(HKEY_CURRENT_USER, kUninstallRegistryKey, | 174 if (!ReadValueFromRegistry(HKEY_CURRENT_USER, kUninstallRegistryKey, |
| 152 kUninstallRegistryValueName, path, size)) { | 175 kUninstallRegistryValueName, path, size)) { |
| 153 if (!ReadValueFromRegistry(HKEY_LOCAL_MACHINE, kUninstallRegistryKey, | 176 if (!ReadValueFromRegistry(HKEY_LOCAL_MACHINE, kUninstallRegistryKey, |
| 154 kUninstallRegistryValueName, path, size)) { | 177 kUninstallRegistryValueName, path, size)) { |
| 155 return false; | 178 return false; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 } | 488 } |
| 466 | 489 |
| 467 // Main function. First gets a working dir, unpacks the resources and finally | 490 // Main function. First gets a working dir, unpacks the resources and finally |
| 468 // executes setup.exe to do the install/upgrade. | 491 // executes setup.exe to do the install/upgrade. |
| 469 int WMain(HMODULE module) { | 492 int WMain(HMODULE module) { |
| 470 // First get a path where we can extract payload | 493 // First get a path where we can extract payload |
| 471 wchar_t base_path[MAX_PATH]; | 494 wchar_t base_path[MAX_PATH]; |
| 472 if (!GetWorkDir(module, base_path)) | 495 if (!GetWorkDir(module, base_path)) |
| 473 return 101; | 496 return 101; |
| 474 | 497 |
| 498 // Set the magic suffix in registry to try full installer next time. We ignore | |
| 499 // any errors here and we try to set the suffix for user level as well as | |
| 500 // system level. | |
| 501 SetFullInstallerFlag(HKEY_LOCAL_MACHINE); | |
| 502 SetFullInstallerFlag(HKEY_CURRENT_USER); | |
| 503 | |
| 475 wchar_t archive_path[MAX_PATH] = {0}; | 504 wchar_t archive_path[MAX_PATH] = {0}; |
| 476 wchar_t setup_path[MAX_PATH] = {0}; | 505 wchar_t setup_path[MAX_PATH] = {0}; |
| 477 if (!UnpackBinaryResources(module, base_path, archive_path, MAX_PATH, | 506 if (!UnpackBinaryResources(module, base_path, archive_path, MAX_PATH, |
| 478 setup_path, MAX_PATH)) | 507 setup_path, MAX_PATH)) |
| 479 return 102; | 508 return 102; |
| 480 | 509 |
| 481 int exit_code = 103; | 510 int exit_code = 103; |
| 482 if (!RunSetup(archive_path, setup_path, &exit_code)) | 511 if (!RunSetup(archive_path, setup_path, &exit_code)) |
| 483 return exit_code; | 512 return exit_code; |
| 484 | 513 |
| 485 wchar_t value[4]; | 514 wchar_t value[4]; |
| 486 if ((!ReadValueFromRegistry(HKEY_CURRENT_USER, kCleanupRegistryKey, | 515 if ((!ReadValueFromRegistry(HKEY_CURRENT_USER, kCleanupRegistryKey, |
| 487 kCleanupRegistryValueName, value, 4)) || | 516 kCleanupRegistryValueName, value, 4)) || |
| 488 (value[0] != L'0')) | 517 (value[0] != L'0')) |
| 489 DeleteExtractedFiles(base_path, archive_path, setup_path); | 518 DeleteExtractedFiles(base_path, archive_path, setup_path); |
| 490 | 519 |
| 491 return exit_code; | 520 return exit_code; |
| 492 } | 521 } |
| 493 } // namespace mini_installer | 522 } // namespace mini_installer |
| 494 | 523 |
| 495 | 524 |
| 496 int MainEntryPoint() { | 525 int MainEntryPoint() { |
| 497 int result = mini_installer::WMain(::GetModuleHandle(NULL)); | 526 int result = mini_installer::WMain(::GetModuleHandle(NULL)); |
| 498 ::ExitProcess(result); | 527 ::ExitProcess(result); |
| 499 } | 528 } |
| OLD | NEW |