| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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 | 
|  | 308 // Append any command line params passed to mini_installer to the given buffer | 
|  | 309 // so that they can be passed on to setup.exe. We do not return any error from | 
|  | 310 // this method and simply skip making any changes in case of error. | 
|  | 311 void AppendCommandLineFlags(CommandString* buffer) { | 
|  | 312   PathString full_exe_path; | 
|  | 313   size_t len = ::GetModuleFileName(NULL, full_exe_path.get(), | 
|  | 314                                    full_exe_path.capacity()); | 
|  | 315   if (!len || len >= full_exe_path.capacity()) | 
|  | 316     return; | 
|  | 317 | 
|  | 318   const wchar_t* exe_name = GetNameFromPathExt(full_exe_path.get(), len); | 
|  | 319   if (exe_name == NULL) | 
|  | 320     return; | 
|  | 321 | 
|  | 322   int args_num; | 
|  | 323   wchar_t* cmd_line = ::GetCommandLine(); | 
|  | 324   wchar_t** args = ::CommandLineToArgvW(cmd_line, &args_num); | 
|  | 325   if (args_num <= 0) | 
|  | 326     return; | 
|  | 327 | 
|  | 328   const wchar_t* cmd_to_append = L""; | 
|  | 329   if (!StrEndsWith(args[0], exe_name)) { | 
|  | 330     // Current executable name not in the command line so just append | 
|  | 331     // the whole command line. | 
|  | 332     cmd_to_append = cmd_line; | 
|  | 333   } else if (args_num > 1) { | 
|  | 334     const wchar_t* tmp = SearchStringI(cmd_line, exe_name); | 
|  | 335     tmp = SearchStringI(tmp, L" "); | 
|  | 336     cmd_to_append = tmp; | 
|  | 337   } | 
|  | 338 | 
|  | 339   buffer->append(cmd_to_append); | 
|  | 340 | 
|  | 341   LocalFree(args); | 
|  | 342 } | 
|  | 343 | 
| 308 | 344 | 
| 309 // Windows defined callback used in the EnumResourceNames call. For each | 345 // Windows defined callback used in the EnumResourceNames call. For each | 
| 310 // matching resource found, the callback is invoked and at this point we write | 346 // 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 | 347 // it to disk. We expect resource names to start with 'chrome' or 'setup'. Any | 
| 312 // other name is treated as an error. | 348 // other name is treated as an error. | 
| 313 BOOL CALLBACK OnResourceFound(HMODULE module, const wchar_t* type, | 349 BOOL CALLBACK OnResourceFound(HMODULE module, const wchar_t* type, | 
| 314                               wchar_t* name, LONG_PTR context) { | 350                               wchar_t* name, LONG_PTR context) { | 
| 315   if (NULL == context) | 351   if (NULL == context) | 
| 316     return FALSE; | 352     return FALSE; | 
| 317 | 353 | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 388         !cmd_line.append(L"=\"") || | 424         !cmd_line.append(L"=\"") || | 
| 389         !cmd_line.append(setup_path->get()) || | 425         !cmd_line.append(setup_path->get()) || | 
| 390         !cmd_line.append(L"\"") || | 426         !cmd_line.append(L"\"") || | 
| 391         !cmd_line.append(kCmdNewSetupExe) || | 427         !cmd_line.append(kCmdNewSetupExe) || | 
| 392         !cmd_line.append(L"=\"") || | 428         !cmd_line.append(L"=\"") || | 
| 393         !cmd_line.append(setup_dest_path.get()) || | 429         !cmd_line.append(setup_dest_path.get()) || | 
| 394         !cmd_line.append(L"\"")) { | 430         !cmd_line.append(L"\"")) { | 
| 395       success = false; | 431       success = false; | 
| 396     } | 432     } | 
| 397 | 433 | 
|  | 434     // Get any command line option specified for mini_installer and pass them | 
|  | 435     // on to setup.exe.  This is important since switches such as | 
|  | 436     // --multi-install and --chrome-frame affect where setup.exe will write | 
|  | 437     // installer results for consumption by Google Update. | 
|  | 438     AppendCommandLineFlags(&cmd_line); | 
|  | 439 | 
| 398     int exit_code = 0; | 440     int exit_code = 0; | 
| 399     if (success && | 441     if (success && | 
| 400         (!RunProcessAndWait(NULL, cmd_line.get(), &exit_code) || | 442         (!RunProcessAndWait(NULL, cmd_line.get(), &exit_code) || | 
| 401          exit_code != ERROR_SUCCESS)) { | 443          exit_code != ERROR_SUCCESS)) { | 
| 402       success = false; | 444       success = false; | 
| 403     } | 445     } | 
| 404 | 446 | 
| 405     if (!success) | 447     if (!success) | 
| 406       DeleteFile(setup_path->get()); | 448       DeleteFile(setup_path->get()); | 
| 407 | 449 | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 448         setup_path->clear(); | 490         setup_path->clear(); | 
| 449       } else if (!setup_path->assign(setup_dest_path.get())) { | 491       } else if (!setup_path->assign(setup_dest_path.get())) { | 
| 450         ::DeleteFile(setup_dest_path.get()); | 492         ::DeleteFile(setup_dest_path.get()); | 
| 451       } | 493       } | 
| 452     } | 494     } | 
| 453   } | 495   } | 
| 454 | 496 | 
| 455   return setup_path->length() > 0; | 497   return setup_path->length() > 0; | 
| 456 } | 498 } | 
| 457 | 499 | 
| 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. | 500 // 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, | 501 bool RunSetup(const wchar_t* archive_path, const wchar_t* setup_path, | 
| 496               int* exit_code) { | 502               int* exit_code) { | 
| 497   // There could be three full paths in the command line for setup.exe (path | 503   // 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 | 504   // 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. | 505   // total size as three + one additional to hold command line options. | 
| 500   CommandString cmd_line; | 506   CommandString cmd_line; | 
| 501 | 507 | 
| 502   // Get the path to setup.exe first. | 508   // Get the path to setup.exe first. | 
| 503   if (::lstrlen(setup_path) > 0) { | 509   if (::lstrlen(setup_path) > 0) { | 
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 843     case 1: | 849     case 1: | 
| 844       dest8[count - 1] = c; | 850       dest8[count - 1] = c; | 
| 845   } | 851   } | 
| 846 | 852 | 
| 847   while (adjcount-- > 0)  // Copy the rest, 4 bytes/32 bits at a time | 853   while (adjcount-- > 0)  // Copy the rest, 4 bytes/32 bits at a time | 
| 848     *(dest32++) = fill; | 854     *(dest32++) = fill; | 
| 849 | 855 | 
| 850   return dest; | 856   return dest; | 
| 851 } | 857 } | 
| 852 }  // extern "C" | 858 }  // extern "C" | 
| OLD | NEW | 
|---|