Chromium Code Reviews| Index: cloud_print/virtual_driver/win/install/setup.cc |
| diff --git a/cloud_print/virtual_driver/win/install/setup.cc b/cloud_print/virtual_driver/win/install/setup.cc |
| index 6ee31096b7ef1338e3c5ccb0e44d16dd6548e1e6..119514a72ffa9c888fe7d1e95cbe92c1a5c7279a 100644 |
| --- a/cloud_print/virtual_driver/win/install/setup.cc |
| +++ b/cloud_print/virtual_driver/win/install/setup.cc |
| @@ -13,12 +13,56 @@ |
| #include "base/path_service.h" |
| #include "base/process_util.h" |
| #include "base/string16.h" |
| +#include "base/win/registry.h" |
| #include "base/win/scoped_handle.h" |
| #include "cloud_print/virtual_driver/win/virtual_driver_consts.h" |
| #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" |
| #include "grit/virtual_driver_setup_resources.h" |
| namespace { |
| +const wchar_t* kVersionKey = L"pv"; |
|
sanjeevr
2011/08/03 11:19:29
It is the norm in Chrome to use const wchar_t[] in
abeera
2011/08/03 19:50:30
Done.
|
| +const wchar_t* kNameKey = L"name"; |
| +const wchar_t* kLangKey = L"lang"; |
| + |
| +void SetRegistryKeys() { |
| + base::win::RegKey key; |
| + if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, |
| + KEY_ALL_ACCESS) != ERROR_SUCCESS) { |
|
sanjeevr
2011/08/03 11:19:29
You don't need KEY_ALL_ACCESS here. You just need
abeera
2011/08/03 19:50:30
Done.
|
| + LOG(ERROR) << "Unable to open key"; |
| + } |
| + |
| + // Get the version from the resource file. |
| + std::wstring version_string; |
| + scoped_ptr<FileVersionInfo> version_info( |
| + FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| + |
| + if (version_info.get()) { |
| + FileVersionInfoWin* version_info_win = |
| + static_cast<FileVersionInfoWin*>(version_info.get()); |
| + version_string = version_info_win->product_version(); |
| + } else { |
| + LOG(ERROR) << "Unable to get version string"; |
| + // Use a random version string so that Omaha has something to go by. |
| + version_string = L"0.0.0.99"; |
| + } |
| + |
| + if (key.WriteValue(kVersionKey, version_string.c_str()) != ERROR_SUCCESS || |
| + key.WriteValue(kNameKey, L"GCP Virtual Driver") != ERROR_SUCCESS || |
|
sanjeevr
2011/08/03 11:19:29
Why don't you create constant strings for these as
abeera
2011/08/03 19:50:30
Done.
|
| + key.WriteValue(kLangKey, L"en") != ERROR_SUCCESS) { |
| + LOG(ERROR) << "Unable to set registry keys"; |
| + } |
| +} |
| + |
| +void DeleteRegistryKeys() { |
| + base::win::RegKey key; |
| + if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kKeyLocation, |
| + KEY_ALL_ACCESS) != ERROR_SUCCESS) { |
|
sanjeevr
2011/08/03 11:19:29
Again you only need DELETE access. And you don't n
abeera
2011/08/03 19:50:30
Done.
|
| + LOG(ERROR) << "Unable to open key to delete"; |
| + } |
| + if (key.DeleteKey(L"") != ERROR_SUCCESS) { |
| + LOG(ERROR) << "Unable to delete key"; |
| + } |
| +} |
| HRESULT GetGpdPath(FilePath* path) { |
| if (!PathService::Get(base::DIR_EXE, path)) { |
| @@ -278,6 +322,7 @@ HRESULT InstallVirtualDriver(void) { |
| LOG(ERROR) << "Unable to install printer."; |
| return result; |
| } |
| + SetRegistryKeys(); |
| return S_OK; |
| } |
| @@ -298,6 +343,7 @@ HRESULT UninstallVirtualDriver(void) { |
| LOG(ERROR) << "Unable to remove port monitor."; |
| return result; |
| } |
| + DeleteRegistryKeys(); |
| return S_OK; |
| } |
| @@ -315,7 +361,8 @@ int WINAPI WinMain(__in HINSTANCE hInstance, |
| } else { |
| retval = InstallVirtualDriver(); |
| } |
| - if (!CommandLine::ForCurrentProcess()->HasSwitch("silent")) { |
| + // Installer is silent by default as required by Omaha. |
| + if (CommandLine::ForCurrentProcess()->HasSwitch("verbose")) { |
| cloud_print::DisplayWindowsMessage(NULL, retval, |
| cloud_print::LoadLocalString(IDS_DRIVER_NAME)); |
| } |