| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // The file contains the implementation of the mini_installer re-versioner. | 5 // The file contains the implementation of the mini_installer re-versioner. |
| 6 // The main function (GenerateNextVersion) does the following in a temp dir: | 6 // The main function (GenerateNextVersion) does the following in a temp dir: |
| 7 // - Extracts and unpacks setup.exe and the Chrome-bin folder from | 7 // - Extracts and unpacks setup.exe and the Chrome-bin folder from |
| 8 // mini_installer.exe. | 8 // mini_installer.exe. |
| 9 // - Inspects setup.exe to determine the current version. | 9 // - Inspects setup.exe to determine the current version. |
| 10 // - Runs through all .dll and .exe files: | 10 // - Runs through all .dll and .exe files: |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 }; // class ScopedTempDirectory | 105 }; // class ScopedTempDirectory |
| 106 | 106 |
| 107 // A helper class for manipulating a Chrome product version. | 107 // A helper class for manipulating a Chrome product version. |
| 108 class ChromeVersion { | 108 class ChromeVersion { |
| 109 public: | 109 public: |
| 110 static ChromeVersion FromHighLow(DWORD high, DWORD low) { | 110 static ChromeVersion FromHighLow(DWORD high, DWORD low) { |
| 111 return ChromeVersion(static_cast<ULONGLONG>(high) << 32 | | 111 return ChromeVersion(static_cast<ULONGLONG>(high) << 32 | |
| 112 static_cast<ULONGLONG>(low)); | 112 static_cast<ULONGLONG>(low)); |
| 113 } | 113 } |
| 114 static ChromeVersion FromString(const std::string& version_string) { | 114 static ChromeVersion FromString(const std::string& version_string) { |
| 115 Version version(version_string); | 115 base::Version version(version_string); |
| 116 DCHECK(version.IsValid()); | 116 DCHECK(version.IsValid()); |
| 117 const std::vector<uint32_t>& c(version.components()); | 117 const std::vector<uint32_t>& c(version.components()); |
| 118 return ChromeVersion(static_cast<ULONGLONG>(c[0]) << 48 | | 118 return ChromeVersion(static_cast<ULONGLONG>(c[0]) << 48 | |
| 119 static_cast<ULONGLONG>(c[1]) << 32 | | 119 static_cast<ULONGLONG>(c[1]) << 32 | |
| 120 static_cast<ULONGLONG>(c[2]) << 16 | | 120 static_cast<ULONGLONG>(c[2]) << 16 | |
| 121 static_cast<ULONGLONG>(c[3])); | 121 static_cast<ULONGLONG>(c[3])); |
| 122 } | 122 } |
| 123 | 123 |
| 124 ChromeVersion() { } | 124 ChromeVersion() { } |
| 125 explicit ChromeVersion(ULONGLONG value) : version_(value) { } | 125 explicit ChromeVersion(ULONGLONG value) : version_(value) { } |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 return false; | 733 return false; |
| 734 } | 734 } |
| 735 ctx.current_version_str = ctx.current_version.ToString(); | 735 ctx.current_version_str = ctx.current_version.ToString(); |
| 736 | 736 |
| 737 if (!IncrementNewVersion(direction, &ctx)) { | 737 if (!IncrementNewVersion(direction, &ctx)) { |
| 738 LOG(DFATAL) << "Failed to increment version from \"" | 738 LOG(DFATAL) << "Failed to increment version from \"" |
| 739 << original_file.value() << "\""; | 739 << original_file.value() << "\""; |
| 740 return false; | 740 return false; |
| 741 } | 741 } |
| 742 | 742 |
| 743 Version new_version(base::UTF16ToASCII(ctx.new_version_str)); | 743 base::Version new_version(base::UTF16ToASCII(ctx.new_version_str)); |
| 744 GenerateSpecificPEFileVersion(original_file, target_file, new_version); | 744 GenerateSpecificPEFileVersion(original_file, target_file, new_version); |
| 745 | 745 |
| 746 return true; | 746 return true; |
| 747 } | 747 } |
| 748 | 748 |
| 749 bool GenerateSpecificPEFileVersion(const base::FilePath& original_file, | 749 bool GenerateSpecificPEFileVersion(const base::FilePath& original_file, |
| 750 const base::FilePath& target_file, | 750 const base::FilePath& target_file, |
| 751 const Version& version) { | 751 const base::Version& version) { |
| 752 // First copy original_file to target_file. | 752 // First copy original_file to target_file. |
| 753 if (!base::CopyFile(original_file, target_file)) { | 753 if (!base::CopyFile(original_file, target_file)) { |
| 754 LOG(DFATAL) << "Failed copying \"" << original_file.value() | 754 LOG(DFATAL) << "Failed copying \"" << original_file.value() |
| 755 << "\" to \"" << target_file.value() << "\""; | 755 << "\" to \"" << target_file.value() << "\""; |
| 756 return false; | 756 return false; |
| 757 } | 757 } |
| 758 | 758 |
| 759 VisitResourceContext ctx; | 759 VisitResourceContext ctx; |
| 760 if (!GetFileVersion(target_file, &ctx.current_version)) { | 760 if (!GetFileVersion(target_file, &ctx.current_version)) { |
| 761 LOG(DFATAL) << "Failed reading version from \"" << target_file.value() | 761 LOG(DFATAL) << "Failed reading version from \"" << target_file.value() |
| 762 << "\""; | 762 << "\""; |
| 763 return false; | 763 return false; |
| 764 } | 764 } |
| 765 ctx.current_version_str = ctx.current_version.ToString(); | 765 ctx.current_version_str = ctx.current_version.ToString(); |
| 766 ctx.new_version = ChromeVersion::FromString(version.GetString()); | 766 ctx.new_version = ChromeVersion::FromString(version.GetString()); |
| 767 ctx.new_version_str = ctx.new_version.ToString(); | 767 ctx.new_version_str = ctx.new_version.ToString(); |
| 768 | 768 |
| 769 return UpdateVersionIfMatch(target_file, &ctx); | 769 return UpdateVersionIfMatch(target_file, &ctx); |
| 770 } | 770 } |
| 771 | 771 |
| 772 } // namespace upgrade_test | 772 } // namespace upgrade_test |
| OLD | NEW |