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

Unified Diff: cloud_print/virtual_driver/win/install/setup.cc

Issue 14107007: Moved Google Update and install related code to cloud_print/common (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
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 df7eb57fe7044f08c96c43e0bbaf4501a0727e31..fbc297ea75d751f5d6eb4bbaecbe3dd537beb055 100644
--- a/cloud_print/virtual_driver/win/install/setup.cc
+++ b/cloud_print/virtual_driver/win/install/setup.cc
@@ -23,6 +23,7 @@
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#include "cloud_print/common/win/cloud_print_utils.h"
+#include "cloud_print/common/win/install_utils.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"
@@ -30,12 +31,12 @@
#include <strsafe.h> // Must be after base headers to avoid deprecation
// warnings.
+namespace cloud_print {
+
namespace {
const wchar_t kNameValue[] = L"GCP Virtual Driver";
-const wchar_t kUninstallRegistry[] =
- L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
- L"{74AA24E0-AC50-4B28-BA46-9CF05467C9B7}";
+const wchar_t kUninstallId[] = L"{74AA24E0-AC50-4B28-BA46-9CF05467C9B7}";
const wchar_t kInstallerName[] = L"virtual_driver_setup.exe";
const wchar_t kGcpUrl[] = L"http://www.google.com/cloudprint";
@@ -62,69 +63,6 @@ const char kRegisterSwitch[] = "register";
const char kUninstallSwitch[] = "uninstall";
const char kUnregisterSwitch[] = "unregister";
-// Google update related constants.
-const wchar_t kVersionKey[] = L"pv";
-const wchar_t kNameKey[] = L"name";
-const DWORD kInstallerResultFailedCustomError = 1;
-const wchar_t kRegValueInstallerResult[] = L"InstallerResult";
-const wchar_t kRegValueInstallerResultUIString[] = L"InstallerResultUIString";
-
-void SetGoogleUpdateKeys() {
- base::win::RegKey key;
- if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientsKey,
- KEY_SET_VALUE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key";
- }
-
- // Get the version from the resource file.
- string16 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 Google Update 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, kNameValue) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to set registry keys";
- }
-}
-
-void SetGoogleUpdateError(const string16& message) {
- LOG(ERROR) << message;
- base::win::RegKey key;
- if (key.Create(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientStateKey,
- KEY_SET_VALUE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key";
- }
-
- if (key.WriteValue(kRegValueInstallerResult,
- kInstallerResultFailedCustomError) != ERROR_SUCCESS ||
- key.WriteValue(kRegValueInstallerResultUIString,
- message.c_str()) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to set registry keys";
- }
-}
-
-void DeleteGoogleUpdateKeys() {
- base::win::RegKey key;
- if (key.Open(HKEY_LOCAL_MACHINE, cloud_print::kGoogleUpdateClientsKey,
- DELETE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key to delete";
- return;
- }
- if (key.DeleteKey(L"") != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to delete key";
- }
-}
-
base::FilePath GetSystemPath(const string16& binary) {
base::FilePath path;
if (!PathService::Get(base::DIR_SYSTEM, &path)) {
@@ -135,7 +73,7 @@ base::FilePath GetSystemPath(const string16& binary) {
}
base::FilePath GetNativeSystemPath(const string16& binary) {
- if (!cloud_print::IsSystem64Bit())
+ if (!IsSystem64Bit())
return GetSystemPath(binary);
base::FilePath path;
// Sysnative will bypass filesystem redirection and give us
@@ -165,19 +103,18 @@ void SpoolerServiceCommand(const char* command) {
HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
DCHECK(install || install_path.empty());
- base::FilePath target_path =
- GetNativeSystemPath(cloud_print::GetPortMonitorDllName());
+ base::FilePath target_path = GetNativeSystemPath(GetPortMonitorDllName());
if (target_path.empty()) {
LOG(ERROR) << "Unable to get port monitor target path.";
return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
}
if (install) {
base::FilePath source_path =
- install_path.Append(cloud_print::GetPortMonitorDllName());
+ install_path.Append(GetPortMonitorDllName());
if (!file_util::CopyFile(source_path, target_path)) {
LOG(ERROR) << "Unable copy port monitor dll from " <<
source_path.value() << " to " << target_path.value();
- return cloud_print::GetLastHResult();
+ return GetLastHResult();
}
} else if (!file_util::PathExists(target_path)) {
// Already removed. Just "succeed" silently.
@@ -197,8 +134,7 @@ HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
}
// Use system32 path here because otherwise ::AddMonitor would fail.
- command_line.AppendArgPath(GetSystemPath(
- cloud_print::GetPortMonitorDllName()));
+ command_line.AppendArgPath(GetSystemPath(GetPortMonitorDllName()));
base::LaunchOptions options;
options.wait = true;
@@ -213,7 +149,7 @@ HRESULT RegisterPortMonitor(bool install, const base::FilePath& install_path) {
if (install) {
if (!GetExitCodeProcess(regsvr32_handle, &exit_code)) {
LOG(ERROR) << "Unable to get regsvr32.exe exit code.";
- return cloud_print::GetLastHResult();
+ return GetLastHResult();
}
if (exit_code != 0) {
LOG(ERROR) << "Regsvr32.exe failed with " << exit_code;
@@ -334,7 +270,8 @@ HRESULT InstallDriver(const base::FilePath& install_path) {
base::FilePath ui_help_path = temp_path.path().Append(kHelpName);
if (!file_util::PathExists(xps_path)) {
- SetGoogleUpdateError(cloud_print::LoadLocalString(IDS_ERROR_NO_XPS));
+ SetGoogleUpdateError(kGoogleUpdateProductId,
+ LoadLocalString(IDS_ERROR_NO_XPS));
return HRESULT_FROM_WIN32(ERROR_BAD_DRIVER);
}
@@ -355,25 +292,25 @@ HRESULT InstallDriver(const base::FilePath& install_path) {
driver_info.pDependentFiles = &dependent_files[0];
// Set up user visible strings.
- string16 manufacturer = cloud_print::LoadLocalString(IDS_GOOGLE);
+ string16 manufacturer = LoadLocalString(IDS_GOOGLE);
driver_info.pszMfgName = const_cast<LPWSTR>(manufacturer.c_str());
driver_info.pszProvider = const_cast<LPWSTR>(manufacturer.c_str());
driver_info.pszOEMUrl = const_cast<LPWSTR>(kGcpUrl);
driver_info.dwlDriverVersion = GetVersionNumber();
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
driver_info.pName = const_cast<LPWSTR>(driver_name.c_str());
if (!::AddPrinterDriverEx(NULL, 6, reinterpret_cast<BYTE*>(&driver_info),
APD_COPY_NEW_FILES | APD_COPY_FROM_DIRECTORY)) {
LOG(ERROR) << "Unable to add printer driver";
- return cloud_print::GetLastHResult();
+ return GetLastHResult();
}
return S_OK;
}
HRESULT UninstallDriver() {
int tries = 3;
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
while (!DeletePrinterDriverEx(NULL,
NULL,
const_cast<LPWSTR>(driver_name.c_str()),
@@ -390,7 +327,7 @@ HRESULT UninstallDriver() {
Sleep(2000);
}
if (tries <= 0) {
- HRESULT result = cloud_print::GetLastHResult();
+ HRESULT result = GetLastHResult();
LOG(ERROR) << "Unable to delete printer driver.";
return result;
}
@@ -402,18 +339,18 @@ HRESULT InstallPrinter(void) {
// None of the print API structures likes constant strings even though they
// don't modify the string. const_casting is the cleanest option.
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
printer_info.pDriverName = const_cast<LPWSTR>(driver_name.c_str());
printer_info.pPrinterName = const_cast<LPWSTR>(driver_name.c_str());
printer_info.pComment = const_cast<LPWSTR>(driver_name.c_str());
printer_info.pLocation = const_cast<LPWSTR>(kGcpUrl);
string16 port_name;
- printer_info.pPortName = const_cast<LPWSTR>(cloud_print::kPortName);
+ printer_info.pPortName = const_cast<LPWSTR>(kPortName);
printer_info.Attributes = PRINTER_ATTRIBUTE_DIRECT|PRINTER_ATTRIBUTE_LOCAL;
printer_info.pPrintProcessor = L"winprint";
HANDLE handle = AddPrinter(NULL, 2, reinterpret_cast<BYTE*>(&printer_info));
if (handle == NULL) {
- HRESULT result = cloud_print::GetLastHResult();
+ HRESULT result = GetLastHResult();
LOG(ERROR) << "Unable to add printer";
return result;
}
@@ -425,7 +362,7 @@ HRESULT UninstallPrinter(void) {
HANDLE handle = NULL;
PRINTER_DEFAULTS printer_defaults = {0};
printer_defaults.DesiredAccess = PRINTER_ALL_ACCESS;
- string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME);
+ string16 driver_name = LoadLocalString(IDS_DRIVER_NAME);
if (!OpenPrinter(const_cast<LPWSTR>(driver_name.c_str()),
&handle,
&printer_defaults)) {
@@ -434,7 +371,7 @@ HRESULT UninstallPrinter(void) {
return S_OK;
}
if (!DeletePrinter(handle)) {
- HRESULT result = cloud_print::GetLastHResult();
+ HRESULT result = GetLastHResult();
LOG(ERROR) << "Unable to delete printer";
ClosePrinter(handle);
return result;
@@ -443,46 +380,6 @@ HRESULT UninstallPrinter(void) {
return S_OK;
}
-void SetupUninstall(const base::FilePath& install_path) {
- // Now write the Windows Uninstall entries
- // Minimal error checking here since the install can contiunue
- // if this fails.
- base::win::RegKey key;
- if (key.Create(HKEY_LOCAL_MACHINE, kUninstallRegistry,
- KEY_SET_VALUE) != ERROR_SUCCESS) {
- LOG(ERROR) << "Unable to open key";
- return;
- }
- CommandLine uninstall_command(install_path.Append(kInstallerName));
- uninstall_command.AppendArg("--uninstall");
- key.WriteValue(L"UninstallString",
- uninstall_command.GetCommandLineString().c_str());
- key.WriteValue(L"InstallLocation", install_path.value().c_str());
-
-
- // Get the version resource.
- scoped_ptr<FileVersionInfo> version_info(
- FileVersionInfo::CreateFileVersionInfoForCurrentModule());
-
- if (version_info.get()) {
- FileVersionInfoWin* version_info_win =
- static_cast<FileVersionInfoWin*>(version_info.get());
- key.WriteValue(L"DisplayVersion",
- version_info_win->file_version().c_str());
- key.WriteValue(L"Publisher", version_info_win->company_name().c_str());
- } else {
- LOG(ERROR) << "Unable to get version string";
- }
- key.WriteValue(L"DisplayName",
- cloud_print::LoadLocalString(IDS_DRIVER_NAME).c_str());
- key.WriteValue(L"NoModify", 1);
- key.WriteValue(L"NoRepair", 1);
-}
-
-void CleanupUninstall() {
- ::RegDeleteKey(HKEY_LOCAL_MACHINE, kUninstallRegistry);
-}
-
bool IsOSSupported() {
// We don't support XP service pack 2 or older.
base::win::Version version = base::win::GetVersion();
@@ -521,19 +418,6 @@ HRESULT RegisterVirtualDriver(const base::FilePath& install_path) {
return S_OK;
}
-void GetCurrentInstallPath(base::FilePath* install_path) {
- base::win::RegKey key;
- if (key.Open(HKEY_LOCAL_MACHINE, kUninstallRegistry,
- KEY_QUERY_VALUE) != ERROR_SUCCESS) {
- // Not installed.
- *install_path = base::FilePath();
- return;
- }
- string16 install_path_value;
- key.ReadValue(L"InstallLocation", &install_path_value);
- *install_path = base::FilePath(install_path_value);
-}
-
HRESULT TryUnregisterVirtualDriver() {
HRESULT result = S_OK;
result = UninstallPrinter();
@@ -599,11 +483,11 @@ HRESULT DeleteProgramDir(const base::FilePath& installer_source, bool wait) {
}
HRESULT DoUninstall() {
- DeleteGoogleUpdateKeys();
+ DeleteGoogleUpdateKeys(kGoogleUpdateProductId);
HRESULT result = UnregisterVirtualDriver();
if (FAILED(result))
return result;
- CleanupUninstall();
+ DeleteUninstallKey(kUninstallId);
base::FilePath installer_source;
if (PathService::Get(base::FILE_EXE, &installer_source))
return DeleteProgramDir(installer_source, false);
@@ -636,18 +520,18 @@ HRESULT DoInstall(const base::FilePath& install_path) {
LOG(ERROR) << "Unable to unregister.";
return result;
}
- base::FilePath old_install_path;
- GetCurrentInstallPath(&old_install_path);
+ base::FilePath old_install_path = GetInstallLocation(kUninstallId);
if (!old_install_path.value().empty() &&
install_path != old_install_path) {
if (file_util::DirectoryExists(old_install_path))
file_util::Delete(old_install_path, true);
}
- SetupUninstall(install_path);
+ CreateUninstallKey(kUninstallId, LoadLocalString(IDS_DRIVER_NAME),
+ kUninstallSwitch);
result = RegisterVirtualDriver(install_path);
if (FAILED(result))
return result;
- SetGoogleUpdateKeys();
+ SetGoogleUpdateKeys(kGoogleUpdateProductId, kNameValue);
return result;
}
@@ -677,13 +561,15 @@ HRESULT ExecuteCommands() {
} // namespace
+} // namespace cloud_print
+
int WINAPI WinMain(__in HINSTANCE hInstance,
- __in HINSTANCE hPrevInstance,
- __in LPSTR lpCmdLine,
- __in int nCmdShow) {
+ __in HINSTANCE hPrevInstance,
+ __in LPSTR lpCmdLine,
+ __in int nCmdShow) {
base::AtExitManager at_exit_manager;
CommandLine::Init(0, NULL);
- HRESULT retval = ExecuteCommands();
+ HRESULT retval = cloud_print::ExecuteCommands();
LOG(INFO) << _com_error(retval).ErrorMessage() << " HRESULT=0x" <<
std::setbase(16) << retval;
« no previous file with comments | « cloud_print/common/win/install_utils.cc ('k') | cloud_print/virtual_driver/win/install/virtual_driver_install.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698