| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <iomanip> | 5 #include <iomanip> |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #include <winspool.h> | 7 #include <winspool.h> |
| 8 #include <setupapi.h> // Must be included after windows.h | 8 #include <setupapi.h> // Must be included after windows.h |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 const wchar_t kDriverName[] = L"MXDWDRV.DLL"; | 34 const wchar_t kDriverName[] = L"MXDWDRV.DLL"; |
| 35 const wchar_t kUiDriverName[] = L"PS5UI.DLL"; | 35 const wchar_t kUiDriverName[] = L"PS5UI.DLL"; |
| 36 const wchar_t kHelpName[] = L"PSCRIPT.HLP"; | 36 const wchar_t kHelpName[] = L"PSCRIPT.HLP"; |
| 37 const wchar_t* kDependencyList[] = {kDriverName, kUiDriverName, kHelpName}; | 37 const wchar_t* kDependencyList[] = {kDriverName, kUiDriverName, kHelpName}; |
| 38 const wchar_t kUninstallRegistry[] = | 38 const wchar_t kUninstallRegistry[] = |
| 39 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" | 39 L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" |
| 40 L"{74AA24E0-AC50-4B28-BA46-9CF05467C9B7}"; | 40 L"{74AA24E0-AC50-4B28-BA46-9CF05467C9B7}"; |
| 41 const wchar_t kInstallerName[] = L"virtual_driver_setup.exe"; | 41 const wchar_t kInstallerName[] = L"virtual_driver_setup.exe"; |
| 42 const wchar_t kGcpUrl[] = L"http://www.google.com/cloudprint"; | 42 const wchar_t kGcpUrl[] = L"http://www.google.com/cloudprint"; |
| 43 | 43 |
| 44 const char kDoUninstallSwitch[] = "douninstall"; | 44 const char kDelete[] = "delete"; |
| 45 const char kInstallSwitch[] = "install"; | 45 const char kInstallSwitch[] = "install"; |
| 46 const char kRegisterSwitch[] = "register"; | 46 const char kRegisterSwitch[] = "register"; |
| 47 const char kUninstallSwitch[] = "uninstall"; | 47 const char kUninstallSwitch[] = "uninstall"; |
| 48 const char kUnregisterSwitch[] = "unregister"; | 48 const char kUnregisterSwitch[] = "unregister"; |
| 49 | 49 |
| 50 void SetGoogleUpdateKeys() { | 50 void SetGoogleUpdateKeys() { |
| 51 base::win::RegKey key; | 51 base::win::RegKey key; |
| 52 if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, | 52 if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, |
| 53 KEY_SET_VALUE) != ERROR_SUCCESS) { | 53 KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 54 LOG(ERROR) << "Unable to open key"; | 54 LOG(ERROR) << "Unable to open key"; |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 if (SUCCEEDED(hr)) { | 509 if (SUCCEEDED(hr)) { |
| 510 break; | 510 break; |
| 511 } | 511 } |
| 512 // Restart spooler and try again. | 512 // Restart spooler and try again. |
| 513 SpoolerServiceCommand("stop"); | 513 SpoolerServiceCommand("stop"); |
| 514 SpoolerServiceCommand("start"); | 514 SpoolerServiceCommand("start"); |
| 515 } | 515 } |
| 516 return hr; | 516 return hr; |
| 517 } | 517 } |
| 518 | 518 |
| 519 HRESULT DoLaunchUninstall(const FilePath& installer_source, bool wait) { | 519 HRESULT DeleteProgramDir(const FilePath& installer_source, bool wait) { |
| 520 FilePath temp_path; | 520 FilePath temp_path; |
| 521 if (file_util::CreateTemporaryFile(&temp_path)) { | 521 if (file_util::CreateTemporaryFile(&temp_path)) { |
| 522 file_util::CopyFile(installer_source, temp_path); | 522 file_util::CopyFile(installer_source, temp_path); |
| 523 file_util::DeleteAfterReboot(temp_path); | 523 file_util::DeleteAfterReboot(temp_path); |
| 524 CommandLine command_line(temp_path); | 524 CommandLine command_line(temp_path); |
| 525 command_line.AppendArg(kDoUninstallSwitch); | 525 command_line.AppendSwitchPath(kDelete, installer_source.DirName()); |
| 526 base::LaunchOptions options; | 526 base::LaunchOptions options; |
| 527 options.wait = wait; | 527 options.wait = wait; |
| 528 base::ProcessHandle process_handle; | 528 base::ProcessHandle process_handle; |
| 529 if (!base::LaunchProcess(command_line, options, &process_handle)) { | 529 if (!base::LaunchProcess(command_line, options, &process_handle)) { |
| 530 LOG(ERROR) << "Unable to launch child uninstall."; | 530 LOG(ERROR) << "Unable to launch child uninstall."; |
| 531 return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); | 531 return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); |
| 532 } | 532 } |
| 533 if (wait) { | 533 if (wait) { |
| 534 int exit_code = -1; | 534 int exit_code = -1; |
| 535 base::TerminationStatus status = | 535 base::TerminationStatus status = |
| 536 base::GetTerminationStatus(process_handle, &exit_code); | 536 base::GetTerminationStatus(process_handle, &exit_code); |
| 537 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) { | 537 if (status == base::TERMINATION_STATUS_NORMAL_TERMINATION) { |
| 538 return exit_code; | 538 return exit_code; |
| 539 } else { | 539 } else { |
| 540 LOG(ERROR) << "Improper termination of uninstall. " << status; | 540 LOG(ERROR) << "Improper termination of uninstall. " << status; |
| 541 return E_FAIL; | 541 return E_FAIL; |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 return S_OK; | 545 return S_OK; |
| 546 } | 546 } |
| 547 | 547 |
| 548 HRESULT LaunchChildForUninstall() { | 548 HRESULT DoUninstall() { |
| 549 DeleteGoogleUpdateKeys(); |
| 550 HRESULT result = UnregisterVirtualDriver(); |
| 551 if (FAILED(result)) |
| 552 return result; |
| 553 CleanupUninstall(); |
| 549 FilePath installer_source; | 554 FilePath installer_source; |
| 550 if (PathService::Get(base::FILE_EXE, &installer_source)) { | 555 if (PathService::Get(base::FILE_EXE, &installer_source)) |
| 551 return DoLaunchUninstall(installer_source, false); | 556 return DeleteProgramDir(installer_source, false); |
| 552 } | |
| 553 return S_OK; | 557 return S_OK; |
| 554 } | 558 } |
| 555 | 559 |
| 556 HRESULT DoUnregister() { | 560 HRESULT DoUnregister() { |
| 557 return UnregisterVirtualDriver(); | 561 return UnregisterVirtualDriver(); |
| 558 } | 562 } |
| 559 | 563 |
| 560 HRESULT DoRegister(const FilePath& install_path) { | 564 HRESULT DoRegister(const FilePath& install_path) { |
| 561 HRESULT result = UnregisterVirtualDriver(); | 565 HRESULT result = UnregisterVirtualDriver(); |
| 562 if (FAILED(result)) | 566 if (FAILED(result)) |
| 563 return result; | 567 return result; |
| 564 return RegisterVirtualDriver(install_path); | 568 return RegisterVirtualDriver(install_path); |
| 565 } | 569 } |
| 566 | 570 |
| 567 HRESULT DoUninstall() { | 571 HRESULT DoDelete(const FilePath& install_path) { |
| 568 FilePath install_path; | 572 if (install_path.value().empty()) |
| 569 GetCurrentInstallPath(&install_path); | 573 return E_INVALIDARG; |
| 570 if (install_path.value().empty()) { | 574 if (!file_util::DirectoryExists(install_path)) |
| 571 return S_FALSE; | 575 return S_FALSE; |
| 572 } | 576 Sleep(5000); // Give parent some time to exit. |
| 573 HRESULT result = UnregisterVirtualDriver(); | 577 return file_util::Delete(install_path, true) ? S_OK : E_FAIL; |
| 574 if (FAILED(result)) | |
| 575 return result; | |
| 576 DeleteGoogleUpdateKeys(); | |
| 577 if (file_util::DirectoryExists(install_path)) | |
| 578 file_util::Delete(install_path, true); | |
| 579 CleanupUninstall(); | |
| 580 return result; | |
| 581 } | 578 } |
| 582 | 579 |
| 583 HRESULT DoInstall(const FilePath& install_path) { | 580 HRESULT DoInstall(const FilePath& install_path) { |
| 584 HRESULT result = UnregisterVirtualDriver(); | 581 HRESULT result = UnregisterVirtualDriver(); |
| 585 if (FAILED(result)) { | 582 if (FAILED(result)) { |
| 586 LOG(ERROR) << "Unable to unregister."; | 583 LOG(ERROR) << "Unable to unregister."; |
| 587 return result; | 584 return result; |
| 588 } | 585 } |
| 589 FilePath old_install_path; | 586 FilePath old_install_path; |
| 590 GetCurrentInstallPath(&old_install_path); | 587 GetCurrentInstallPath(&old_install_path); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 603 | 600 |
| 604 HRESULT ExecuteCommands() { | 601 HRESULT ExecuteCommands() { |
| 605 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 602 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 606 | 603 |
| 607 FilePath exe_path; | 604 FilePath exe_path; |
| 608 if (FAILED(PathService::Get(base::DIR_EXE, &exe_path)) || | 605 if (FAILED(PathService::Get(base::DIR_EXE, &exe_path)) || |
| 609 !file_util::DirectoryExists(exe_path)) { | 606 !file_util::DirectoryExists(exe_path)) { |
| 610 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); | 607 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); |
| 611 } | 608 } |
| 612 | 609 |
| 613 if (command_line.HasSwitch(kDoUninstallSwitch)) { | 610 if (command_line.HasSwitch(kDelete)) { |
| 611 return DoDelete(command_line.GetSwitchValuePath(kDelete)); |
| 612 } else if (command_line.HasSwitch(kUninstallSwitch)) { |
| 614 return DoUninstall(); | 613 return DoUninstall(); |
| 615 } else if (command_line.HasSwitch(kUninstallSwitch)) { | |
| 616 return LaunchChildForUninstall(); | |
| 617 } else if (command_line.HasSwitch(kInstallSwitch)) { | 614 } else if (command_line.HasSwitch(kInstallSwitch)) { |
| 618 return DoInstall(exe_path); | 615 return DoInstall(exe_path); |
| 619 } else if (command_line.HasSwitch(kUnregisterSwitch)) { | 616 } else if (command_line.HasSwitch(kUnregisterSwitch)) { |
| 620 return DoUnregister(); | 617 return DoUnregister(); |
| 621 } else if (command_line.HasSwitch(kRegisterSwitch)) { | 618 } else if (command_line.HasSwitch(kRegisterSwitch)) { |
| 622 return DoRegister(exe_path); | 619 return DoRegister(exe_path); |
| 623 } | 620 } |
| 624 | 621 |
| 625 return E_INVALIDARG; | 622 return E_INVALIDARG; |
| 626 } | 623 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 637 | 634 |
| 638 LOG(INFO) << "HRESULT=0x" << std::setbase(16) << retval; | 635 LOG(INFO) << "HRESULT=0x" << std::setbase(16) << retval; |
| 639 | 636 |
| 640 // Installer is silent by default as required by Google Update. | 637 // Installer is silent by default as required by Google Update. |
| 641 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { | 638 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { |
| 642 cloud_print::DisplayWindowsMessage(NULL, retval, | 639 cloud_print::DisplayWindowsMessage(NULL, retval, |
| 643 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); | 640 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); |
| 644 } | 641 } |
| 645 return retval; | 642 return retval; |
| 646 } | 643 } |
| OLD | NEW |