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) { | |
sanjeevr
2011/08/08 07:51:32
Nit: Indentation.
| |
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 GetGpdPath(FilePath* path) { | 69 HRESULT GetGpdPath(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.gpd"); | 74 *path = path->Append(L"gcp.gpd"); |
29 return S_OK; | 75 return S_OK; |
30 } | 76 } |
31 | 77 |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 result = InstallGpd(); | 317 result = InstallGpd(); |
272 if (!SUCCEEDED(result)) { | 318 if (!SUCCEEDED(result)) { |
273 LOG(ERROR) << "Unable to install gpd."; | 319 LOG(ERROR) << "Unable to install gpd."; |
274 return result; | 320 return result; |
275 } | 321 } |
276 result = InstallPrinter(); | 322 result = InstallPrinter(); |
277 if (!SUCCEEDED(result)) { | 323 if (!SUCCEEDED(result)) { |
278 LOG(ERROR) << "Unable to install printer."; | 324 LOG(ERROR) << "Unable to install printer."; |
279 return result; | 325 return result; |
280 } | 326 } |
327 SetRegistryKeys(); | |
281 return S_OK; | 328 return S_OK; |
282 } | 329 } |
283 | 330 |
284 HRESULT UninstallVirtualDriver(void) { | 331 HRESULT UninstallVirtualDriver(void) { |
285 HRESULT result = S_OK; | 332 HRESULT result = S_OK; |
286 result = UninstallPrinter(); | 333 result = UninstallPrinter(); |
287 if (!SUCCEEDED(result)) { | 334 if (!SUCCEEDED(result)) { |
288 LOG(ERROR) << "Unable to uninstall gpd."; | 335 LOG(ERROR) << "Unable to uninstall gpd."; |
289 return result; | 336 return result; |
290 } | 337 } |
291 result = UninstallGpd(); | 338 result = UninstallGpd(); |
292 if (!SUCCEEDED(result)) { | 339 if (!SUCCEEDED(result)) { |
293 LOG(ERROR) << "Unable to remove gpd."; | 340 LOG(ERROR) << "Unable to remove gpd."; |
294 return result; | 341 return result; |
295 } | 342 } |
296 result = RegisterPortMonitor(false); | 343 result = RegisterPortMonitor(false); |
297 if (!SUCCEEDED(result)) { | 344 if (!SUCCEEDED(result)) { |
298 LOG(ERROR) << "Unable to remove port monitor."; | 345 LOG(ERROR) << "Unable to remove port monitor."; |
299 return result; | 346 return result; |
300 } | 347 } |
348 DeleteRegistryKeys(); | |
301 return S_OK; | 349 return S_OK; |
302 } | 350 } |
303 | 351 |
304 } // namespace | 352 } // namespace |
305 | 353 |
306 int WINAPI WinMain(__in HINSTANCE hInstance, | 354 int WINAPI WinMain(__in HINSTANCE hInstance, |
307 __in HINSTANCE hPrevInstance, | 355 __in HINSTANCE hPrevInstance, |
308 __in LPSTR lpCmdLine, | 356 __in LPSTR lpCmdLine, |
309 __in int nCmdShow) { | 357 __in int nCmdShow) { |
310 base::AtExitManager at_exit_manager; | 358 base::AtExitManager at_exit_manager; |
311 CommandLine::Init(0, NULL); | 359 CommandLine::Init(0, NULL); |
312 HRESULT retval = S_OK; | 360 HRESULT retval = S_OK; |
313 if (CommandLine::ForCurrentProcess()->HasSwitch("uninstall")) { | 361 if (CommandLine::ForCurrentProcess()->HasSwitch("uninstall")) { |
314 retval = UninstallVirtualDriver(); | 362 retval = UninstallVirtualDriver(); |
315 } else { | 363 } else { |
316 retval = InstallVirtualDriver(); | 364 retval = InstallVirtualDriver(); |
317 } | 365 } |
318 if (!CommandLine::ForCurrentProcess()->HasSwitch("silent")) { | 366 // Installer is silent by default as required by Omaha. |
367 if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { | |
319 cloud_print::DisplayWindowsMessage(NULL, retval, | 368 cloud_print::DisplayWindowsMessage(NULL, retval, |
320 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); | 369 cloud_print::LoadLocalString(IDS_DRIVER_NAME)); |
321 } | 370 } |
322 return retval; | 371 return retval; |
323 } | 372 } |
324 | 373 |
OLD | NEW |