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 #include <windows.h> | 5 #include <windows.h> |
6 #include <winspool.h> | 6 #include <winspool.h> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/file_version_info_win.h" | 11 #include "base/file_version_info_win.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/win/registry.h" |
16 #include "base/win/scoped_handle.h" | 17 #include "base/win/scoped_handle.h" |
17 #include "cloud_print/virtual_driver/win/virtual_driver_consts.h" | 18 #include "cloud_print/virtual_driver/win/virtual_driver_consts.h" |
18 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" | 19 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" |
19 #include "grit/virtual_driver_setup_resources.h" | 20 #include "grit/virtual_driver_setup_resources.h" |
20 | 21 |
21 namespace { | 22 namespace { |
| 23 const wchar_t kVersionKey[] = L"pv"; |
| 24 const wchar_t kNameKey[] = L"name"; |
| 25 const wchar_t kLangKey[] = L"lang"; |
| 26 const wchar_t kNameValue[] = L"GCP Virtual Driver"; |
| 27 const wchar_t kLangValue[] = L"rn"; |
| 28 |
| 29 void SetRegistryKeys() { |
| 30 base::win::RegKey key; |
| 31 if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, |
| 32 KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 33 LOG(ERROR) << "Unable to open key"; |
| 34 } |
| 35 |
| 36 // Get the version from the resource file. |
| 37 std::wstring version_string; |
| 38 scoped_ptr<FileVersionInfo> version_info( |
| 39 FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 40 |
| 41 if (version_info.get()) { |
| 42 FileVersionInfoWin* version_info_win = |
| 43 static_cast<FileVersionInfoWin*>(version_info.get()); |
| 44 version_string = version_info_win->product_version(); |
| 45 } else { |
| 46 LOG(ERROR) << "Unable to get version string"; |
| 47 // Use a random version string so that Omaha has something to go by. |
| 48 version_string = L"0.0.0.99"; |
| 49 } |
| 50 |
| 51 if (key.WriteValue(kVersionKey, version_string.c_str()) != ERROR_SUCCESS || |
| 52 key.WriteValue(kNameKey, kNameValue) != ERROR_SUCCESS || |
| 53 key.WriteValue(kLangKey, kLangValue) != ERROR_SUCCESS) { |
| 54 LOG(ERROR) << "Unable to set registry keys"; |
| 55 } |
| 56 } |
| 57 |
| 58 void DeleteRegistryKeys() { |
| 59 base::win::RegKey key; |
| 60 if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, |
| 61 DELETE) != ERROR_SUCCESS) { |
| 62 LOG(ERROR) << "Unable to open key to delete"; |
| 63 } |
| 64 if (key.DeleteKey(L"") != ERROR_SUCCESS) { |
| 65 LOG(ERROR) << "Unable to delete key"; |
| 66 } |
| 67 } |
22 | 68 |
23 HRESULT GetPpdPath(FilePath* path) { | 69 HRESULT GetPpdPath(FilePath* path) { |
24 if (!PathService::Get(base::DIR_EXE, path)) { | 70 if (!PathService::Get(base::DIR_EXE, path)) { |
25 LOG(ERROR) << "Unable to get install path."; | 71 LOG(ERROR) << "Unable to get install path."; |
26 return ERROR_PATH_NOT_FOUND; | 72 return ERROR_PATH_NOT_FOUND; |
27 } | 73 } |
28 *path = path->Append(L"GCP-driver.ppd"); | 74 *path = path->Append(L"GCP-driver.ppd"); |
29 return S_OK; | 75 return S_OK; |
30 } | 76 } |
31 | 77 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 result = InstallPpd(); | 319 result = InstallPpd(); |
274 if (!SUCCEEDED(result)) { | 320 if (!SUCCEEDED(result)) { |
275 LOG(ERROR) << "Unable to install Ppd."; | 321 LOG(ERROR) << "Unable to install Ppd."; |
276 return result; | 322 return result; |
277 } | 323 } |
278 result = InstallPrinter(); | 324 result = InstallPrinter(); |
279 if (!SUCCEEDED(result)) { | 325 if (!SUCCEEDED(result)) { |
280 LOG(ERROR) << "Unable to install printer."; | 326 LOG(ERROR) << "Unable to install printer."; |
281 return result; | 327 return result; |
282 } | 328 } |
| 329 SetRegistryKeys(); |
283 return S_OK; | 330 return S_OK; |
284 } | 331 } |
285 | 332 |
286 HRESULT UninstallVirtualDriver(void) { | 333 HRESULT UninstallVirtualDriver(void) { |
287 HRESULT result = S_OK; | 334 HRESULT result = S_OK; |
288 result = UninstallPrinter(); | 335 result = UninstallPrinter(); |
289 if (!SUCCEEDED(result)) { | 336 if (!SUCCEEDED(result)) { |
290 LOG(ERROR) << "Unable to uninstall Ppd."; | 337 LOG(ERROR) << "Unable to uninstall Ppd."; |
291 return result; | 338 return result; |
292 } | 339 } |
293 result = UninstallPpd(); | 340 result = UninstallPpd(); |
294 if (!SUCCEEDED(result)) { | 341 if (!SUCCEEDED(result)) { |
295 LOG(ERROR) << "Unable to remove Ppd."; | 342 LOG(ERROR) << "Unable to remove Ppd."; |
296 return result; | 343 return result; |
297 } | 344 } |
298 result = RegisterPortMonitor(false); | 345 result = RegisterPortMonitor(false); |
299 if (!SUCCEEDED(result)) { | 346 if (!SUCCEEDED(result)) { |
300 LOG(ERROR) << "Unable to remove port monitor."; | 347 LOG(ERROR) << "Unable to remove port monitor."; |
301 return result; | 348 return result; |
302 } | 349 } |
| 350 DeleteRegistryKeys(); |
303 return S_OK; | 351 return S_OK; |
304 } | 352 } |
305 | 353 |
306 } // namespace | 354 } // namespace |
307 | 355 |
308 int WINAPI WinMain(__in HINSTANCE hInstance, | 356 int WINAPI WinMain(__in HINSTANCE hInstance, |
309 __in HINSTANCE hPrevInstance, | 357 __in HINSTANCE hPrevInstance, |
310 __in LPSTR lpCmdLine, | 358 __in LPSTR lpCmdLine, |
311 __in int nCmdShow) { | 359 __in int nCmdShow) { |
312 base::AtExitManager at_exit_manager; | 360 base::AtExitManager at_exit_manager; |
313 CommandLine::Init(0, NULL); | 361 CommandLine::Init(0, NULL); |
314 HRESULT retval = S_OK; | 362 HRESULT retval = S_OK; |
315 if (CommandLine::ForCurrentProcess()->HasSwitch("uninstall")) { | 363 if (CommandLine::ForCurrentProcess()->HasSwitch("uninstall")) { |
316 retval = UninstallVirtualDriver(); | 364 retval = UninstallVirtualDriver(); |
317 } else { | 365 } else { |
318 retval = InstallVirtualDriver(); | 366 retval = InstallVirtualDriver(); |
319 } | 367 } |
320 if (!CommandLine::ForCurrentProcess()->HasSwitch("silent")) { | 368 // Installer is silent by default as required by Omaha. |
| 369 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { |
321 cloud_print::DisplayWindowsMessage(NULL, retval, | 370 cloud_print::DisplayWindowsMessage(NULL, retval, |
322 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); | 371 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); |
323 } | 372 } |
324 return retval; | 373 return retval; |
325 } | 374 } |
OLD | NEW |