OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // The file contains the implementation of the mini_installer re-versioner. |
| 6 // The main function (GenerateNextVersion) does the following in a temp dir: |
| 7 // - Extracts and unpacks setup.exe and the Chrome-bin folder from |
| 8 // mini_installer.exe. |
| 9 // - Inspects setup.exe to determine the current version. |
| 10 // - Runs through all .dll and .exe files: |
| 11 // - Replacing all occurrences of the Unicode version string in the files' |
| 12 // resources with the updated string. |
| 13 // - For all resources in which the string substitution is made, the binary |
| 14 // form of the version is also replaced. |
| 15 // - Re-packs setup.exe and Chrome-bin. |
| 16 // - Inserts them into the target mini_installer.exe. |
| 17 // |
| 18 // This code assumes that the host program 1) initializes the process-wide |
| 19 // CommandLine instance, and 2) resides in the output directory of a build |
| 20 // tree. When #2 is not the case, the --7za_path command-line switch may be |
| 21 // used to provide the (relative or absolute) path to the directory containing |
| 22 // 7za.exe. |
| 23 |
| 24 #include "chrome/installer/test/alternate_version_generator.h" |
| 25 |
| 26 #include <windows.h> |
| 27 |
| 28 #include <algorithm> |
| 29 #include <sstream> |
| 30 #include <limits> |
| 31 #include <utility> |
| 32 #include <vector> |
| 33 |
| 34 #include "base/basictypes.h" |
| 35 #include "base/command_line.h" |
| 36 #include "base/file_path.h" |
| 37 #include "base/file_util.h" |
| 38 #include "base/logging.h" |
| 39 #include "base/path_service.h" |
| 40 #include "base/platform_file.h" |
| 41 #include "base/win/pe_image.h" |
| 42 #include "base/win/scoped_handle.h" |
| 43 #include "chrome/installer/test/pe_image_resources.h" |
| 44 #include "chrome/installer/test/resource_loader.h" |
| 45 #include "chrome/installer/test/resource_updater.h" |
| 46 #include "chrome/installer/util/lzma_util.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" |
| 48 |
| 49 namespace { |
| 50 |
| 51 const wchar_t k7zaExe[] = L"7za.exe"; |
| 52 const wchar_t k7zaPathRelative[] = L"..\\..\\third_party\\lzma_sdk\\Executable"; |
| 53 const wchar_t kB7[] = L"B7"; |
| 54 const wchar_t kBl[] = L"BL"; |
| 55 const wchar_t kChrome7z[] = L"chrome.7z"; |
| 56 const wchar_t kChromeBin[] = L"Chrome-bin"; |
| 57 const wchar_t kChromePacked7z[] = L"chrome.packed.7z"; |
| 58 const wchar_t kExe[] = L"exe"; |
| 59 const wchar_t kExpandExe[] = L"expand.exe"; |
| 60 const wchar_t kExtDll[] = L".dll"; |
| 61 const wchar_t kExtExe[] = L".exe"; |
| 62 const wchar_t kMakeCab[] = L"makecab.exe"; |
| 63 const wchar_t kSetupEx_[] = L"setup.ex_"; |
| 64 const wchar_t kSetupExe[] = L"setup.exe"; |
| 65 const char kSwitch7zaPath[] = "7za_path"; |
| 66 const wchar_t kTempDirPrefix[] = L"mini_installer_test_temp"; |
| 67 |
| 68 // A helper class for creating and cleaning a temporary directory. A temporary |
| 69 // directory is created in Initialize and destroyed (along with all of its |
| 70 // contents) when the guard instance is destroyed. |
| 71 class ScopedTempDirectory { |
| 72 public: |
| 73 ScopedTempDirectory() { } |
| 74 ~ScopedTempDirectory() { |
| 75 if (!directory_.empty() && !file_util::Delete(directory_, true)) { |
| 76 LOG(DFATAL) << "Failed deleting temporary directory \"" |
| 77 << directory_.value() << "\""; |
| 78 } |
| 79 } |
| 80 // Creates a temporary directory. |
| 81 bool Initialize() { |
| 82 DCHECK(directory_.empty()); |
| 83 if (!file_util::CreateNewTempDirectory(&kTempDirPrefix[0], &directory_)) { |
| 84 LOG(DFATAL) << "Failed creating temporary directory."; |
| 85 return false; |
| 86 } |
| 87 return true; |
| 88 } |
| 89 const FilePath& directory() const { |
| 90 DCHECK(!directory_.empty()); |
| 91 return directory_; |
| 92 } |
| 93 private: |
| 94 FilePath directory_; |
| 95 DISALLOW_COPY_AND_ASSIGN(ScopedTempDirectory); |
| 96 }; // class ScopedTempDirectory |
| 97 |
| 98 // A helper class for manipulating a Chrome product version. |
| 99 class ChromeVersion { |
| 100 public: |
| 101 static ChromeVersion FromHighLow(DWORD high, DWORD low) { |
| 102 return ChromeVersion(static_cast<ULONGLONG>(high) << 32 | |
| 103 static_cast<ULONGLONG>(low)); |
| 104 } |
| 105 ChromeVersion() { } |
| 106 explicit ChromeVersion(ULONGLONG value) : version_(value) { } |
| 107 WORD major() const { return static_cast<WORD>(version_ >> 48); } |
| 108 WORD minor() const { return static_cast<WORD>(version_ >> 32); } |
| 109 WORD build() const { return static_cast<WORD>(version_ >> 16); } |
| 110 WORD patch() const { return static_cast<WORD>(version_); } |
| 111 DWORD high() const { return static_cast<DWORD>(version_ >> 32); } |
| 112 DWORD low() const { return static_cast<DWORD>(version_); } |
| 113 ULONGLONG value() const { return version_; } |
| 114 void set_value(ULONGLONG value) { version_ = value; } |
| 115 std::wstring ToString() const; |
| 116 private: |
| 117 ULONGLONG version_; |
| 118 }; // class ChromeVersion |
| 119 |
| 120 std::wstring ChromeVersion::ToString() const { |
| 121 wchar_t buffer[24]; |
| 122 int string_len = |
| 123 swprintf_s(&buffer[0], arraysize(buffer), L"%hu.%hu.%hu.%hu", |
| 124 major(), minor(), build(), patch()); |
| 125 DCHECK_NE(-1, string_len); |
| 126 DCHECK_GT(static_cast<int>(arraysize(buffer)), string_len); |
| 127 return std::wstring(&buffer[0], string_len); |
| 128 } |
| 129 |
| 130 // A read/write mapping of a file. |
| 131 // Note: base::MemoryMappedFile is not used because it doesn't support |
| 132 // read/write mappings. Adding such support across all platforms for this |
| 133 // Windows-only test code seems like overkill. |
| 134 class MappedFile { |
| 135 public: |
| 136 MappedFile() : size_(), mapping_(), view_() { } |
| 137 ~MappedFile(); |
| 138 bool Initialize(base::PlatformFile file); |
| 139 void* data() const { return view_; } |
| 140 size_t size() const { return size_; } |
| 141 private: |
| 142 size_t size_; |
| 143 HANDLE mapping_; |
| 144 void* view_; |
| 145 DISALLOW_COPY_AND_ASSIGN(MappedFile); |
| 146 }; // class MappedFile |
| 147 |
| 148 MappedFile::~MappedFile() { |
| 149 if (view_ != NULL) { |
| 150 EXPECT_NE(0, UnmapViewOfFile(view_)); |
| 151 } |
| 152 if (mapping_ != NULL) { |
| 153 EXPECT_NE(0, CloseHandle(mapping_)); |
| 154 } |
| 155 } |
| 156 |
| 157 bool MappedFile::Initialize(base::PlatformFile file) { |
| 158 DCHECK(mapping_ == NULL); |
| 159 bool result = false; |
| 160 base::PlatformFileInfo file_info; |
| 161 |
| 162 if (base::GetPlatformFileInfo(file, &file_info)) { |
| 163 if (file_info.size <= |
| 164 static_cast<int64>(std::numeric_limits<size_t>::max())) { |
| 165 mapping_ = CreateFileMapping(file, NULL, PAGE_READWRITE, 0, |
| 166 static_cast<DWORD>(file_info.size), NULL); |
| 167 if (mapping_ != NULL) { |
| 168 view_ = MapViewOfFile(mapping_, FILE_MAP_WRITE, 0, 0, |
| 169 static_cast<size_t>(file_info.size)); |
| 170 if (view_ != NULL) { |
| 171 result = true; |
| 172 } else { |
| 173 PLOG(DFATAL) << "MapViewOfFile failed"; |
| 174 } |
| 175 } else { |
| 176 PLOG(DFATAL) << "CreateFileMapping failed"; |
| 177 } |
| 178 } else { |
| 179 LOG(DFATAL) << "Files larger than " << std::numeric_limits<size_t>::max() |
| 180 << " are not supported."; |
| 181 } |
| 182 } else { |
| 183 PLOG(DFATAL) << "GetPlatformFileInfo failed"; |
| 184 } |
| 185 return result; |
| 186 } |
| 187 |
| 188 // Calls CreateProcess with good default parameters and waits for the process |
| 189 // to terminate returning the process exit code. |
| 190 bool RunProcessAndWait(const wchar_t* exe_path, const std::wstring& cmdline, |
| 191 int* exit_code) { |
| 192 std::vector<wchar_t> cmd_line(cmdline.c_str(), |
| 193 cmdline.c_str() + cmdline.size() + 1); |
| 194 STARTUPINFOW si = {sizeof(si)}; |
| 195 PROCESS_INFORMATION pi = {0}; |
| 196 if (!CreateProcess(exe_path, &cmd_line[0], NULL, NULL, FALSE, |
| 197 CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { |
| 198 PLOG(DFATAL) << "CreateProcess failed with command line: \"" << cmdline |
| 199 << "\""; |
| 200 return false; |
| 201 } |
| 202 |
| 203 CloseHandle(pi.hThread); |
| 204 bool result = true; |
| 205 DWORD wr = WaitForSingleObject(pi.hProcess, INFINITE); |
| 206 if (wr == WAIT_OBJECT_0) { |
| 207 if (exit_code) { |
| 208 if (!GetExitCodeProcess(pi.hProcess, |
| 209 reinterpret_cast<DWORD*>(exit_code))) { |
| 210 PLOG(DFATAL) << "Failed getting the exit code for \"" |
| 211 << cmdline << "\"."; |
| 212 result = false; |
| 213 } else { |
| 214 DCHECK_NE(*exit_code, STILL_ACTIVE); |
| 215 } |
| 216 } |
| 217 } else { |
| 218 if (wr == WAIT_FAILED) { |
| 219 PLOG(DFATAL) << "Failed while waiting for \"" << &cmd_line[0] |
| 220 << "\" to exit."; |
| 221 } else { |
| 222 LOG(DFATAL) << "Received result " << wr << " while waiting for \"" |
| 223 << &cmd_line[0] << "\" to exit."; |
| 224 } |
| 225 result = false; |
| 226 } |
| 227 |
| 228 CloseHandle(pi.hProcess); |
| 229 return result; |
| 230 } |
| 231 |
| 232 // Retrieves the version number of setup.exe in |work_dir| from its version |
| 233 // resource, placing the value in |version|. Returns true on success. |
| 234 bool GetSetupExeVersion(const FilePath& work_dir, ChromeVersion* version) { |
| 235 DCHECK(version); |
| 236 bool result = false; |
| 237 upgrade_test::ResourceLoader setup; |
| 238 std::pair<const uint8*, DWORD> version_info_data; |
| 239 |
| 240 if (setup.Initialize(work_dir.Append(&kSetupExe[0])) && |
| 241 setup.Load(VS_VERSION_INFO, reinterpret_cast<WORD>(RT_VERSION), |
| 242 &version_info_data)) { |
| 243 const VS_FIXEDFILEINFO* fixed_file_info; |
| 244 UINT ver_info_len; |
| 245 if (VerQueryValue(version_info_data.first, L"\\", |
| 246 reinterpret_cast<void**>( |
| 247 const_cast<VS_FIXEDFILEINFO**>(&fixed_file_info)), |
| 248 &ver_info_len) != 0) { |
| 249 DCHECK_EQ(sizeof(VS_FIXEDFILEINFO), static_cast<size_t>(ver_info_len)); |
| 250 *version = ChromeVersion::FromHighLow(fixed_file_info->dwFileVersionMS, |
| 251 fixed_file_info->dwFileVersionLS); |
| 252 result = true; |
| 253 } else { |
| 254 LOG(DFATAL) << "VerQueryValue failed to retrieve VS_FIXEDFILEINFO"; |
| 255 } |
| 256 } |
| 257 |
| 258 return result; |
| 259 } |
| 260 |
| 261 // Replace all occurrences in the sequence [|dest_first|, |dest_last) that |
| 262 // equals [|src_first|, |src_last) with the sequence at |replacement_first| of |
| 263 // the same length. Returns true on success. If non-NULL, |replacements_made| |
| 264 // is set to true/false accordingly. |
| 265 bool ReplaceAll(uint8* dest_first, uint8* dest_last, |
| 266 const uint8* src_first, const uint8* src_last, |
| 267 const uint8* replacement_first, bool* replacements_made) { |
| 268 bool result = true; |
| 269 bool changed = false; |
| 270 do { |
| 271 dest_first = std::search(dest_first, dest_last, src_first, src_last); |
| 272 if (dest_first == dest_last) { |
| 273 break; |
| 274 } |
| 275 changed = true; |
| 276 if (memcpy_s(dest_first, dest_last - dest_first, |
| 277 replacement_first, src_last - src_first) != 0) { |
| 278 result = false; |
| 279 break; |
| 280 } |
| 281 dest_first += (src_last - src_first); |
| 282 } while (true); |
| 283 |
| 284 if (replacements_made != NULL) { |
| 285 *replacements_made = changed; |
| 286 } |
| 287 |
| 288 return result; |
| 289 } |
| 290 |
| 291 // A context structure in support of our EnumResource_Fn callback. |
| 292 struct VisitResourceContext { |
| 293 ChromeVersion current_version; |
| 294 std::wstring current_version_str; |
| 295 ChromeVersion new_version; |
| 296 std::wstring new_version_str; |
| 297 }; // struct VisitResourceContext |
| 298 |
| 299 // Replaces the old version with the new in a resource. A first pass is made to |
| 300 // replace the string form (e.g., "9.0.584.0"). If any replacements are made, a |
| 301 // second pass is made to replace the binary form (e.g., 0x0000024800000009). |
| 302 void VisitResource(const upgrade_test::EntryPath& path, |
| 303 uint8* data, DWORD size, DWORD code_page, |
| 304 uintptr_t context) { |
| 305 VisitResourceContext& ctx = *reinterpret_cast<VisitResourceContext*>(context); |
| 306 |
| 307 // Replace all occurrences of current_version_str with new_version_str |
| 308 bool changing_version = false; |
| 309 if (ReplaceAll( |
| 310 data, |
| 311 data + size, |
| 312 reinterpret_cast<const uint8*>(ctx.current_version_str.c_str()), |
| 313 reinterpret_cast<const uint8*>(ctx.current_version_str.c_str() + |
| 314 ctx.current_version_str.size() + 1), |
| 315 reinterpret_cast<const uint8*>(ctx.new_version_str.c_str()), |
| 316 &changing_version) && |
| 317 changing_version) { |
| 318 // Replace all occurrences of current_version with new_version |
| 319 struct VersionPair { |
| 320 DWORD high; |
| 321 DWORD low; |
| 322 }; |
| 323 VersionPair cur_ver = { |
| 324 ctx.current_version.high(), ctx.current_version.low() |
| 325 }; |
| 326 VersionPair new_ver = { |
| 327 ctx.new_version.high(), ctx.new_version.low() |
| 328 }; |
| 329 ReplaceAll(data, data + size, reinterpret_cast<const uint8*>(&cur_ver), |
| 330 reinterpret_cast<const uint8*>(&cur_ver) + sizeof(cur_ver), |
| 331 reinterpret_cast<const uint8*>(&new_ver), NULL); |
| 332 } |
| 333 } |
| 334 |
| 335 // Updates the version strings and numbers in all of |image_file|'s resources. |
| 336 bool UpdateVersionIfMatch(const FilePath& image_file, |
| 337 VisitResourceContext* context) { |
| 338 bool result = false; |
| 339 base::win::ScopedHandle image_handle(base::CreatePlatformFile( |
| 340 image_file, |
| 341 (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ | |
| 342 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 343 base::PLATFORM_FILE_EXCLUSIVE_WRITE), NULL, NULL)); |
| 344 if (image_handle.Get() != INVALID_HANDLE_VALUE) { |
| 345 MappedFile image_mapping; |
| 346 if (image_mapping.Initialize(image_handle)) { |
| 347 base::win::PEImageAsData image( |
| 348 reinterpret_cast<HMODULE>(image_mapping.data())); |
| 349 // PEImage class does not support other-architecture images. |
| 350 if (image.GetNTHeaders()->OptionalHeader.Magic == |
| 351 IMAGE_NT_OPTIONAL_HDR_MAGIC) { |
| 352 result = upgrade_test::EnumResources( |
| 353 image, &VisitResource, reinterpret_cast<uintptr_t>(context)); |
| 354 } else { |
| 355 result = true; |
| 356 } |
| 357 } |
| 358 } else { |
| 359 PLOG(DFATAL) << "Failed to open \"" << image_file.value() << "\""; |
| 360 } |
| 361 return result; |
| 362 } |
| 363 |
| 364 // Bumps the version of all .exe and .dll files in |work_dir| as well as the |
| 365 // |work-dir|\Chrome-bin\w.x.y.z directory. |
| 366 bool ApplyNextVersion(const FilePath& work_dir) { |
| 367 VisitResourceContext ctx; |
| 368 if (!GetSetupExeVersion(work_dir, &ctx.current_version)) { |
| 369 return false; |
| 370 } |
| 371 ctx.current_version_str = ctx.current_version.ToString(); |
| 372 |
| 373 // Figure out a future version with the same string length as this one by |
| 374 // incrementing each component. |
| 375 ULONGLONG incrementer = 1; |
| 376 |
| 377 do { |
| 378 if (incrementer == 0) { |
| 379 LOG(DFATAL) << "Improbable version composed of only 9s and/or USHRT_MAX"; |
| 380 return false; |
| 381 } |
| 382 ctx.new_version.set_value(ctx.current_version.value() + incrementer); |
| 383 ctx.new_version_str = ctx.new_version.ToString(); |
| 384 incrementer <<= 16; |
| 385 } while (ctx.new_version_str.size() != ctx.current_version_str.size()); |
| 386 |
| 387 // Modify all .dll and .exe files with the current version. |
| 388 bool doing_great = true; |
| 389 file_util::FileEnumerator all_files(work_dir, true, |
| 390 file_util::FileEnumerator::FILES); |
| 391 do { |
| 392 FilePath file = all_files.Next(); |
| 393 if (file.empty()) { |
| 394 break; |
| 395 } |
| 396 std::wstring extension = file.Extension(); |
| 397 if (extension == &kExtExe[0] || extension == &kExtDll[0]) { |
| 398 doing_great = UpdateVersionIfMatch(file, &ctx); |
| 399 } |
| 400 } while (doing_great); |
| 401 |
| 402 // Change the versioned directory. |
| 403 FilePath chrome_bin = work_dir.Append(&kChromeBin[0]); |
| 404 doing_great = file_util::Move(chrome_bin.Append(ctx.current_version_str), |
| 405 chrome_bin.Append(ctx.new_version_str)); |
| 406 |
| 407 return doing_great; |
| 408 } |
| 409 |
| 410 // Returns the path to the directory holding the 7za executable. By default, it |
| 411 // is assumed that the test resides in the tree's output directory, so the |
| 412 // relative path "..\..\third_party\lzma_sdk\Executable" is applied to the host |
| 413 // executable's directory. This can be overridden with the --7za_path |
| 414 // command-line switch. |
| 415 FilePath Get7zaPath() { |
| 416 FilePath l7za_path = CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 417 &kSwitch7zaPath[0]); |
| 418 if (l7za_path.empty()) { |
| 419 FilePath dir_exe; |
| 420 if (!PathService::Get(base::DIR_EXE, &dir_exe)) |
| 421 LOG(DFATAL) << "Failed getting directory of host executable"; |
| 422 l7za_path = dir_exe.Append(&k7zaPathRelative[0]); |
| 423 } |
| 424 return l7za_path; |
| 425 } |
| 426 |
| 427 bool CreateArchive(const FilePath& output_file, const FilePath& input_path, |
| 428 int compression_level) { |
| 429 DCHECK(compression_level == 0 || |
| 430 compression_level >= 1 && compression_level <= 9 && |
| 431 (compression_level & 0x01) != 0); |
| 432 |
| 433 std::wstring command_line(1, L'"'); |
| 434 command_line |
| 435 .append(Get7zaPath().Append(&k7zaExe[0]).value()) |
| 436 .append(L"\" a -bd -t7z \"") |
| 437 .append(output_file.value()) |
| 438 .append(L"\" \"") |
| 439 .append(input_path.value()) |
| 440 .append(L"\" -mx") |
| 441 .append(1, L'0' + compression_level); |
| 442 int exit_code; |
| 443 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
| 444 return false; |
| 445 if (exit_code != 0) { |
| 446 LOG(DFATAL) << Get7zaPath().Append(&k7zaExe[0]).value() |
| 447 << " exited with code " << exit_code |
| 448 << " while creating " << output_file.value(); |
| 449 return false; |
| 450 } |
| 451 return true; |
| 452 } |
| 453 |
| 454 } // namespace |
| 455 |
| 456 namespace upgrade_test { |
| 457 |
| 458 bool GenerateNextVersion(const FilePath& original_installer_path, |
| 459 const FilePath& target_path) { |
| 460 // Create a temporary directory in which we'll do our work. |
| 461 ScopedTempDirectory work_dir; |
| 462 if (!work_dir.Initialize()) |
| 463 return false; |
| 464 |
| 465 // Copy the original mini_installer. |
| 466 FilePath mini_installer = |
| 467 work_dir.directory().Append(original_installer_path.BaseName()); |
| 468 if (!file_util::CopyFile(original_installer_path, mini_installer)) { |
| 469 LOG(DFATAL) << "Failed copying \"" << original_installer_path.value() |
| 470 << "\" to \"" << mini_installer.value() << "\""; |
| 471 return false; |
| 472 } |
| 473 |
| 474 FilePath setup_ex_ = work_dir.directory().Append(&kSetupEx_[0]); |
| 475 FilePath chrome_packed_7z = work_dir.directory().Append(&kChromePacked7z[0]); |
| 476 // Load the original file and extract setup.ex_ and chrome.packed.7z |
| 477 { |
| 478 ResourceLoader resource_loader; |
| 479 std::pair<const uint8*, DWORD> resource_data; |
| 480 |
| 481 if (!resource_loader.Initialize(mini_installer)) |
| 482 return false; |
| 483 |
| 484 // Write out setup.ex_ |
| 485 if (!resource_loader.Load(&kSetupEx_[0], &kBl[0], &resource_data)) |
| 486 return false; |
| 487 int written = |
| 488 file_util::WriteFile(setup_ex_, |
| 489 reinterpret_cast<const char*>(resource_data.first), |
| 490 static_cast<int>(resource_data.second)); |
| 491 if (written != resource_data.second) { |
| 492 LOG(DFATAL) << "Failed writing \"" << setup_ex_.value() << "\""; |
| 493 return false; |
| 494 } |
| 495 |
| 496 // Write out chrome.packed.7z |
| 497 if (!resource_loader.Load(&kChromePacked7z[0], &kB7[0], &resource_data)) |
| 498 return false; |
| 499 written = |
| 500 file_util::WriteFile(chrome_packed_7z, |
| 501 reinterpret_cast<const char*>(resource_data.first), |
| 502 static_cast<int>(resource_data.second)); |
| 503 if (written != resource_data.second) { |
| 504 LOG(DFATAL) << "Failed writing \"" << chrome_packed_7z.value() << "\""; |
| 505 return false; |
| 506 } |
| 507 } |
| 508 |
| 509 // Expand setup.ex_ |
| 510 FilePath setup_exe = setup_ex_.ReplaceExtension(&kExe[0]); |
| 511 std::wstring command_line; |
| 512 command_line.append(1, L'"') |
| 513 .append(&kExpandExe[0]) |
| 514 .append(L"\" \"") |
| 515 .append(setup_ex_.value()) |
| 516 .append(L"\" \"") |
| 517 .append(setup_exe.value()) |
| 518 .append(1, L'\"'); |
| 519 int exit_code; |
| 520 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
| 521 return false; |
| 522 if (exit_code != 0) { |
| 523 LOG(DFATAL) << &kExpandExe[0] << " exited with code " << exit_code; |
| 524 return false; |
| 525 } |
| 526 |
| 527 // Unpack chrome.packed.7z |
| 528 std::wstring chrome_7z_name; |
| 529 if (LzmaUtil::UnPackArchive(chrome_packed_7z.value(), |
| 530 work_dir.directory().value(), |
| 531 &chrome_7z_name) != NO_ERROR) { |
| 532 LOG(DFATAL) << "Failed unpacking \"" << chrome_packed_7z.value() << "\""; |
| 533 return false; |
| 534 } |
| 535 |
| 536 // Unpack chrome.7z |
| 537 if (LzmaUtil::UnPackArchive(chrome_7z_name, work_dir.directory().value(), |
| 538 NULL) != NO_ERROR) { |
| 539 LOG(DFATAL) << "Failed unpacking \"" << chrome_7z_name << "\""; |
| 540 return false; |
| 541 } |
| 542 |
| 543 // Get rid of intermediate files |
| 544 FilePath chrome_7z(chrome_7z_name); |
| 545 if (!file_util::Delete(chrome_7z, false) || |
| 546 !file_util::Delete(chrome_packed_7z, false) || |
| 547 !file_util::Delete(setup_ex_, false)) { |
| 548 LOG(DFATAL) << "Failed deleting intermediate files"; |
| 549 return false; |
| 550 } |
| 551 |
| 552 // Increment the version in all files. |
| 553 ApplyNextVersion(work_dir.directory()); |
| 554 |
| 555 // Pack up files into chrome.7z |
| 556 if (!CreateArchive(chrome_7z, work_dir.directory().Append(&kChromeBin[0]), 0)) |
| 557 return false; |
| 558 |
| 559 // Compress chrome.7z into chrome.packed.7z |
| 560 if (!CreateArchive(chrome_packed_7z, chrome_7z, 9)) |
| 561 return false; |
| 562 |
| 563 // Compress setup.exe into setup.ex_ |
| 564 command_line.assign(1, L'"') |
| 565 .append(&kMakeCab[0]) |
| 566 .append(L"\" /D CompressionType=LZX /L \"") |
| 567 .append(work_dir.directory().value()) |
| 568 .append(L"\" \"") |
| 569 .append(setup_exe.value()); |
| 570 if (!RunProcessAndWait(NULL, command_line, &exit_code)) |
| 571 return false; |
| 572 if (exit_code != 0) { |
| 573 LOG(DFATAL) << &kMakeCab[0] << " exited with code " << exit_code; |
| 574 return false; |
| 575 } |
| 576 |
| 577 // Replace the mini_installer's setup.ex_ and chrome.packed.7z resources. |
| 578 ResourceUpdater updater; |
| 579 if (!updater.Initialize(mini_installer) || |
| 580 !updater.Update(&kSetupEx_[0], &kBl[0], |
| 581 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), |
| 582 setup_ex_) || |
| 583 !updater.Update(&kChromePacked7z[0], &kB7[0], |
| 584 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), |
| 585 chrome_packed_7z) || |
| 586 !updater.Commit()) { |
| 587 return false; |
| 588 } |
| 589 |
| 590 // Finally, move the updated mini_installer into place. |
| 591 return file_util::Move(mini_installer, target_path); |
| 592 } |
| 593 |
| 594 } // namespace upgrade_test |
OLD | NEW |