summaryrefslogtreecommitdiffstats
path: root/chrome/installer/setup/main.cc
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 22:24:26 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-27 22:24:26 +0000
commitef038f229a742a7408ecaec1f56ea61e3bc38409 (patch)
treed6f638bbcc751c1cdb8eb8957c8d3d8677866e8f /chrome/installer/setup/main.cc
parent9aed47ca88d66fd3edd77f6a4ac0c4f4f953cecc (diff)
downloadchromium_src-ef038f229a742a7408ecaec1f56ea61e3bc38409.zip
chromium_src-ef038f229a742a7408ecaec1f56ea61e3bc38409.tar.gz
chromium_src-ef038f229a742a7408ecaec1f56ea61e3bc38409.tar.bz2
Before installing Chrome check that the installation directory doesn't exist (or can be deleted).
BUG=7176 Review URL: http://codereview.chromium.org/27258 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/setup/main.cc')
-rw-r--r--chrome/installer/setup/main.cc58
1 files changed, 42 insertions, 16 deletions
diff --git a/chrome/installer/setup/main.cc b/chrome/installer/setup/main.cc
index 0fe810e..672b1a1 100644
--- a/chrome/installer/setup/main.cc
+++ b/chrome/installer/setup/main.cc
@@ -304,8 +304,50 @@ void UpdateChromeOpenCmd(bool system_install) {
ReplaceRegistryValue(reg_key[i], old_open_cmd, new_open_cmd);
}
+bool CheckPreInstallConditions(const installer::Version* installed_version,
+ int options,
+ installer_util::InstallStatus& status) {
+ bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0;
+
+ // Check to avoid simultaneous per-user and per-machine installs.
+ scoped_ptr<installer::Version>
+ chrome_version(InstallUtil::GetChromeVersion(!system_install));
+ if (chrome_version.get()) {
+ LOG(ERROR) << "Already installed version " << chrome_version->GetString()
+ << " conflicts with the current install mode.";
+ status = system_install ? installer_util::USER_LEVEL_INSTALL_EXISTS :
+ installer_util::SYSTEM_LEVEL_INSTALL_EXISTS;
+ int str_id = system_install ? IDS_INSTALL_USER_LEVEL_EXISTS_BASE :
+ IDS_INSTALL_SYSTEM_LEVEL_EXISTS_BASE;
+ InstallUtil::WriteInstallerResult(system_install, status, str_id, NULL);
+ return false;
+ }
+
+ // If no previous installation of Chrome, make sure installation directory
+ // either does not exist or can be deleted (i.e. is not locked by some other
+ // process).
+ if (installed_version) {
+ std::wstring install_path(installer::GetChromeInstallPath(system_install));
+ if (file_util::PathExists(install_path) &&
+ !file_util::Delete(install_path, true)) {
+ LOG(ERROR) << "Installation directory " << install_path
+ << " exists and can not be deleted.";
+ status = installer_util::INSTALL_DIR_IN_USE;
+ int str_id = IDS_INSTALL_DIR_IN_USE_BASE;
+ InstallUtil::WriteInstallerResult(system_install, status, str_id, NULL);
+ return false;
+ }
+ }
+
+ return true;
+}
+
installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line,
const installer::Version* installed_version, int options) {
+ installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS;
+ if (!CheckPreInstallConditions(installed_version, options, install_status))
+ return install_status;
+
bool system_install = (options & installer_util::SYSTEM_LEVEL) != 0;
// For install the default location for chrome.packed.7z is in current
// folder, so get that value first.
@@ -337,7 +379,6 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line,
file_util::AppendToPath(&unpack_path,
std::wstring(installer::kInstallSourceDir));
bool incremental_install = false;
- installer_util::InstallStatus install_status = installer_util::UNKNOWN_STATUS;
if (UnPackArchive(archive, system_install, installed_version,
temp_path, unpack_path, incremental_install)) {
install_status = installer_util::UNCOMPRESSION_FAILED;
@@ -560,21 +601,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
system_install);
// If --uninstall option is not specified, we assume it is install case.
} else {
- // Check to avoid simultaneous per-user and per-machine installs.
- scoped_ptr<installer::Version>
- chrome_version(InstallUtil::GetChromeVersion(!system_install));
- if (chrome_version.get()) {
- LOG(ERROR) << "Already installed version " << chrome_version->GetString()
- << " conflicts with the current install mode.";
- installer_util::InstallStatus status = system_install ?
- installer_util::USER_LEVEL_INSTALL_EXISTS :
- installer_util::SYSTEM_LEVEL_INSTALL_EXISTS;
- int str_id = system_install ? IDS_INSTALL_USER_LEVEL_EXISTS_BASE :
- IDS_INSTALL_SYSTEM_LEVEL_EXISTS_BASE;
- InstallUtil::WriteInstallerResult(system_install, status, str_id, NULL);
- return status;
- }
-
install_status = InstallChrome(parsed_command_line,
installed_version.get(),
options);