Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: cloud_print/virtual_driver/win/install/setup.cc

Issue 7532031: Changes to write various registry keys as required by Omaha for Windows Cloud Print Virtual Driver. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Make installer silent by default. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
27 void SetRegistryKeys() {
28 base::win::RegKey key;
29 if(key.Create(HKEY_LOCAL_MACHINE,cloud_print::kKeyLocation,
30 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
31 LOG(ERROR) << "Unable to open key";
32 }
33
34 // Get the version from the resource file.
35 std::wstring version_string;
36 scoped_ptr<FileVersionInfo> version_info(
37 FileVersionInfo::CreateFileVersionInfoForCurrentModule());
38
39 if (version_info.get()) {
40 FileVersionInfoWin* version_info_win =
41 static_cast<FileVersionInfoWin*>(version_info.get());
42 version_string = version_info_win->product_version();
43 }
44 else {
45 LOG(ERROR) << "Unable to get version string";
46 // Use a random version string so that Omaha has something to go by.
47 version_string = L"1.9.8.3";
Albert Bodenhamer 2011/07/29 21:43:48 Use 0.0.0.99 or something like it. 1.9.8.3 might
abeera 2011/07/29 21:53:41 Done.
48 }
49
50 if(key.WriteValue(kVersionKey,version_string.c_str()) != ERROR_SUCCESS ||
51 key.WriteValue(kNameKey,L"GCP Virtual Driver") != ERROR_SUCCESS ||
52 key.WriteValue(kLangKey,L"en") != ERROR_SUCCESS) {
53 LOG(ERROR) << "Unable to set registry keys";
54 }
55 }
56
57 void DeleteRegistryKeys() {
58 base::win::RegKey key;
59 if(key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation,
60 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
61 LOG(ERROR) << "Unable to open key to delete";
62 }
63 if(key.DeleteKey(L"") != ERROR_SUCCESS ) {
64 LOG(ERROR) << "Unable to delete key";
65 }
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698