| 416 | } |
| 417 | |
| 418 | int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) |
| 419 | { |
| 420 | Win32ProgressCallback progress; |
| 421 | |
| 422 | wil::unique_couninitialize_call uninit = wil::CoInitializeEx_failfast(COINIT_MULTITHREADED); |
| 423 | |
| 424 | int argc = 0; |
| 425 | wil::unique_hlocal_ptr<LPWSTR[]> argv(CommandLineToArgvW(GetCommandLineW(), &argc)); |
| 426 | if (!argv || argc <= 0) |
| 427 | { |
| 428 | progress.ModalError("Failed to parse command line."); |
| 429 | return 1; |
| 430 | } |
| 431 | if (argc != 5) |
| 432 | { |
| 433 | progress.ModalError("Expected 4 arguments: parent process id, output directory, update zip, program to " |
| 434 | "launch.\n\nThis program is not intended to be run manually, please use the main PCSX2 application and " |
| 435 | "click Help->Check for Updates."); |
| 436 | return 1; |
| 437 | } |
| 438 | |
| 439 | const int parent_process_id = StringUtil::FromChars<int>(StringUtil::WideStringToUTF8String(argv[1])).value_or(0); |
| 440 | const std::string destination_directory = StringUtil::WideStringToUTF8String(argv[2]); |
| 441 | const std::string zip_path = StringUtil::WideStringToUTF8String(argv[3]); |
| 442 | const std::wstring program_to_launch(argv[4]); |
| 443 | argv.reset(); |
| 444 | |
| 445 | if (parent_process_id <= 0 || destination_directory.empty() || zip_path.empty() || program_to_launch.empty()) |
| 446 | { |
| 447 | progress.ModalError("One or more parameters is empty."); |
| 448 | return 1; |
| 449 | } |
| 450 | |
| 451 | Updater::SetupLogging(&progress, destination_directory); |
| 452 | Updater updater(&progress); |
| 453 | |
| 454 | progress.SetFormattedStatusText("Waiting for parent process %d to exit...", parent_process_id); |
| 455 | progress.SetProgressState(ProgressCallback::ProgressState::Indeterminate); |
| 456 | WaitForProcessToExit(parent_process_id); |
| 457 | |
| 458 | if (!updater.Initialize(destination_directory)) |
| 459 | { |
| 460 | progress.ModalError("Failed to initialize updater."); |
| 461 | return 1; |
| 462 | } |
| 463 | |
| 464 | if (!updater.OpenUpdateZip(zip_path.c_str())) |
| 465 | { |
| 466 | progress.DisplayFormattedModalError("Could not open update zip '%s'. Update not installed.", zip_path.c_str()); |
| 467 | return 1; |
| 468 | } |
| 469 | |
| 470 | if (!updater.PrepareStagingDirectory()) |
| 471 | { |
| 472 | progress.ModalError("Failed to prepare staging directory. Update not installed."); |
| 473 | return 1; |
| 474 | } |
| 475 |
nothing calls this directly
no test coverage detected