| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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 <string> | 5 #include <string> |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #include <msi.h> | 7 #include <msi.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe); | 297 file_util::AppendToPath(&chrome_exe, installer_util::kChromeExe); |
| 298 std::wstring old_open_cmd = L"\"" + chrome_exe + L"\" \"%1\""; | 298 std::wstring old_open_cmd = L"\"" + chrome_exe + L"\" \"%1\""; |
| 299 std::wstring new_open_cmd = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 299 std::wstring new_open_cmd = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
| 300 std::wstring reg_key[] = { L"ChromeHTML\\shell\\open\\command", | 300 std::wstring reg_key[] = { L"ChromeHTML\\shell\\open\\command", |
| 301 L"http\\shell\\open\\command", | 301 L"http\\shell\\open\\command", |
| 302 L"https\\shell\\open\\command" }; | 302 L"https\\shell\\open\\command" }; |
| 303 for (int i = 0; i < _countof(reg_key); i++) | 303 for (int i = 0; i < _countof(reg_key); i++) |
| 304 ReplaceRegistryValue(reg_key[i], old_open_cmd, new_open_cmd); | 304 ReplaceRegistryValue(reg_key[i], old_open_cmd, new_open_cmd); |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool CheckPreInstallConditions(const installer::Version* installed_version, |
| 308 int options, |
| 309 installer_util::InstallStatus& status) { |
| 310 bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; |
| 311 |
| 312 // Check to avoid simultaneous per-user and per-machine installs. |
| 313 scoped_ptr<installer::Version> |
| 314 chrome_version(InstallUtil::GetChromeVersion(!system_install)); |
| 315 if (chrome_version.get()) { |
| 316 LOG(ERROR) << "Already installed version " << chrome_version->GetString() |
| 317 << " conflicts with the current install mode."; |
| 318 status = system_install ? installer_util::USER_LEVEL_INSTALL_EXISTS : |
| 319 installer_util::SYSTEM_LEVEL_INSTALL_EXISTS; |
| 320 int str_id = system_install ? IDS_INSTALL_USER_LEVEL_EXISTS_BASE : |
| 321 IDS_INSTALL_SYSTEM_LEVEL_EXISTS_BASE; |
| 322 InstallUtil::WriteInstallerResult(system_install, status, str_id, NULL); |
| 323 return false; |
| 324 } |
| 325 |
| 326 // If no previous installation of Chrome, make sure installation directory |
| 327 // either does not exist or can be deleted (i.e. is not locked by some other |
| 328 // process). |
| 329 if (installed_version) { |
| 330 std::wstring install_path(installer::GetChromeInstallPath(system_install)); |
| 331 if (file_util::PathExists(install_path) && |
| 332 !file_util::Delete(install_path, true)) { |
| 333 LOG(ERROR) << "Installation directory " << install_path |
| 334 << " exists and can not be deleted."; |
| 335 status = installer_util::INSTALL_DIR_IN_USE; |
| 336 int str_id = IDS_INSTALL_DIR_IN_USE_BASE; |
| 337 InstallUtil::WriteInstallerResult(system_install, status, str_id, NULL); |
| 338 return false; |
| 339 } |
| 340 } |
| 341 |
| 342 return true; |
| 343 } |
| 344 |
| 307 installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, | 345 installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, |
| 308 const installer::Version* installed_version, int options) { | 346 const installer::Version* installed_version, int options) { |
| 347 installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS; |
| 348 if (!CheckPreInstallConditions(installed_version, options, install_status)) |
| 349 return install_status; |
| 350 |
| 309 bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; | 351 bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0; |
| 310 // For install the default location for chrome.packed.7z is in current | 352 // For install the default location for chrome.packed.7z is in current |
| 311 // folder, so get that value first. | 353 // folder, so get that value first. |
| 312 std::wstring archive = file_util::GetDirectoryFromPath(cmd_line.program()); | 354 std::wstring archive = file_util::GetDirectoryFromPath(cmd_line.program()); |
| 313 file_util::AppendToPath(&archive, | 355 file_util::AppendToPath(&archive, |
| 314 std::wstring(installer::kChromeCompressedArchive)); | 356 std::wstring(installer::kChromeCompressedArchive)); |
| 315 // If --install-archive is given, get the user specified value | 357 // If --install-archive is given, get the user specified value |
| 316 if (cmd_line.HasSwitch(installer_util::switches::kInstallArchive)) { | 358 if (cmd_line.HasSwitch(installer_util::switches::kInstallArchive)) { |
| 317 archive = cmd_line.GetSwitchValue( | 359 archive = cmd_line.GetSwitchValue( |
| 318 installer_util::switches::kInstallArchive); | 360 installer_util::switches::kInstallArchive); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 330 IDS_INSTALL_TEMP_DIR_FAILED_BASE, | 372 IDS_INSTALL_TEMP_DIR_FAILED_BASE, |
| 331 NULL); | 373 NULL); |
| 332 return installer_util::TEMP_DIR_FAILED; | 374 return installer_util::TEMP_DIR_FAILED; |
| 333 } | 375 } |
| 334 LOG(INFO) << "created path " << temp_path; | 376 LOG(INFO) << "created path " << temp_path; |
| 335 | 377 |
| 336 std::wstring unpack_path(temp_path); | 378 std::wstring unpack_path(temp_path); |
| 337 file_util::AppendToPath(&unpack_path, | 379 file_util::AppendToPath(&unpack_path, |
| 338 std::wstring(installer::kInstallSourceDir)); | 380 std::wstring(installer::kInstallSourceDir)); |
| 339 bool incremental_install = false; | 381 bool incremental_install = false; |
| 340 installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS; | |
| 341 if (UnPackArchive(archive, system_install, installed_version, | 382 if (UnPackArchive(archive, system_install, installed_version, |
| 342 temp_path, unpack_path, incremental_install)) { | 383 temp_path, unpack_path, incremental_install)) { |
| 343 install_status = installer_util::UNCOMPRESSION_FAILED; | 384 install_status = installer_util::UNCOMPRESSION_FAILED; |
| 344 InstallUtil::WriteInstallerResult(system_install, install_status, | 385 InstallUtil::WriteInstallerResult(system_install, install_status, |
| 345 IDS_INSTALL_UNCOMPRESSION_FAILED_BASE, | 386 IDS_INSTALL_UNCOMPRESSION_FAILED_BASE, |
| 346 NULL); | 387 NULL); |
| 347 } else { | 388 } else { |
| 348 LOG(INFO) << "unpacked to " << unpack_path; | 389 LOG(INFO) << "unpacked to " << unpack_path; |
| 349 std::wstring src_path(unpack_path); | 390 std::wstring src_path(unpack_path); |
| 350 file_util::AppendToPath(&src_path, | 391 file_util::AppendToPath(&src_path, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 594 } |
| 554 | 595 |
| 555 installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS; | 596 installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS; |
| 556 // If --uninstall option is given, uninstall chrome | 597 // If --uninstall option is given, uninstall chrome |
| 557 if (parsed_command_line.HasSwitch(installer_util::switches::kUninstall)) { | 598 if (parsed_command_line.HasSwitch(installer_util::switches::kUninstall)) { |
| 558 install_status = UninstallChrome(parsed_command_line, | 599 install_status = UninstallChrome(parsed_command_line, |
| 559 installed_version.get(), | 600 installed_version.get(), |
| 560 system_install); | 601 system_install); |
| 561 // If --uninstall option is not specified, we assume it is install case. | 602 // If --uninstall option is not specified, we assume it is install case. |
| 562 } else { | 603 } else { |
| 563 // Check to avoid simultaneous per-user and per-machine installs. | |
| 564 scoped_ptr<installer::Version> | |
| 565 chrome_version(InstallUtil::GetChromeVersion(!system_install)); | |
| 566 if (chrome_version.get()) { | |
| 567 LOG(ERROR) << "Already installed version " << chrome_version->GetString() | |
| 568 << " conflicts with the current install mode."; | |
| 569 installer_util::InstallStatus status = system_install ? | |
| 570 installer_util::USER_LEVEL_INSTALL_EXISTS : | |
| 571 installer_util::SYSTEM_LEVEL_INSTALL_EXISTS; | |
| 572 int str_id = system_install ? IDS_INSTALL_USER_LEVEL_EXISTS_BASE : | |
| 573 IDS_INSTALL_SYSTEM_LEVEL_EXISTS_BASE; | |
| 574 InstallUtil::WriteInstallerResult(system_install, status, str_id, NULL); | |
| 575 return status; | |
| 576 } | |
| 577 | |
| 578 install_status = InstallChrome(parsed_command_line, | 604 install_status = InstallChrome(parsed_command_line, |
| 579 installed_version.get(), | 605 installed_version.get(), |
| 580 options); | 606 options); |
| 581 } | 607 } |
| 582 | 608 |
| 583 CoUninitialize(); | 609 CoUninitialize(); |
| 584 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 610 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 585 return dist->GetInstallReturnCode(install_status); | 611 return dist->GetInstallReturnCode(install_status); |
| 586 } | 612 } |
| OLD | NEW |