| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <setupapi.h> // Must be included after windows.h | 6 #include <setupapi.h> // Must be included after windows.h |
| 7 #include <winspool.h> | 7 #include <winspool.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 base::FilePath GetSystemPath(const base::string16& binary) { | 47 base::FilePath GetSystemPath(const base::string16& binary) { |
| 48 base::FilePath path; | 48 base::FilePath path; |
| 49 if (!PathService::Get(base::DIR_SYSTEM, &path)) { | 49 if (!PathService::Get(base::DIR_SYSTEM, &path)) { |
| 50 LOG(ERROR) << "Unable to get system path."; | 50 LOG(ERROR) << "Unable to get system path."; |
| 51 return path; | 51 return path; |
| 52 } | 52 } |
| 53 return path.Append(binary); | 53 return path.Append(binary); |
| 54 } | 54 } |
| 55 | 55 |
| 56 base::FilePath GetNativeSystemPath(const base::string16& binary) { |
| 57 if (!IsSystem64Bit()) |
| 58 return GetSystemPath(binary); |
| 59 base::FilePath path; |
| 60 // Sysnative will bypass filesystem redirection and give us |
| 61 // the location of the 64bit system32 from a 32 bit process. |
| 62 if (!PathService::Get(base::DIR_WINDOWS, &path)) { |
| 63 LOG(ERROR) << "Unable to get windows path."; |
| 64 return path; |
| 65 } |
| 66 return path.Append(L"sysnative").Append(binary); |
| 67 } |
| 68 |
| 56 void SpoolerServiceCommand(const char* command) { | 69 void SpoolerServiceCommand(const char* command) { |
| 57 base::FilePath net_path = GetSystemPath(L"net"); | 70 base::FilePath net_path = GetNativeSystemPath(L"net"); |
| 58 if (net_path.empty()) | 71 if (net_path.empty()) |
| 59 return; | 72 return; |
| 60 base::CommandLine command_line(net_path); | 73 base::CommandLine command_line(net_path); |
| 61 command_line.AppendArg(command); | 74 command_line.AppendArg(command); |
| 62 command_line.AppendArg("spooler"); | 75 command_line.AppendArg("spooler"); |
| 63 command_line.AppendArg("/y"); | 76 command_line.AppendArg("/y"); |
| 64 | 77 |
| 65 base::LaunchOptions options; | 78 base::LaunchOptions options; |
| 66 options.wait = true; | 79 options.wait = true; |
| 67 options.start_hidden = true; | 80 options.start_hidden = true; |
| 68 VLOG(0) << command_line.GetCommandLineString(); | 81 VLOG(0) << command_line.GetCommandLineString(); |
| 69 base::LaunchProcess(command_line, options); | 82 base::LaunchProcess(command_line, options); |
| 70 } | 83 } |
| 71 | 84 |
| 72 HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) { | 85 HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) { |
| 73 DCHECK(install || install_path.empty()); | 86 DCHECK(install || install_path.empty()); |
| 74 base::FilePath target_path = GetSystemPath(L"gcp_portmon.dll"); | 87 base::FilePath target_path = GetNativeSystemPath(GetPortMonitorDllName()); |
| 75 if (target_path.empty()) { | 88 if (target_path.empty()) { |
| 76 LOG(ERROR) << "Unable to get port monitor target path."; | 89 LOG(ERROR) << "Unable to get port monitor target path."; |
| 77 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); | 90 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); |
| 78 } | 91 } |
| 79 if (install) { | 92 if (install) { |
| 80 base::FilePath source_path = install_path.Append(L"gcp_portmon.dll"); | 93 base::FilePath source_path = install_path.Append(GetPortMonitorDllName()); |
| 81 if (!base::CopyFile(source_path, target_path)) { | 94 if (!base::CopyFile(source_path, target_path)) { |
| 82 LOG(ERROR) << "Unable copy port monitor dll from " << source_path.value() | 95 LOG(ERROR) << "Unable copy port monitor dll from " << source_path.value() |
| 83 << " to " << target_path.value(); | 96 << " to " << target_path.value(); |
| 84 return GetLastHResult(); | 97 return GetLastHResult(); |
| 85 } | 98 } |
| 86 } else if (!base::PathExists(target_path)) { | 99 } else if (!base::PathExists(target_path)) { |
| 87 // Already removed. Just "succeed" silently. | 100 // Already removed. Just "succeed" silently. |
| 88 return S_OK; | 101 return S_OK; |
| 89 } | 102 } |
| 90 | 103 |
| 91 base::FilePath regsvr32_path = GetSystemPath(L"regsvr32.exe"); | 104 base::FilePath regsvr32_path = GetNativeSystemPath(L"regsvr32.exe"); |
| 92 if (regsvr32_path.empty()) { | 105 if (regsvr32_path.empty()) { |
| 93 LOG(ERROR) << "Can't find regsvr32.exe."; | 106 LOG(ERROR) << "Can't find regsvr32.exe."; |
| 94 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); | 107 return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); |
| 95 } | 108 } |
| 96 | 109 |
| 97 base::CommandLine command_line(regsvr32_path); | 110 base::CommandLine command_line(regsvr32_path); |
| 98 command_line.AppendArg("/s"); | 111 command_line.AppendArg("/s"); |
| 99 if (!install) { | 112 if (!install) { |
| 100 command_line.AppendArg("/u"); | 113 command_line.AppendArg("/u"); |
| 101 } | 114 } |
| 102 | 115 |
| 103 // Use system32 path here because otherwise ::AddMonitor would fail. | 116 // Use system32 path here because otherwise ::AddMonitor would fail. |
| 104 command_line.AppendArgPath(GetSystemPath(L"gcp_portmon.dll")); | 117 command_line.AppendArgPath(GetSystemPath(GetPortMonitorDllName())); |
| 105 | 118 |
| 106 base::LaunchOptions options; | 119 base::LaunchOptions options; |
| 107 options.wait = true; | 120 options.wait = true; |
| 108 | 121 |
| 109 base::Process regsvr32_process = | 122 base::Process regsvr32_process = |
| 110 base::LaunchProcess(command_line.GetCommandLineString(), options); | 123 base::LaunchProcess(command_line.GetCommandLineString(), options); |
| 111 if (!regsvr32_process.IsValid()) { | 124 if (!regsvr32_process.IsValid()) { |
| 112 LOG(ERROR) << "Unable to launch regsvr32.exe."; | 125 LOG(ERROR) << "Unable to launch regsvr32.exe."; |
| 113 return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); | 126 return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); |
| 114 } | 127 } |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 425 |
| 413 VLOG(0) << GetErrorMessage(retval) << " HRESULT=0x" << std::setbase(16) | 426 VLOG(0) << GetErrorMessage(retval) << " HRESULT=0x" << std::setbase(16) |
| 414 << retval; | 427 << retval; |
| 415 | 428 |
| 416 // Installer is silent by default as required by Google Update. | 429 // Installer is silent by default as required by Google Update. |
| 417 if (base::CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { | 430 if (base::CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { |
| 418 DisplayWindowsMessage(NULL, retval, LoadLocalString(IDS_DRIVER_NAME)); | 431 DisplayWindowsMessage(NULL, retval, LoadLocalString(IDS_DRIVER_NAME)); |
| 419 } | 432 } |
| 420 return retval; | 433 return retval; |
| 421 } | 434 } |
| OLD | NEW |