Chromium Code Reviews| 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 // mini_installer.exe is the first exe that is run when chrome is being | 5 // mini_installer.exe is the first exe that is run when chrome is being |
| 6 // installed or upgraded. It is designed to be extremely small (~5KB with no | 6 // installed or upgraded. It is designed to be extremely small (~5KB with no |
| 7 // extra resources linked) and it has two main jobs: | 7 // extra resources linked) and it has two main jobs: |
| 8 // 1) unpack the resources (possibly decompressing some) | 8 // 1) unpack the resources (possibly decompressing some) |
| 9 // 2) run the real installer (setup.exe) with appropriate flags. | 9 // 2) run the real installer (setup.exe) with appropriate flags. |
| 10 // | 10 // |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 if (!::GetExitCodeProcess(pi.hProcess, | 297 if (!::GetExitCodeProcess(pi.hProcess, |
| 298 reinterpret_cast<DWORD*>(exit_code))) { | 298 reinterpret_cast<DWORD*>(exit_code))) { |
| 299 ret = false; | 299 ret = false; |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 ::CloseHandle(pi.hProcess); | 303 ::CloseHandle(pi.hProcess); |
| 304 | 304 |
| 305 return ret; | 305 return ret; |
| 306 } | 306 } |
| 307 | 307 |
|
robertshield
2011/05/18 12:28:40
Remove extra blank line.
grt (UTC plus 2)
2011/05/18 13:39:30
Done.
| |
| 308 | 308 |
| 309 // Append any command line params passed to mini_installer to the given buffer | |
| 310 // so that they can be passed on to setup.exe. We do not return any error from | |
| 311 // this method and simply skip making any changes in case of error. | |
| 312 void AppendCommandLineFlags(CommandString* buffer) { | |
| 313 PathString full_exe_path; | |
| 314 size_t len = ::GetModuleFileName(NULL, full_exe_path.get(), | |
| 315 full_exe_path.capacity()); | |
| 316 if (!len || len >= full_exe_path.capacity()) | |
| 317 return; | |
| 318 | |
| 319 const wchar_t* exe_name = GetNameFromPathExt(full_exe_path.get(), len); | |
| 320 if (exe_name == NULL) | |
| 321 return; | |
| 322 | |
| 323 int args_num; | |
| 324 wchar_t* cmd_line = ::GetCommandLine(); | |
| 325 wchar_t** args = ::CommandLineToArgvW(cmd_line, &args_num); | |
| 326 if (args_num <= 0) | |
| 327 return; | |
| 328 | |
| 329 const wchar_t* cmd_to_append = L""; | |
| 330 if (!StrEndsWith(args[0], exe_name)) { | |
| 331 // Current executable name not in the command line so just append | |
| 332 // the whole command line. | |
| 333 cmd_to_append = cmd_line; | |
| 334 } else if (args_num > 1) { | |
| 335 const wchar_t* tmp = SearchStringI(cmd_line, exe_name); | |
| 336 tmp = SearchStringI(tmp, L" "); | |
| 337 cmd_to_append = tmp; | |
| 338 } | |
| 339 | |
| 340 buffer->append(cmd_to_append); | |
| 341 | |
| 342 LocalFree(args); | |
| 343 } | |
| 344 | |
| 345 | |
| 309 // Windows defined callback used in the EnumResourceNames call. For each | 346 // Windows defined callback used in the EnumResourceNames call. For each |
| 310 // matching resource found, the callback is invoked and at this point we write | 347 // matching resource found, the callback is invoked and at this point we write |
| 311 // it to disk. We expect resource names to start with 'chrome' or 'setup'. Any | 348 // it to disk. We expect resource names to start with 'chrome' or 'setup'. Any |
| 312 // other name is treated as an error. | 349 // other name is treated as an error. |
| 313 BOOL CALLBACK OnResourceFound(HMODULE module, const wchar_t* type, | 350 BOOL CALLBACK OnResourceFound(HMODULE module, const wchar_t* type, |
| 314 wchar_t* name, LONG_PTR context) { | 351 wchar_t* name, LONG_PTR context) { |
| 315 if (NULL == context) | 352 if (NULL == context) |
| 316 return FALSE; | 353 return FALSE; |
| 317 | 354 |
| 318 Context* ctx = reinterpret_cast<Context*>(context); | 355 Context* ctx = reinterpret_cast<Context*>(context); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 !cmd_line.append(L"=\"") || | 425 !cmd_line.append(L"=\"") || |
| 389 !cmd_line.append(setup_path->get()) || | 426 !cmd_line.append(setup_path->get()) || |
| 390 !cmd_line.append(L"\"") || | 427 !cmd_line.append(L"\"") || |
| 391 !cmd_line.append(kCmdNewSetupExe) || | 428 !cmd_line.append(kCmdNewSetupExe) || |
| 392 !cmd_line.append(L"=\"") || | 429 !cmd_line.append(L"=\"") || |
| 393 !cmd_line.append(setup_dest_path.get()) || | 430 !cmd_line.append(setup_dest_path.get()) || |
| 394 !cmd_line.append(L"\"")) { | 431 !cmd_line.append(L"\"")) { |
| 395 success = false; | 432 success = false; |
| 396 } | 433 } |
| 397 | 434 |
| 435 // Get any command line option specified for mini_installer and pass them | |
| 436 // on to setup.exe. This is important since switches such as | |
| 437 // --multi-install and --chrome-frame affect where setup.exe will write | |
| 438 // installer results for consumption by Google Update. | |
| 439 AppendCommandLineFlags(&cmd_line); | |
| 440 | |
| 398 int exit_code = 0; | 441 int exit_code = 0; |
| 399 if (success && | 442 if (success && |
| 400 (!RunProcessAndWait(NULL, cmd_line.get(), &exit_code) || | 443 (!RunProcessAndWait(NULL, cmd_line.get(), &exit_code) || |
| 401 exit_code != ERROR_SUCCESS)) { | 444 exit_code != ERROR_SUCCESS)) { |
| 402 success = false; | 445 success = false; |
| 403 } | 446 } |
| 404 | 447 |
| 405 if (!success) | 448 if (!success) |
| 406 DeleteFile(setup_path->get()); | 449 DeleteFile(setup_path->get()); |
| 407 | 450 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 setup_path->clear(); | 491 setup_path->clear(); |
| 449 } else if (!setup_path->assign(setup_dest_path.get())) { | 492 } else if (!setup_path->assign(setup_dest_path.get())) { |
| 450 ::DeleteFile(setup_dest_path.get()); | 493 ::DeleteFile(setup_dest_path.get()); |
| 451 } | 494 } |
| 452 } | 495 } |
| 453 } | 496 } |
| 454 | 497 |
| 455 return setup_path->length() > 0; | 498 return setup_path->length() > 0; |
| 456 } | 499 } |
| 457 | 500 |
| 458 // Append any command line params passed to mini_installer to the given buffer | |
| 459 // so that they can be passed on to setup.exe. We do not return any error from | |
| 460 // this method and simply skip making any changes in case of error. | |
| 461 void AppendCommandLineFlags(CommandString* buffer) { | |
| 462 PathString full_exe_path; | |
| 463 size_t len = ::GetModuleFileName(NULL, full_exe_path.get(), | |
| 464 full_exe_path.capacity()); | |
| 465 if (!len || len >= full_exe_path.capacity()) | |
| 466 return; | |
| 467 | |
| 468 const wchar_t* exe_name = GetNameFromPathExt(full_exe_path.get(), len); | |
| 469 if (exe_name == NULL) | |
| 470 return; | |
| 471 | |
| 472 int args_num; | |
| 473 wchar_t* cmd_line = ::GetCommandLine(); | |
| 474 wchar_t** args = ::CommandLineToArgvW(cmd_line, &args_num); | |
| 475 if (args_num <= 0) | |
| 476 return; | |
| 477 | |
| 478 const wchar_t* cmd_to_append = L""; | |
| 479 if (!StrEndsWith(args[0], exe_name)) { | |
| 480 // Current executable name not in the command line so just append | |
| 481 // the whole command line. | |
| 482 cmd_to_append = cmd_line; | |
| 483 } else if (args_num > 1) { | |
| 484 const wchar_t* tmp = SearchStringI(cmd_line, exe_name); | |
| 485 tmp = SearchStringI(tmp, L" "); | |
| 486 cmd_to_append = tmp; | |
| 487 } | |
| 488 | |
| 489 buffer->append(cmd_to_append); | |
| 490 | |
| 491 LocalFree(args); | |
| 492 } | |
| 493 | |
| 494 // Executes setup.exe, waits for it to finish and returns the exit code. | 501 // Executes setup.exe, waits for it to finish and returns the exit code. |
| 495 bool RunSetup(const wchar_t* archive_path, const wchar_t* setup_path, | 502 bool RunSetup(const wchar_t* archive_path, const wchar_t* setup_path, |
| 496 int* exit_code) { | 503 int* exit_code) { |
| 497 // There could be three full paths in the command line for setup.exe (path | 504 // There could be three full paths in the command line for setup.exe (path |
| 498 // to exe itself, path to archive and path to log file), so we declare | 505 // to exe itself, path to archive and path to log file), so we declare |
| 499 // total size as three + one additional to hold command line options. | 506 // total size as three + one additional to hold command line options. |
| 500 CommandString cmd_line; | 507 CommandString cmd_line; |
| 501 | 508 |
| 502 // Get the path to setup.exe first. | 509 // Get the path to setup.exe first. |
| 503 if (::lstrlen(setup_path) > 0) { | 510 if (::lstrlen(setup_path) > 0) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 case 1: | 850 case 1: |
| 844 dest8[count - 1] = c; | 851 dest8[count - 1] = c; |
| 845 } | 852 } |
| 846 | 853 |
| 847 while (adjcount-- > 0) // Copy the rest, 4 bytes/32 bits at a time | 854 while (adjcount-- > 0) // Copy the rest, 4 bytes/32 bits at a time |
| 848 *(dest32++) = fill; | 855 *(dest32++) = fill; |
| 849 | 856 |
| 850 return dest; | 857 return dest; |
| 851 } | 858 } |
| 852 } // extern "C" | 859 } // extern "C" |
| OLD | NEW |