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 87244292f51d5fb512582636b91dd12c9d8b745c..06f83ee1201bd6b5e5d262d1443ecf7fdffe6be9 100644 |
--- a/cloud_print/virtual_driver/win/install/setup.cc |
+++ b/cloud_print/virtual_driver/win/install/setup.cc |
@@ -8,51 +8,43 @@ |
#include "base/at_exit.h" |
#include "base/command_line.h" |
#include "base/file_util.h" |
+#include "base/file_version_info_win.h" |
#include "base/logging.h" |
#include "base/path_service.h" |
#include "base/process_util.h" |
#include "base/win/scoped_handle.h" |
-#include "base/win/windows_version.h" |
-#include "cloud_print/virtual_driver/win/virtual_driver_consts.h" |
+#include "cloud_print/virtual_driver/win/virtual_driver_common_resources.h" |
#include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" |
+#include "grit/virtual_driver_setup_resources.h" |
namespace { |
-bool IsSystem64Bit() { |
- base::win::OSInfo::WindowsArchitecture arch = |
- base::win::OSInfo::GetInstance()->architecture(); |
- return (arch == base::win::OSInfo::X64_ARCHITECTURE) || |
- (arch == base::win::OSInfo::IA64_ARCHITECTURE); |
-} |
- |
HRESULT GetGpdPath(FilePath* path) { |
if (!PathService::Get(base::DIR_EXE, path)) { |
LOG(ERROR) << "Unable to get install path."; |
return ERROR_PATH_NOT_FOUND; |
} |
- *path = path->Append(L"gcp.gpd"); |
+ wchar_t driver_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_GCP_DRIVER, |
+ driver_name, |
+ MAX_PATH); |
+ *path = path->Append(driver_name); |
return S_OK; |
} |
-const wchar_t *GetPortMonitorDllName() { |
- if (IsSystem64Bit()) { |
- return cloud_print::kPortMonitorDllName64; |
- } else { |
- return cloud_print::kPortMonitorDllName32; |
- } |
-} |
- |
HRESULT GetPortMonitorDllPath(FilePath* path) { |
if (!PathService::Get(base::DIR_EXE, path)) { |
LOG(ERROR) << "Unable to get install path."; |
return ERROR_PATH_NOT_FOUND; |
} |
- *path = path->Append(GetPortMonitorDllName()); |
+ FilePath dll_name; |
+ cloud_print::GetPortMonitorDllName(&dll_name); |
+ *path = path->Append(dll_name); |
return S_OK; |
} |
HRESULT GetPortMonitorInstallPath(FilePath* path) { |
- if (IsSystem64Bit()) { |
+ if (cloud_print::IsSystem64Bit()) { |
if (!PathService::Get(base::DIR_WINDOWS, path)) { |
return ERROR_PATH_NOT_FOUND; |
} |
@@ -65,7 +57,9 @@ HRESULT GetPortMonitorInstallPath(FilePath* path) { |
return ERROR_PATH_NOT_FOUND; |
} |
} |
- *path = path->Append(GetPortMonitorDllName()); |
+ FilePath dll_name; |
+ cloud_print::GetPortMonitorDllName(&dll_name); |
+ *path = path->Append(dll_name); |
return S_OK; |
} |
@@ -139,33 +133,68 @@ HRESULT RegisterPortMonitor(bool install) { |
return S_OK; |
} |
+DWORDLONG GetVersionNumber() { |
+ DWORDLONG retval = 0; |
+ scoped_ptr<FileVersionInfo> version_info( |
+ FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
+ if (version_info.get()) { |
+ FileVersionInfoWin* version_info_win = |
+ static_cast<FileVersionInfoWin*>(version_info.get()); |
+ VS_FIXEDFILEINFO* fixed_file_info = version_info_win->fixed_file_info(); |
+ retval = fixed_file_info->dwFileVersionMS; |
+ retval <<= 32; |
+ retval |= fixed_file_info->dwFileVersionMS; |
+ } |
+ return retval; |
+} |
+ |
HRESULT InstallGpd() { |
+ DRIVER_INFO_6 driver_info = {0}; |
HRESULT result = S_OK; |
+ |
+ // Set up paths for the files we depend on. |
FilePath source_path; |
+ FilePath driver_dir; |
+ cloud_print::GetPrinterDriverDir(&driver_dir); |
+ wchar_t buffer[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_XPS_DRIVER, buffer, MAX_PATH); |
sanjeevr
2011/05/09 19:39:11
Do the DLL names need to be in the resource?
|
+ FilePath xps_path = driver_dir.Append(buffer); |
+ cloud_print::LoadLocalString(IDS_UI_DRIVER, buffer, MAX_PATH); |
+ FilePath ui_path = driver_dir.Append(buffer); |
+ cloud_print::LoadLocalString(IDS_UI_HELP, buffer, MAX_PATH); |
+ FilePath ui_help_path = driver_dir.Append(buffer); |
result = GetGpdPath(&source_path); |
if (!SUCCEEDED(result)) { |
return result; |
} |
- FilePath driver_dir; |
- cloud_print::GetPrinterDriverDir(&driver_dir); |
- FilePath xps_path = driver_dir.Append(L"mxdwdrv.dll"); |
- FilePath ui_path = driver_dir.Append(L"unidrvui.dll"); |
- FilePath ui_help_path = driver_dir.Append(L"unidrv.hlp"); |
- DRIVER_INFO_6 driver_info = {0}; |
- driver_info.cVersion = 3; |
// None of the print API structures likes constant strings even though they |
// don't modify the string. const_casting is the cleanest option. |
- driver_info.pName = const_cast<LPWSTR>(cloud_print::kVirtualDriverName); |
- driver_info.pDriverPath = const_cast<LPWSTR>(xps_path.value().c_str()); |
- driver_info.pConfigFile = const_cast<LPWSTR>(ui_path.value().c_str()); |
driver_info.pDataFile = const_cast<LPWSTR>(source_path.value().c_str()); |
driver_info.pHelpFile = const_cast<LPWSTR>(ui_help_path.value().c_str()); |
- // TODO(abodenha@chromium.org) Pull these strings from resources. |
- driver_info.pszMfgName = L"Google"; |
- driver_info.pszProvider = driver_info.pszMfgName; |
- driver_info.pszOEMUrl = L"http://www.google.com/cloudprint"; |
- driver_info.dwlDriverVersion = 1; |
- driver_info.pDefaultDataType = L"RAW"; |
+ driver_info.pDriverPath = const_cast<LPWSTR>(xps_path.value().c_str()); |
+ driver_info.pConfigFile = const_cast<LPWSTR>(ui_path.value().c_str()); |
+ |
+ // Set up user visible strings. |
+ wchar_t manufacturer[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_GOOGLE, manufacturer, MAX_PATH); |
+ driver_info.pszMfgName = manufacturer; |
+ driver_info.pszProvider = manufacturer; |
+ wchar_t oem_url[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_GCP_URL, oem_url, MAX_PATH); |
+ driver_info.pszOEMUrl = oem_url; |
+ driver_info.dwlDriverVersion = GetVersionNumber(); |
+ wchar_t driver_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DRIVER_NAME, |
+ driver_name, |
+ MAX_PATH); |
+ driver_info.pName = driver_name; |
+ |
+ // Set up supported data type and print system version. |
+ wchar_t data_type[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DATA_TYPE, data_type, MAX_PATH); |
+ driver_info.pDefaultDataType = data_type; |
+ driver_info.cVersion = 3; |
+ |
// TODO(abodenha@chromium.org) Properly handle dependencies. |
// GPD files are often dependent on various Windows core drivers. |
// I haven't found a reliable way to express those dependencies |
@@ -183,12 +212,17 @@ HRESULT InstallGpd() { |
HRESULT UninstallGpd() { |
int tries = 10; |
+ wchar_t driver_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DRIVER_NAME, driver_name, MAX_PATH); |
while (!DeletePrinterDriverEx(NULL, |
NULL, |
- const_cast<LPWSTR> |
- (cloud_print::kVirtualDriverName), |
+ driver_name, |
DPD_DELETE_UNUSED_FILES, |
0) && tries > 0) { |
+ if (GetLastError() == ERROR_UNKNOWN_PRINTER_DRIVER) { |
+ LOG(WARNING) << "Print driver is already uninstalled."; |
+ return S_OK; |
+ } |
// After deleting the printer it can take a few seconds before |
// the driver is free for deletion. Retry a few times before giving up. |
LOG(WARNING) << "Attempt to delete printer driver failed. Retrying."; |
@@ -196,7 +230,7 @@ HRESULT UninstallGpd() { |
Sleep(2000); |
} |
if (tries <= 0) { |
- HRESULT result = cloud_print::GetLastHResult(); |
+ HRESULT result = S_OK; |
LOG(ERROR) << "Unable to delete printer driver."; |
return result; |
} |
@@ -205,17 +239,21 @@ HRESULT UninstallGpd() { |
HRESULT InstallPrinter(void) { |
PRINTER_INFO_2 printer_info = {0}; |
- printer_info.pPrinterName = |
- const_cast<LPWSTR>(cloud_print::kVirtualDriverName); |
- printer_info.pPortName = const_cast<LPWSTR>(cloud_print::kPortName); |
- printer_info.pDriverName = |
- const_cast<LPWSTR>(cloud_print::kVirtualDriverName); |
- printer_info.pPrinterName = printer_info.pDriverName; |
- // TODO(abodenha@chromium.org) pComment should be localized. |
- printer_info.pComment = const_cast<LPWSTR>(cloud_print::kVirtualDriverName); |
+ wchar_t driver_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DRIVER_NAME, driver_name, MAX_PATH); |
+ printer_info.pDriverName = driver_name; |
+ printer_info.pPrinterName = driver_name; |
+ printer_info.pComment = driver_name; |
+ wchar_t port_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_PORT_NAME, port_name, MAX_PATH); |
+ printer_info.pPortName = port_name; |
printer_info.Attributes = PRINTER_ATTRIBUTE_DIRECT|PRINTER_ATTRIBUTE_LOCAL; |
- printer_info.pPrintProcessor = L"winprint"; |
- printer_info.pDatatype = L"RAW"; |
+ wchar_t print_processor[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_PRINT_PROCESSOR, print_processor, MAX_PATH); |
+ printer_info.pPrintProcessor = print_processor; |
+ wchar_t data_type[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DATA_TYPE, data_type, MAX_PATH); |
+ printer_info.pDatatype = data_type; |
HANDLE handle = AddPrinter(NULL, 2, reinterpret_cast<BYTE*>(&printer_info)); |
if (handle == NULL) { |
HRESULT result = cloud_print::GetLastHResult(); |
@@ -230,9 +268,9 @@ HRESULT UninstallPrinter(void) { |
HANDLE handle = NULL; |
PRINTER_DEFAULTS printer_defaults = {0}; |
printer_defaults.DesiredAccess = PRINTER_ALL_ACCESS; |
- if (!OpenPrinter(const_cast<LPWSTR>(cloud_print::kVirtualDriverName), |
- &handle, |
- &printer_defaults)) { |
+ wchar_t driver_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DRIVER_NAME, driver_name, MAX_PATH); |
+ if (!OpenPrinter(driver_name, &handle, &printer_defaults)) { |
// If we can't open the printer, it was probably already removed. |
LOG(WARNING) << "Unable to open printer"; |
return S_OK; |
@@ -302,7 +340,9 @@ int WINAPI WinMain(__in HINSTANCE hInstance, |
retval = InstallVirtualDriver(); |
} |
if (!CommandLine::ForCurrentProcess()->HasSwitch("silent")) { |
- cloud_print::DisplayWindowsMessage(NULL, retval); |
+ wchar_t driver_name[MAX_PATH]; |
+ cloud_print::LoadLocalString(IDS_DRIVER_NAME, driver_name, MAX_PATH); |
+ cloud_print::DisplayWindowsMessage(NULL, retval, driver_name); |
} |
return retval; |
} |