// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // This file declares util functions for setup project. #include "chrome/installer/setup/setup_util.h" #include "base/file_util.h" #include "base/logging.h" #include "base/string_util.h" #include "chrome/installer/util/util_constants.h" #include "courgette/courgette.h" #include "third_party/bspatch/mbspatch.h" int installer::ApplyDiffPatch(const FilePath& src, const FilePath& patch, const FilePath& dest) { VLOG(1) << "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.value().c_str(), patch.value().c_str(), dest.value().c_str()); if (patch_status == courgette::C_OK) return 0; VLOG(1) << "Failed to apply patch " << patch.value() << " using courgette."; return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), dest.value().c_str()); } Version* installer::GetMaxVersionFromArchiveDir(const FilePath& chrome_path) { VLOG(1) << "Looking for Chrome version folder under " << chrome_path.value(); Version* version = NULL; file_util::FileEnumerator version_enum(chrome_path, false, file_util::FileEnumerator::DIRECTORIES); // TODO(tommi): The version directory really should match the version of // setup.exe. To begin with, we should at least DCHECK that that's true. scoped_ptr max_version(Version::GetVersionFromString("0.0.0.0")); bool version_found = false; while (!version_enum.Next().empty()) { file_util::FileEnumerator::FindInfo find_data = {0}; version_enum.GetFindInfo(&find_data); VLOG(1) << "directory found: " << find_data.cFileName; scoped_ptr found_version( Version::GetVersionFromString(WideToASCII(find_data.cFileName))); if (found_version.get() != NULL && found_version->CompareTo(*max_version.get()) > 0) { max_version.reset(found_version.release()); version_found = true; } } return (version_found ? max_version.release() : NULL); }