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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "base/version.h" | 49 #include "base/version.h" |
50 #include "base/win/pe_image.h" | 50 #include "base/win/pe_image.h" |
51 #include "base/win/scoped_handle.h" | 51 #include "base/win/scoped_handle.h" |
52 #include "chrome/installer/test/pe_image_resources.h" | 52 #include "chrome/installer/test/pe_image_resources.h" |
53 #include "chrome/installer/test/resource_loader.h" | 53 #include "chrome/installer/test/resource_loader.h" |
54 #include "chrome/installer/test/resource_updater.h" | 54 #include "chrome/installer/test/resource_updater.h" |
55 #include "chrome/installer/util/lzma_util.h" | 55 #include "chrome/installer/util/lzma_util.h" |
56 | 56 |
57 namespace { | 57 namespace { |
58 | 58 |
59 const wchar_t k7zaExe[] = L"7za.exe"; | 59 const base::char16 k7zaExe[] = L"7za.exe"; |
60 const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable"; | 60 const base::char16 k7zaPathRelative[] = |
61 const wchar_t kB7[] = L"B7"; | 61 L"..\\..\\third_party\\lzma_sdk\\Executable"; |
62 const wchar_t kBl[] = L"BL"; | 62 const base::char16 kB7[] = L"B7"; |
63 const wchar_t kChromeBin[] = L"Chrome-bin"; | 63 const base::char16 kBl[] = L"BL"; |
64 const wchar_t kChromePacked7z[] = L"CHROME.PACKED.7Z"; | 64 const base::char16 kChromeBin[] = L"Chrome-bin"; |
65 const wchar_t kChrome7z[] = L"CHROME.7Z"; | 65 const base::char16 kChromePacked7z[] = L"CHROME.PACKED.7Z"; |
66 const wchar_t kExe[] = L"exe"; | 66 const base::char16 kChrome7z[] = L"CHROME.7Z"; |
67 const wchar_t kExpandExe[] = L"expand.exe"; | 67 const base::char16 kExe[] = L"exe"; |
68 const wchar_t kExtDll[] = L".dll"; | 68 const base::char16 kExpandExe[] = L"expand.exe"; |
69 const wchar_t kExtExe[] = L".exe"; | 69 const base::char16 kExtDll[] = L".dll"; |
70 const wchar_t kMakeCab[] = L"makecab.exe"; | 70 const base::char16 kExtExe[] = L".exe"; |
71 const wchar_t kSetupEx_[] = L"setup.ex_"; | 71 const base::char16 kMakeCab[] = L"makecab.exe"; |
72 const wchar_t kSetupExe[] = L"setup.exe"; | 72 const base::char16 kSetupEx_[] = L"setup.ex_"; |
| 73 const base::char16 kSetupExe[] = L"setup.exe"; |
73 const char kSwitch7zaPath[] = "7za_path"; | 74 const char kSwitch7zaPath[] = "7za_path"; |
74 const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp"; | 75 const base::char16 kTempDirPrefix[] = L"mini_installer_test_temp"; |
75 | 76 |
76 // A helper class for creating and cleaning a temporary directory. A temporary | 77 // A helper class for creating and cleaning a temporary directory. A temporary |
77 // directory is created in Initialize and destroyed (along with all of its | 78 // directory is created in Initialize and destroyed (along with all of its |
78 // contents) when the guard instance is destroyed. | 79 // contents) when the guard instance is destroyed. |
79 class ScopedTempDirectory { | 80 class ScopedTempDirectory { |
80 public: | 81 public: |
81 ScopedTempDirectory() { } | 82 ScopedTempDirectory() { } |
82 ~ScopedTempDirectory() { | 83 ~ScopedTempDirectory() { |
83 if (!directory_.empty() && !base::DeleteFile(directory_, true)) { | 84 if (!directory_.empty() && !base::DeleteFile(directory_, true)) { |
84 LOG(DFATAL) << "Failed deleting temporary directory \"" | 85 LOG(DFATAL) << "Failed deleting temporary directory \"" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 ChromeVersion() { } | 125 ChromeVersion() { } |
125 explicit ChromeVersion(ULONGLONG value) : version_(value) { } | 126 explicit ChromeVersion(ULONGLONG value) : version_(value) { } |
126 WORD major() const { return static_cast<WORD>(version_ >> 48); } | 127 WORD major() const { return static_cast<WORD>(version_ >> 48); } |
127 WORD minor() const { return static_cast<WORD>(version_ >> 32); } | 128 WORD minor() const { return static_cast<WORD>(version_ >> 32); } |
128 WORD build() const { return static_cast<WORD>(version_ >> 16); } | 129 WORD build() const { return static_cast<WORD>(version_ >> 16); } |
129 WORD patch() const { return static_cast<WORD>(version_); } | 130 WORD patch() const { return static_cast<WORD>(version_); } |
130 DWORD high() const { return static_cast<DWORD>(version_ >> 32); } | 131 DWORD high() const { return static_cast<DWORD>(version_ >> 32); } |
131 DWORD low() const { return static_cast<DWORD>(version_); } | 132 DWORD low() const { return static_cast<DWORD>(version_); } |
132 ULONGLONG value() const { return version_; } | 133 ULONGLONG value() const { return version_; } |
133 void set_value(ULONGLONG value) { version_ = value; } | 134 void set_value(ULONGLONG value) { version_ = value; } |
134 std::wstring ToString() const; | 135 base::string16 ToString() const; |
135 std::string ToASCII() const; | 136 std::string ToASCII() const; |
136 | 137 |
137 private: | 138 private: |
138 ULONGLONG version_; | 139 ULONGLONG version_; |
139 }; // class ChromeVersion | 140 }; // class ChromeVersion |
140 | 141 |
141 std::wstring ChromeVersion::ToString() const { | 142 base::string16 ChromeVersion::ToString() const { |
142 wchar_t buffer[24]; | 143 base::char16 buffer[24]; |
143 int string_len = | 144 int string_len = |
144 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", | 145 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", |
145 major(), minor(), build(), patch()); | 146 major(), minor(), build(), patch()); |
146 DCHECK_NE(-1, string_len); | 147 DCHECK_NE(-1, string_len); |
147 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); | 148 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); |
148 return std::wstring(&buffer[0], string_len); | 149 return base::string16(&buffer[0], string_len); |
149 } | 150 } |
150 | 151 |
151 std::string ChromeVersion::ToASCII() const { | 152 std::string ChromeVersion::ToASCII() const { |
152 char buffer[24]; | 153 char buffer[24]; |
153 int string_len = sprintf_s(&buffer[0], arraysize(buffer), "%hu.%hu.%hu.%hu", | 154 int string_len = sprintf_s(&buffer[0], arraysize(buffer), "%hu.%hu.%hu.%hu", |
154 major(), minor(), build(), patch()); | 155 major(), minor(), build(), patch()); |
155 DCHECK_NE(-1, string_len); | 156 DCHECK_NE(-1, string_len); |
156 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); | 157 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); |
157 return std::string(&buffer[0], string_len); | 158 return std::string(&buffer[0], string_len); |
158 } | 159 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 211 } |
211 } else { | 212 } else { |
212 PLOG(DFATAL) << "file.GetInfo failed"; | 213 PLOG(DFATAL) << "file.GetInfo failed"; |
213 } | 214 } |
214 file_ = std::move(file); | 215 file_ = std::move(file); |
215 return result; | 216 return result; |
216 } | 217 } |
217 | 218 |
218 // Calls CreateProcess with good default parameters and waits for the process | 219 // Calls CreateProcess with good default parameters and waits for the process |
219 // to terminate returning the process exit code. | 220 // to terminate returning the process exit code. |
220 bool RunProcessAndWait(const wchar_t* exe_path, const std::wstring& cmdline, | 221 bool RunProcessAndWait(const base::char16* exe_path, |
| 222 const base::string16& cmdline, |
221 int* exit_code) { | 223 int* exit_code) { |
222 bool result = true; | 224 bool result = true; |
223 base::LaunchOptions options; | 225 base::LaunchOptions options; |
224 options.wait = true; | 226 options.wait = true; |
225 options.start_hidden = true; | 227 options.start_hidden = true; |
226 base::Process process = base::LaunchProcess(cmdline, options); | 228 base::Process process = base::LaunchProcess(cmdline, options); |
227 if (process.IsValid()) { | 229 if (process.IsValid()) { |
228 if (exit_code) { | 230 if (exit_code) { |
229 if (!GetExitCodeProcess(process.Handle(), | 231 if (!GetExitCodeProcess(process.Handle(), |
230 reinterpret_cast<DWORD*>(exit_code))) { | 232 reinterpret_cast<DWORD*>(exit_code))) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 309 |
308 if (replacements_made != NULL) | 310 if (replacements_made != NULL) |
309 *replacements_made = changed; | 311 *replacements_made = changed; |
310 | 312 |
311 return result; | 313 return result; |
312 } | 314 } |
313 | 315 |
314 // A context structure in support of our EnumResource_Fn callback. | 316 // A context structure in support of our EnumResource_Fn callback. |
315 struct VisitResourceContext { | 317 struct VisitResourceContext { |
316 ChromeVersion current_version; | 318 ChromeVersion current_version; |
317 std::wstring current_version_str; | 319 base::string16 current_version_str; |
318 ChromeVersion new_version; | 320 ChromeVersion new_version; |
319 std::wstring new_version_str; | 321 base::string16 new_version_str; |
320 }; // struct VisitResourceContext | 322 }; // struct VisitResourceContext |
321 | 323 |
322 // Replaces the old version with the new in a resource. A first pass is made to | 324 // Replaces the old version with the new in a resource. A first pass is made to |
323 // replace the string form (e.g., "9.0.584.0"). If any replacements are made, a | 325 // replace the string form (e.g., "9.0.584.0"). If any replacements are made, a |
324 // second pass is made to replace the binary form (e.g., 0x0000024800000009). | 326 // second pass is made to replace the binary form (e.g., 0x0000024800000009). |
325 // A final pass is made to replace the ASCII string form. | 327 // A final pass is made to replace the ASCII string form. |
326 void VisitResource(const upgrade_test::EntryPath& path, | 328 void VisitResource(const upgrade_test::EntryPath& path, |
327 uint8_t* data, | 329 uint8_t* data, |
328 DWORD size, | 330 DWORD size, |
329 DWORD code_page, | 331 DWORD code_page, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 | 452 |
451 return true; | 453 return true; |
452 } | 454 } |
453 | 455 |
454 // Raises or lowers the version of all .exe and .dll files in |work_dir| as well | 456 // Raises or lowers the version of all .exe and .dll files in |work_dir| as well |
455 // as the |work-dir|\Chrome-bin\w.x.y.z directory. |original_version| and | 457 // as the |work-dir|\Chrome-bin\w.x.y.z directory. |original_version| and |
456 // |new_version|, when non-null, are given the original and new version numbers | 458 // |new_version|, when non-null, are given the original and new version numbers |
457 // on success. | 459 // on success. |
458 bool ApplyAlternateVersion(const base::FilePath& work_dir, | 460 bool ApplyAlternateVersion(const base::FilePath& work_dir, |
459 upgrade_test::Direction direction, | 461 upgrade_test::Direction direction, |
460 std::wstring* original_version, | 462 base::string16* original_version, |
461 std::wstring* new_version) { | 463 base::string16* new_version) { |
462 VisitResourceContext ctx; | 464 VisitResourceContext ctx; |
463 if (!GetSetupExeVersion(work_dir, &ctx.current_version)) | 465 if (!GetSetupExeVersion(work_dir, &ctx.current_version)) |
464 return false; | 466 return false; |
465 ctx.current_version_str = ctx.current_version.ToString(); | 467 ctx.current_version_str = ctx.current_version.ToString(); |
466 | 468 |
467 if (!IncrementNewVersion(direction, &ctx)) | 469 if (!IncrementNewVersion(direction, &ctx)) |
468 return false; | 470 return false; |
469 | 471 |
470 // Modify all .dll and .exe files with the current version. | 472 // Modify all .dll and .exe files with the current version. |
471 base::FileEnumerator all_files(work_dir, true, base::FileEnumerator::FILES); | 473 base::FileEnumerator all_files(work_dir, true, base::FileEnumerator::FILES); |
472 while (true) { | 474 while (true) { |
473 base::FilePath file = all_files.Next(); | 475 base::FilePath file = all_files.Next(); |
474 if (file.empty()) | 476 if (file.empty()) |
475 break; | 477 break; |
476 std::wstring extension = file.Extension(); | 478 base::string16 extension = file.Extension(); |
477 if ((extension == &kExtExe[0] || extension == &kExtDll[0]) && | 479 if ((extension == &kExtExe[0] || extension == &kExtDll[0]) && |
478 !UpdateVersionIfMatch(file, &ctx)) { | 480 !UpdateVersionIfMatch(file, &ctx)) { |
479 return false; | 481 return false; |
480 } | 482 } |
481 } | 483 } |
482 | 484 |
483 // Change the versioned directory. | 485 // Change the versioned directory. |
484 base::FilePath chrome_bin = work_dir.Append(&kChromeBin[0]); | 486 base::FilePath chrome_bin = work_dir.Append(&kChromeBin[0]); |
485 if (!base::Move(chrome_bin.Append(ctx.current_version_str), | 487 if (!base::Move(chrome_bin.Append(ctx.current_version_str), |
486 chrome_bin.Append(ctx.new_version_str))) { | 488 chrome_bin.Append(ctx.new_version_str))) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 return l7za_path; | 529 return l7za_path; |
528 } | 530 } |
529 | 531 |
530 bool CreateArchive(const base::FilePath& output_file, | 532 bool CreateArchive(const base::FilePath& output_file, |
531 const base::FilePath& input_path, | 533 const base::FilePath& input_path, |
532 int compression_level) { | 534 int compression_level) { |
533 DCHECK(compression_level == 0 || | 535 DCHECK(compression_level == 0 || |
534 compression_level >= 1 && compression_level <= 9 && | 536 compression_level >= 1 && compression_level <= 9 && |
535 (compression_level & 0x01) != 0); | 537 (compression_level & 0x01) != 0); |
536 | 538 |
537 std::wstring command_line(1, L'"'); | 539 base::string16 command_line(1, L'"'); |
538 command_line | 540 command_line |
539 .append(Get7zaPath().Append(&k7zaExe[0]).value()) | 541 .append(Get7zaPath().Append(&k7zaExe[0]).value()) |
540 .append(L"\" a -bd -t7z \"") | 542 .append(L"\" a -bd -t7z \"") |
541 .append(output_file.value()) | 543 .append(output_file.value()) |
542 .append(L"\" \"") | 544 .append(L"\" \"") |
543 .append(input_path.value()) | 545 .append(input_path.value()) |
544 .append(L"\" -mx") | 546 .append(L"\" -mx") |
545 .append(1, L'0' + compression_level); | 547 .append(1, L'0' + compression_level); |
546 int exit_code; | 548 int exit_code; |
547 if (!RunProcessAndWait(NULL, command_line, &exit_code)) | 549 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
548 return false; | 550 return false; |
549 if (exit_code != 0) { | 551 if (exit_code != 0) { |
550 LOG(DFATAL) << Get7zaPath().Append(&k7zaExe[0]).value() | 552 LOG(DFATAL) << Get7zaPath().Append(&k7zaExe[0]).value() |
551 << " exited with code " << exit_code | 553 << " exited with code " << exit_code |
552 << " while creating " << output_file.value(); | 554 << " while creating " << output_file.value(); |
553 return false; | 555 return false; |
554 } | 556 } |
555 return true; | 557 return true; |
556 } | 558 } |
557 | 559 |
558 } // namespace | 560 } // namespace |
559 | 561 |
560 namespace upgrade_test { | 562 namespace upgrade_test { |
561 | 563 |
562 bool GenerateAlternateVersion(const base::FilePath& original_installer_path, | 564 bool GenerateAlternateVersion(const base::FilePath& original_installer_path, |
563 const base::FilePath& target_path, | 565 const base::FilePath& target_path, |
564 Direction direction, | 566 Direction direction, |
565 std::wstring* original_version, | 567 base::string16* original_version, |
566 std::wstring* new_version) { | 568 base::string16* new_version) { |
567 // Create a temporary directory in which we'll do our work. | 569 // Create a temporary directory in which we'll do our work. |
568 ScopedTempDirectory work_dir; | 570 ScopedTempDirectory work_dir; |
569 if (!work_dir.Initialize()) | 571 if (!work_dir.Initialize()) |
570 return false; | 572 return false; |
571 | 573 |
572 // Copy the original mini_installer. | 574 // Copy the original mini_installer. |
573 base::FilePath mini_installer = | 575 base::FilePath mini_installer = |
574 work_dir.directory().Append(original_installer_path.BaseName()); | 576 work_dir.directory().Append(original_installer_path.BaseName()); |
575 if (!base::CopyFile(original_installer_path, mini_installer)) { | 577 if (!base::CopyFile(original_installer_path, mini_installer)) { |
576 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() | 578 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() |
577 << "\" to \"" << mini_installer.value() << "\""; | 579 << "\" to \"" << mini_installer.value() << "\""; |
578 return false; | 580 return false; |
579 } | 581 } |
580 | 582 |
581 base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); | 583 base::FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); |
582 base::FilePath chrome_packed_7z; // Empty for component builds. | 584 base::FilePath chrome_packed_7z; // Empty for component builds. |
583 base::FilePath chrome_7z; | 585 base::FilePath chrome_7z; |
584 const wchar_t* archive_resource_name = nullptr; | 586 const base::char16* archive_resource_name = nullptr; |
585 base::FilePath* archive_file = nullptr; | 587 base::FilePath* archive_file = nullptr; |
586 // Load the original file and extract setup.ex_ and chrome.packed.7z | 588 // Load the original file and extract setup.ex_ and chrome.packed.7z |
587 { | 589 { |
588 ResourceLoader resource_loader; | 590 ResourceLoader resource_loader; |
589 std::pair<const uint8_t*, DWORD> resource_data; | 591 std::pair<const uint8_t*, DWORD> resource_data; |
590 | 592 |
591 if (!resource_loader.Initialize(mini_installer)) | 593 if (!resource_loader.Initialize(mini_installer)) |
592 return false; | 594 return false; |
593 | 595 |
594 // Write out setup.ex_ | 596 // Write out setup.ex_ |
(...skipping 27 matching lines...) Expand all Loading... |
622 *archive_file, reinterpret_cast<const char*>(resource_data.first), | 624 *archive_file, reinterpret_cast<const char*>(resource_data.first), |
623 static_cast<int>(resource_data.second)); | 625 static_cast<int>(resource_data.second)); |
624 if (written != static_cast<int>(resource_data.second)) { | 626 if (written != static_cast<int>(resource_data.second)) { |
625 LOG(DFATAL) << "Failed writing \"" << archive_file->value() << "\""; | 627 LOG(DFATAL) << "Failed writing \"" << archive_file->value() << "\""; |
626 return false; | 628 return false; |
627 } | 629 } |
628 } | 630 } |
629 | 631 |
630 // Expand setup.ex_ | 632 // Expand setup.ex_ |
631 base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); | 633 base::FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); |
632 std::wstring command_line; | 634 base::string16 command_line; |
633 command_line.append(1, L'"') | 635 command_line.append(1, L'"') |
634 .append(&kExpandExe[0]) | 636 .append(&kExpandExe[0]) |
635 .append(L"\" \"") | 637 .append(L"\" \"") |
636 .append(setup_ex_.value()) | 638 .append(setup_ex_.value()) |
637 .append(L"\" \"") | 639 .append(L"\" \"") |
638 .append(setup_exe.value()) | 640 .append(setup_exe.value()) |
639 .append(1, L'\"'); | 641 .append(1, L'\"'); |
640 int exit_code; | 642 int exit_code; |
641 if (!RunProcessAndWait(NULL, command_line, &exit_code)) | 643 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
642 return false; | 644 return false; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 LOG(ERROR) << "It is common for this step to fail for very large resources," | 718 LOG(ERROR) << "It is common for this step to fail for very large resources," |
717 " as is the case for Debug component=shared_library builds. " | 719 " as is the case for Debug component=shared_library builds. " |
718 "Try with a Release or component=static_library build."; | 720 "Try with a Release or component=static_library build."; |
719 return false; | 721 return false; |
720 } | 722 } |
721 | 723 |
722 // Finally, move the updated mini_installer into place. | 724 // Finally, move the updated mini_installer into place. |
723 return base::Move(mini_installer, target_path); | 725 return base::Move(mini_installer, target_path); |
724 } | 726 } |
725 | 727 |
726 bool GenerateAlternatePEFileVersion(const base::FilePath& original_file, | 728 base::string16 GenerateAlternatePEFileVersion( |
727 const base::FilePath& target_file, | 729 const base::FilePath& original_file, |
728 Direction direction) { | 730 const base::FilePath& target_file, |
| 731 Direction direction) { |
729 VisitResourceContext ctx; | 732 VisitResourceContext ctx; |
730 if (!GetFileVersion(original_file, &ctx.current_version)) { | 733 if (!GetFileVersion(original_file, &ctx.current_version)) { |
731 LOG(DFATAL) << "Failed reading version from \"" << original_file.value() | 734 LOG(DFATAL) << "Failed reading version from \"" << original_file.value() |
732 << "\""; | 735 << "\""; |
733 return false; | 736 return base::string16(); |
734 } | 737 } |
735 ctx.current_version_str = ctx.current_version.ToString(); | 738 ctx.current_version_str = ctx.current_version.ToString(); |
736 | 739 |
737 if (!IncrementNewVersion(direction, &ctx)) { | 740 if (!IncrementNewVersion(direction, &ctx)) { |
738 LOG(DFATAL) << "Failed to increment version from \"" | 741 LOG(DFATAL) << "Failed to increment version from \"" |
739 << original_file.value() << "\""; | 742 << original_file.value() << "\""; |
740 return false; | 743 return base::string16(); |
741 } | 744 } |
742 | 745 |
743 base::Version new_version(base::UTF16ToASCII(ctx.new_version_str)); | 746 base::Version new_version(base::UTF16ToASCII(ctx.new_version_str)); |
744 GenerateSpecificPEFileVersion(original_file, target_file, new_version); | 747 GenerateSpecificPEFileVersion(original_file, target_file, new_version); |
745 | 748 |
746 return true; | 749 return ctx.new_version_str; |
747 } | 750 } |
748 | 751 |
749 bool GenerateSpecificPEFileVersion(const base::FilePath& original_file, | 752 bool GenerateSpecificPEFileVersion(const base::FilePath& original_file, |
750 const base::FilePath& target_file, | 753 const base::FilePath& target_file, |
751 const base::Version& version) { | 754 const base::Version& version) { |
752 // First copy original_file to target_file. | 755 // First copy original_file to target_file. |
753 if (!base::CopyFile(original_file, target_file)) { | 756 if (!base::CopyFile(original_file, target_file)) { |
754 LOG(DFATAL) << "Failed copying \"" << original_file.value() | 757 LOG(DFATAL) << "Failed copying \"" << original_file.value() |
755 << "\" to \"" << target_file.value() << "\""; | 758 << "\" to \"" << target_file.value() << "\""; |
756 return false; | 759 return false; |
757 } | 760 } |
758 | 761 |
759 VisitResourceContext ctx; | 762 VisitResourceContext ctx; |
760 if (!GetFileVersion(target_file, &ctx.current_version)) { | 763 if (!GetFileVersion(target_file, &ctx.current_version)) { |
761 LOG(DFATAL) << "Failed reading version from \"" << target_file.value() | 764 LOG(DFATAL) << "Failed reading version from \"" << target_file.value() |
762 << "\""; | 765 << "\""; |
763 return false; | 766 return false; |
764 } | 767 } |
765 ctx.current_version_str = ctx.current_version.ToString(); | 768 ctx.current_version_str = ctx.current_version.ToString(); |
766 ctx.new_version = ChromeVersion::FromString(version.GetString()); | 769 ctx.new_version = ChromeVersion::FromString(version.GetString()); |
767 ctx.new_version_str = ctx.new_version.ToString(); | 770 ctx.new_version_str = ctx.new_version.ToString(); |
768 | 771 |
769 return UpdateVersionIfMatch(target_file, &ctx); | 772 return UpdateVersionIfMatch(target_file, &ctx); |
770 } | 773 } |
771 | 774 |
772 } // namespace upgrade_test | 775 } // namespace upgrade_test |
OLD | NEW |