| Index: cloud_print/service/win/cloud_print_service.cc
|
| diff --git a/cloud_print/service/win/cloud_print_service.cc b/cloud_print/service/win/cloud_print_service.cc
|
| index 2eeac75ad92f55ddbf4b28c4ff2742c78c839ab6..366ea2d8c5bda19a8ee2c3f9e2ced3fd4b9c0f94 100644
|
| --- a/cloud_print/service/win/cloud_print_service.cc
|
| +++ b/cloud_print/service/win/cloud_print_service.cc
|
| @@ -118,7 +118,7 @@ std::string GetOption(const std::string& name, const std::string& default,
|
| DWORD saved_mode = 0;
|
| // Don't close.
|
| HANDLE stdin_handle = ::GetStdHandle(STD_INPUT_HANDLE);
|
| - ::GetConsoleMode(stdin_handle, &saved_mode);
|
| + ::GetConsoleMode(stdin_handle, &saved_mode);
|
| ::SetConsoleMode(stdin_handle, saved_mode & ~ENABLE_ECHO_INPUT);
|
| std::getline(std::cin, tmp);
|
| ::SetConsoleMode(stdin_handle, saved_mode);
|
| @@ -148,11 +148,16 @@ class CloudPrintServiceModule
|
| return S_OK;
|
| }
|
|
|
| - HRESULT Install(const FilePath& user_data_dir) {
|
| + HRESULT InstallService(const FilePath& user_data_dir) {
|
| // TODO(vitalybuka): consider "lite" version if we don't want unregister
|
| // printers here.
|
| - if (!Uninstall())
|
| - return E_FAIL;
|
| + HRESULT hr = UninstallService();
|
| + if (FAILED(hr))
|
| + return hr;
|
| +
|
| + hr = UpdateRegistryAppId(true);
|
| + if (FAILED(hr))
|
| + return hr;
|
|
|
| FilePath service_path;
|
| CHECK(PathService::Get(base::FILE_EXE, &service_path));
|
| @@ -161,14 +166,14 @@ class CloudPrintServiceModule
|
| command_line.AppendSwitchPath(kUserDataDirSwitch, user_data_dir);
|
|
|
| ServiceHandle scm;
|
| - HRESULT hr = OpenServiceManager(&scm);
|
| + hr = OpenServiceManager(&scm);
|
| if (FAILED(hr))
|
| return hr;
|
|
|
| - ServiceHandle service(
|
| - ::CreateService(
|
| - scm, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS,
|
| - SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
| + ServiceHandle service(
|
| + ::CreateService(
|
| + scm, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS,
|
| + SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
| command_line.GetCommandLineString().c_str(), NULL, NULL, NULL,
|
| L"NT AUTHORITY\\LocalService", NULL));
|
|
|
| @@ -178,6 +183,12 @@ class CloudPrintServiceModule
|
| return S_OK;
|
| }
|
|
|
| + HRESULT UninstallService() {
|
| + if (!Uninstall())
|
| + return E_FAIL;
|
| + return UpdateRegistryAppId(false);
|
| + }
|
| +
|
| bool ParseCommandLine(LPCTSTR lpCmdLine, HRESULT* pnRetCode) {
|
| CHECK(pnRetCode);
|
| CommandLine command_line(CommandLine::NO_PROGRAM);
|
| @@ -220,7 +231,7 @@ class CloudPrintServiceModule
|
| return StopService();
|
|
|
| if (command_line.HasSwitch(kUninstallSwitch))
|
| - return Uninstall() ? S_OK : E_FAIL;
|
| + return UninstallService();
|
|
|
| if (command_line.HasSwitch(kInstallSwitch)) {
|
| if (!command_line.HasSwitch(kUserDataDirSwitch)) {
|
| @@ -233,7 +244,7 @@ class CloudPrintServiceModule
|
| command_line.HasSwitch(kQuietSwitch));
|
| if (FAILED(hr))
|
| return hr;
|
| - hr = Install(data_dir);
|
| + hr = InstallService(data_dir);
|
| if (SUCCEEDED(hr) && command_line.HasSwitch(kStartSwitch))
|
| return StartService();
|
|
|
| @@ -274,16 +285,18 @@ class CloudPrintServiceModule
|
| if (quiet)
|
| return is_valid ? S_OK : HRESULT_FROM_WIN32(ERROR_FILE_INVALID);
|
|
|
| - std::cout << "Do you want to use this file [y/n]:";
|
| - for (;;) {
|
| - std::string input;
|
| - std::getline(std::cin, input);
|
| - StringToLowerASCII(&input);
|
| - if (input == "y") {
|
| - return S_OK;
|
| - } else if (input == "n") {
|
| - is_valid = false;
|
| - break;
|
| + if (!contents.empty()) {
|
| + std::cout << "Do you want to use this file [y/n]:";
|
| + for (;;) {
|
| + std::string input;
|
| + std::getline(std::cin, input);
|
| + StringToLowerASCII(&input);
|
| + if (input == "y") {
|
| + return S_OK;
|
| + } else if (input == "n") {
|
| + is_valid = false;
|
| + break;
|
| + }
|
| }
|
| }
|
|
|
|
|