| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
| 6 | 6 |
| 7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/installer/util/master_preferences.h" | 11 #include "chrome/installer/util/master_preferences.h" |
| 12 #include "chrome/installer/util/util_constants.h" | 12 #include "chrome/installer/util/util_constants.h" |
| 13 #include "courgette/courgette.h" | 13 #include "courgette/courgette.h" |
| 14 #include "third_party/bspatch/mbspatch.h" | 14 #include "third_party/bspatch/mbspatch.h" |
| 15 | 15 |
| 16 int setup_util::ApplyDiffPatch(const std::wstring& src, | 16 int setup_util::ApplyDiffPatch(const FilePath& src, |
| 17 const std::wstring& patch, | 17 const FilePath& patch, |
| 18 const std::wstring& dest) { | 18 const FilePath& dest) { |
| 19 LOG(INFO) << "Applying patch " << patch | 19 LOG(INFO) << "Applying patch " << patch.value() |
| 20 << " to file " << src | 20 << " to file " << src.value() |
| 21 << " and generating file " << dest; | 21 << " and generating file " << dest.value(); |
| 22 | 22 |
| 23 // Try Courgette first. Courgette checks the patch file first and fails | 23 // Try Courgette first. Courgette checks the patch file first and fails |
| 24 // quickly if the patch file does not have a valid Courgette header. | 24 // quickly if the patch file does not have a valid Courgette header. |
| 25 courgette::Status patch_status = | 25 courgette::Status patch_status = |
| 26 courgette::ApplyEnsemblePatch(src.c_str(), patch.c_str(), dest.c_str()); | 26 courgette::ApplyEnsemblePatch(src.value().c_str(), |
| 27 patch.value().c_str(), |
| 28 dest.value().c_str()); |
| 27 if (patch_status == courgette::C_OK) { | 29 if (patch_status == courgette::C_OK) { |
| 28 return 0; | 30 return 0; |
| 29 } else { | 31 } else { |
| 30 LOG(INFO) << "Failed to apply patch " << patch << " using courgette."; | 32 LOG(INFO) << "Failed to apply patch " << patch.value() |
| 33 << " using courgette."; |
| 31 } | 34 } |
| 32 | 35 |
| 33 return ApplyBinaryPatch(src.c_str(), patch.c_str(), dest.c_str()); | 36 return ApplyBinaryPatch(src.value().c_str(), patch.value().c_str(), |
| 37 dest.value().c_str()); |
| 34 } | 38 } |
| 35 | 39 |
| 36 installer::Version* setup_util::GetVersionFromDir( | 40 installer::Version* setup_util::GetVersionFromDir( |
| 37 const std::wstring& chrome_path) { | 41 const FilePath& chrome_path) { |
| 38 LOG(INFO) << "Looking for Chrome version folder under " << chrome_path; | 42 LOG(INFO) << "Looking for Chrome version folder under " |
| 39 std::wstring root_path(chrome_path); | 43 << chrome_path.value(); |
| 40 file_util::AppendToPath(&root_path, L"*"); | 44 FilePath root_path = chrome_path.Append(L"*"); |
| 41 | 45 |
| 42 WIN32_FIND_DATA find_data; | 46 WIN32_FIND_DATA find_data; |
| 43 HANDLE file_handle = FindFirstFile(root_path.c_str(), &find_data); | 47 HANDLE file_handle = FindFirstFile(root_path.value().c_str(), &find_data); |
| 44 BOOL ret = TRUE; | 48 BOOL ret = TRUE; |
| 45 installer::Version *version = NULL; | 49 installer::Version *version = NULL; |
| 46 // Here we are assuming that the installer we have is really valid so there | 50 // Here we are assuming that the installer we have is really valid so there |
| 47 // can not be two version directories. We exit as soon as we find a valid | 51 // can not be two version directories. We exit as soon as we find a valid |
| 48 // version directory. | 52 // version directory. |
| 49 while (ret) { | 53 while (ret) { |
| 50 if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | 54 if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 51 LOG(INFO) << "directory found: " << find_data.cFileName; | 55 LOG(INFO) << "directory found: " << find_data.cFileName; |
| 52 version = installer::Version::GetVersionFromString(find_data.cFileName); | 56 version = installer::Version::GetVersionFromString(find_data.cFileName); |
| 53 if (version) break; | 57 if (version) break; |
| 54 } | 58 } |
| 55 ret = FindNextFile(file_handle, &find_data); | 59 ret = FindNextFile(file_handle, &find_data); |
| 56 } | 60 } |
| 57 FindClose(file_handle); | 61 FindClose(file_handle); |
| 58 | 62 |
| 59 return version; | 63 return version; |
| 60 } | 64 } |
| OLD | NEW |