diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 20:30:45 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-14 20:30:45 +0000 |
commit | fc8edf5c2a5af722cbfe4c1605b5c0de4c17ae9b (patch) | |
tree | c89f45ac847d97edae1ca0fafd391c31e86f2d65 /chrome/installer/setup | |
parent | 8a340e008c9ddf072d1deea25af7c142db7f8b50 (diff) | |
download | chromium_src-fc8edf5c2a5af722cbfe4c1605b5c0de4c17ae9b.zip chromium_src-fc8edf5c2a5af722cbfe4c1605b5c0de4c17ae9b.tar.gz chromium_src-fc8edf5c2a5af722cbfe4c1605b5c0de4c17ae9b.tar.bz2 |
CommandLine: remove wstring-based program() accessor
This was already removed on non-Windows, so this change modifies
the remaining Windows-specific usage. In a few places I converted
use of wstring paths into FilePath, but in general for Windows-specific
code I don't think it's too important to use FilePath everywhere,
because it is equivalent on Windows and the current code already works.
BUG=23581
Review URL: http://codereview.chromium.org/3817001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62637 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/setup')
-rw-r--r-- | chrome/installer/setup/setup_main.cc | 37 | ||||
-rw-r--r-- | chrome/installer/setup/setup_util.cc | 32 | ||||
-rw-r--r-- | chrome/installer/setup/setup_util.h | 10 | ||||
-rw-r--r-- | chrome/installer/setup/setup_util_unittest.cc | 13 | ||||
-rw-r--r-- | chrome/installer/setup/uninstall.cc | 2 |
5 files changed, 51 insertions, 43 deletions
diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc index 114bdd4..9329215 100644 --- a/chrome/installer/setup/setup_main.cc +++ b/chrome/installer/setup/setup_main.cc @@ -87,8 +87,9 @@ DWORD UnPackArchive(const std::wstring& archive, bool system_install, installed_version->GetString()); file_util::AppendToPath(&existing_archive, installer_util::kInstallerDir); file_util::AppendToPath(&existing_archive, installer::kChromeArchive); - if (int i = setup_util::ApplyDiffPatch(existing_archive, unpacked_file, - uncompressed_archive)) { + if (int i = setup_util::ApplyDiffPatch(FilePath(existing_archive), + FilePath(unpacked_file), + FilePath(uncompressed_archive))) { LOG(ERROR) << "Binary patching failed with error " << i; return i; } @@ -227,16 +228,16 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, // For install the default location for chrome.packed.7z is in current // folder, so get that value first. - std::wstring archive = file_util::GetDirectoryFromPath(cmd_line.program()); - file_util::AppendToPath(&archive, - std::wstring(installer::kChromeCompressedArchive)); + FilePath archive = + cmd_line.GetProgram().DirName().Append( + installer::kChromeCompressedArchive); // If --install-archive is given, get the user specified value if (cmd_line.HasSwitch(installer_util::switches::kInstallArchive)) { - archive = cmd_line.GetSwitchValueNative( + archive = cmd_line.GetSwitchValuePath( installer_util::switches::kInstallArchive); } - LOG(INFO) << "Archive found to install Chrome " << archive; + LOG(INFO) << "Archive found to install Chrome " << archive.value(); // Create a temp folder where we will unpack Chrome archive. If it fails, // then we are doomed, so return immediately and no cleanup is required. @@ -256,7 +257,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, file_util::AppendToPath(&unpack_path, std::wstring(installer::kInstallSourceDir)); bool incremental_install = false; - if (UnPackArchive(archive, system_level, installed_version, + if (UnPackArchive(archive.value(), system_level, installed_version, temp_path.ToWStringHack(), unpack_path, incremental_install)) { install_status = installer_util::UNCOMPRESSION_FAILED; @@ -269,7 +270,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, file_util::AppendToPath(&src_path, std::wstring(installer::kInstallSourceChromeDir)); scoped_ptr<installer::Version> - installer_version(setup_util::GetVersionFromDir(src_path)); + installer_version(setup_util::GetVersionFromDir(FilePath(src_path))); if (!installer_version.get()) { LOG(ERROR) << "Did not find any valid version in installer."; install_status = installer_util::INVALID_ARCHIVE; @@ -287,12 +288,12 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, } else { // We want to keep uncompressed archive (chrome.7z) that we get after // uncompressing and binary patching. Get the location for this file. - std::wstring archive_to_copy(temp_path.ToWStringHack()); - file_util::AppendToPath(&archive_to_copy, installer::kChromeArchive); + FilePath archive_to_copy = temp_path.Append(installer::kChromeArchive); std::wstring prefs_source_path = cmd_line.GetSwitchValueNative( installer_util::switches::kInstallerData); install_status = installer::InstallOrUpdateChrome( - cmd_line.program(), archive_to_copy, temp_path.ToWStringHack(), + cmd_line.GetProgram().value(), archive_to_copy.value(), + temp_path.ToWStringHack(), prefs_source_path, prefs, *installer_version, installed_version); int install_msg_base = IDS_INSTALL_FAILED_BASE; @@ -398,7 +399,8 @@ installer_util::InstallStatus UninstallChrome(const CommandLine& cmd_line, bool remove_all = !cmd_line.HasSwitch( installer_util::switches::kDoNotRemoveSharedItems); - return installer_setup::UninstallChrome(cmd_line.program(), system_install, + return installer_setup::UninstallChrome(cmd_line.GetProgram().value(), + system_install, remove_all, force, cmd_line, cmd_params); } @@ -454,10 +456,11 @@ bool HandleNonInstallCmdLineOptions(const CommandLine& cmd_line, std::wstring uncompressed_patch; if (LzmaUtil::UnPackArchive(setup_patch, temp_path.ToWStringHack(), &uncompressed_patch) == NO_ERROR) { - std::wstring old_setup_exe = cmd_line.program(); - std::wstring new_setup_exe = cmd_line.GetSwitchValueNative( + FilePath old_setup_exe = cmd_line.GetProgram(); + FilePath new_setup_exe = cmd_line.GetSwitchValuePath( installer_util::switches::kNewSetupExe); - if (!setup_util::ApplyDiffPatch(old_setup_exe, uncompressed_patch, + if (!setup_util::ApplyDiffPatch(old_setup_exe, + FilePath(uncompressed_patch), new_setup_exe)) status = installer_util::NEW_VERSION_UPDATED; } @@ -676,7 +679,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, if (system_install && !IsUserAnAdmin()) { if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA && !parsed_command_line.HasSwitch(installer_util::switches::kRunAsAdmin)) { - std::wstring exe = parsed_command_line.program(); + std::wstring exe = parsed_command_line.GetProgram().value(); std::wstring params(command_line); // Append --run-as-admin flag to let the new instance of setup.exe know // that we already tried to launch ourselves as admin. diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc index 2136616..84f6c2b 100644 --- a/chrome/installer/setup/setup_util.cc +++ b/chrome/installer/setup/setup_util.cc @@ -13,34 +13,38 @@ #include "courgette/courgette.h" #include "third_party/bspatch/mbspatch.h" -int setup_util::ApplyDiffPatch(const std::wstring& src, - const std::wstring& patch, - const std::wstring& dest) { - LOG(INFO) << "Applying patch " << patch - << " to file " << src - << " and generating file " << dest; +int setup_util::ApplyDiffPatch(const FilePath& src, + const FilePath& patch, + const FilePath& dest) { + LOG(INFO) << "Applying patch " << patch.value() + << " to file " << src.value() + << " and generating file " << dest.value(); // Try Courgette first. Courgette checks the patch file first and fails // quickly if the patch file does not have a valid Courgette header. courgette::Status patch_status = - courgette::ApplyEnsemblePatch(src.c_str(), patch.c_str(), dest.c_str()); + courgette::ApplyEnsemblePatch(src.value().c_str(), + patch.value().c_str(), + dest.value().c_str()); if (patch_status == courgette::C_OK) { return 0; } else { - LOG(INFO) << "Failed to apply patch " << patch << " using courgette."; + LOG(INFO) << "Failed to apply patch " << patch.value() + << " using courgette."; } - return ApplyBinaryPatch(src.c_str(), patch.c_str(), dest.c_str()); + return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), + dest.value().c_str()); } installer::Version* setup_util::GetVersionFromDir( - const std::wstring& chrome_path) { - LOG(INFO) << "Looking for Chrome version folder under " << chrome_path; - std::wstring root_path(chrome_path); - file_util::AppendToPath(&root_path, L"*"); + const FilePath& chrome_path) { + LOG(INFO) << "Looking for Chrome version folder under " + << chrome_path.value(); + FilePath root_path = chrome_path.Append(L"*"); WIN32_FIND_DATA find_data; - HANDLE file_handle = FindFirstFile(root_path.c_str(), &find_data); + HANDLE file_handle = FindFirstFile(root_path.value().c_str(), &find_data); BOOL ret = TRUE; installer::Version *version = NULL; // Here we are assuming that the installer we have is really valid so there diff --git a/chrome/installer/setup/setup_util.h b/chrome/installer/setup/setup_util.h index 39118cc..61aed71 100644 --- a/chrome/installer/setup/setup_util.h +++ b/chrome/installer/setup/setup_util.h @@ -10,18 +10,20 @@ #include "chrome/installer/util/version.h" +class FilePath; + namespace setup_util { // Apply a diff patch to source file. First tries to apply it using courgette // since it checks for courgette header and fails quickly. If that fails // tries to apply the patch using regular bsdiff. Returns status code. - int ApplyDiffPatch(const std::wstring& src, - const std::wstring& patch, - const std::wstring& dest); + int ApplyDiffPatch(const FilePath& src, + const FilePath& patch, + const FilePath& dest); // Find the version of Chrome from an install source directory. // Chrome_path should contain a version folder. // Returns the first version found or NULL if no version is found. - installer::Version* GetVersionFromDir(const std::wstring& chrome_path); + installer::Version* GetVersionFromDir(const FilePath& chrome_path); } // namespace setup_util #endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ diff --git a/chrome/installer/setup/setup_util_unittest.cc b/chrome/installer/setup/setup_util_unittest.cc index fc0ac9e..2543d01 100644 --- a/chrome/installer/setup/setup_util_unittest.cc +++ b/chrome/installer/setup/setup_util_unittest.cc @@ -55,12 +55,11 @@ TEST_F(SetupUtilTest, ApplyDiffPatchTest) { FilePath src = data_dir_.AppendASCII("archive1.7z"); FilePath patch = data_dir_.AppendASCII("archive.diff"); FilePath dest = work_dir.AppendASCII("archive2.7z"); - EXPECT_EQ(setup_util::ApplyDiffPatch(src.value(), patch.value(), - dest.value()), 0); + EXPECT_EQ(setup_util::ApplyDiffPatch(src, patch, dest), 0); FilePath base = data_dir_.AppendASCII("archive2.7z"); EXPECT_TRUE(file_util::ContentsEqual(dest, base)); - EXPECT_EQ(setup_util::ApplyDiffPatch(L"", L"", L""), 6); + EXPECT_EQ(setup_util::ApplyDiffPatch(FilePath(), FilePath(), FilePath()), 6); } // Test that we are parsing Chrome version correctly. @@ -70,21 +69,21 @@ TEST_F(SetupUtilTest, GetVersionFromDirTest) { file_util::CreateDirectory(chrome_dir); ASSERT_TRUE(file_util::PathExists(chrome_dir)); scoped_ptr<installer::Version> version( - setup_util::GetVersionFromDir(test_dir_.value())); + setup_util::GetVersionFromDir(test_dir_)); ASSERT_TRUE(version->GetString() == L"1.0.0.0"); file_util::Delete(chrome_dir, true); ASSERT_FALSE(file_util::PathExists(chrome_dir)); - ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_.value()) == NULL); + ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_) == NULL); chrome_dir = test_dir_.AppendASCII("ABC"); file_util::CreateDirectory(chrome_dir); ASSERT_TRUE(file_util::PathExists(chrome_dir)); - ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_.value()) == NULL); + ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_) == NULL); chrome_dir = test_dir_.AppendASCII("2.3.4.5"); file_util::CreateDirectory(chrome_dir); ASSERT_TRUE(file_util::PathExists(chrome_dir)); - version.reset(setup_util::GetVersionFromDir(test_dir_.value())); + version.reset(setup_util::GetVersionFromDir(test_dir_)); ASSERT_TRUE(version->GetString() == L"2.3.4.5"); } diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index f4fe556..4822aa1 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -470,7 +470,7 @@ installer_util::InstallStatus installer_setup::UninstallChrome( !::IsUserAnAdmin() && (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) && !cmd_line.HasSwitch(installer_util::switches::kRunAsAdmin)) { - std::wstring exe = cmd_line.program(); + std::wstring exe = cmd_line.GetProgram().value(); std::wstring params(cmd_params); // Append --run-as-admin flag to let the new instance of setup.exe know // that we already tried to launch ourselves as admin. |