diff options
author | abodenha@google.com <abodenha@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 22:12:41 +0000 |
---|---|---|
committer | abodenha@google.com <abodenha@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 22:12:41 +0000 |
commit | 973da4d5cf9f9310e71ea3898d5514cdad85b255 (patch) | |
tree | 444ce1a42fd12c07a40e216b1a04e5467964aa30 /cloud_print/virtual_driver/win/install | |
parent | c3f3840beeeba4bdead501e8ded1df7177eaa8af (diff) | |
download | chromium_src-973da4d5cf9f9310e71ea3898d5514cdad85b255.zip chromium_src-973da4d5cf9f9310e71ea3898d5514cdad85b255.tar.gz chromium_src-973da4d5cf9f9310e71ea3898d5514cdad85b255.tar.bz2 |
Added resources.
Virtual_driver_setup now has localization support.
All dlls and exes now have a version resource.
Common (untranslated) strings are now pulled from a common resource file.
Installer and port monitor now have separate .gyp files.
Still to do: Integrate with TC and add all languages.
BUG=
TEST=
Review URL: http://codereview.chromium.org/6930019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print/virtual_driver/win/install')
4 files changed, 158 insertions, 45 deletions
diff --git a/cloud_print/virtual_driver/win/install/DEPS b/cloud_print/virtual_driver/win/install/DEPS new file mode 100644 index 0000000..9d41d53 --- /dev/null +++ b/cloud_print/virtual_driver/win/install/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+grit", # For generated headers +] diff --git a/cloud_print/virtual_driver/win/install/setup.cc b/cloud_print/virtual_driver/win/install/setup.cc index 8724429..6ee3109 100644 --- a/cloud_print/virtual_driver/win/install/setup.cc +++ b/cloud_print/virtual_driver/win/install/setup.cc @@ -8,23 +8,18 @@ #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/string16.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_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."; @@ -34,25 +29,17 @@ HRESULT GetGpdPath(FilePath* path) { 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()); + *path = path->Append(cloud_print::GetPortMonitorDllName()); 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 +52,7 @@ HRESULT GetPortMonitorInstallPath(FilePath* path) { return ERROR_PATH_NOT_FOUND; } } - *path = path->Append(GetPortMonitorDllName()); + *path = path->Append(cloud_print::GetPortMonitorDllName()); return S_OK; } @@ -139,33 +126,55 @@ 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; - 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; + result = GetGpdPath(&source_path); + if (!SUCCEEDED(result)) { + return result; + } // 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.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. + string16 manufacturer = cloud_print::LoadLocalString(IDS_GOOGLE); + driver_info.pszMfgName = const_cast<LPWSTR>(manufacturer.c_str()); + driver_info.pszProvider = const_cast<LPWSTR>(manufacturer.c_str()); driver_info.pszOEMUrl = L"http://www.google.com/cloudprint"; - driver_info.dwlDriverVersion = 1; - driver_info.pDefaultDataType = L"RAW"; + driver_info.dwlDriverVersion = GetVersionNumber(); + string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME); + driver_info.pName = const_cast<LPWSTR>(driver_name.c_str()); + + // Set up supported print system version. Must be 3. + 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 +192,16 @@ HRESULT InstallGpd() { HRESULT UninstallGpd() { int tries = 10; + string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME); while (!DeletePrinterDriverEx(NULL, NULL, - const_cast<LPWSTR> - (cloud_print::kVirtualDriverName), + const_cast<LPWSTR>(driver_name.c_str()), 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."; @@ -205,17 +218,17 @@ HRESULT UninstallGpd() { HRESULT InstallPrinter(void) { PRINTER_INFO_2 printer_info = {0}; - printer_info.pPrinterName = - const_cast<LPWSTR>(cloud_print::kVirtualDriverName); + + // 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); + 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()); + string16 port_name; 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); printer_info.Attributes = PRINTER_ATTRIBUTE_DIRECT|PRINTER_ATTRIBUTE_LOCAL; printer_info.pPrintProcessor = L"winprint"; - printer_info.pDatatype = L"RAW"; HANDLE handle = AddPrinter(NULL, 2, reinterpret_cast<BYTE*>(&printer_info)); if (handle == NULL) { HRESULT result = cloud_print::GetLastHResult(); @@ -230,7 +243,8 @@ 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), + string16 driver_name = cloud_print::LoadLocalString(IDS_DRIVER_NAME); + if (!OpenPrinter(const_cast<LPWSTR>(driver_name.c_str()), &handle, &printer_defaults)) { // If we can't open the printer, it was probably already removed. @@ -302,7 +316,8 @@ int WINAPI WinMain(__in HINSTANCE hInstance, retval = InstallVirtualDriver(); } if (!CommandLine::ForCurrentProcess()->HasSwitch("silent")) { - cloud_print::DisplayWindowsMessage(NULL, retval); + cloud_print::DisplayWindowsMessage(NULL, retval, + cloud_print::LoadLocalString(IDS_DRIVER_NAME)); } return retval; } diff --git a/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp b/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp new file mode 100644 index 0000000..1182d2d --- /dev/null +++ b/cloud_print/virtual_driver/win/install/virtual_driver_install.gyp @@ -0,0 +1,65 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'target_defaults': { + 'variables': { + 'chromium_code': 1, + }, + 'include_dirs': [ + '../../../..', + ], + }, + 'targets' : [ + { + 'target_name': 'virtual_driver_setup', + 'type': 'executable', + 'msvs_guid': 'E1E25ACA-043D-4D6E-A06F-97126532843A', + 'dependencies': [ + '../../../../base/base.gyp:base', + 'virtual_driver_setup_resources', + ], + 'sources': [ + 'setup.cc', + '../virtual_driver_consts.h', + '../virtual_driver_consts.cc', + '../virtual_driver_helpers.h', + '../virtual_driver_helpers.cc', + '../virtual_driver_common_resources.rc', + '<(SHARED_INTERMEDIATE_DIR)/virtual_driver_setup_resources/virtual_driver_setup_resources_en-US.rc', + '<(SHARED_INTERMEDIATE_DIR)/virtual_driver_setup_resources/virtual_driver_setup_resources_es.rc', + ], + 'msvs_settings': { + 'VCLinkerTool': { + 'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS + }, + }, + }, + { + 'target_name': 'virtual_driver_setup_resources', + 'type': 'none', + 'msvs_guid': '13D30B4C-1B06-40DB-8ED6-D2CAD76940CB', + 'variables': { + 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/virtual_driver_setup_resources', + }, + 'actions': [ + { + 'action_name': 'virtual_driver_setup_resources', + 'variables': { + 'grit_grd_file': 'virtual_driver_setup_resources.grd', + }, + 'includes': [ '../../../../build/grit_action.gypi' ], + }, + ], + 'includes': [ '../../../../build/grit_target.gypi' ], + }, + ], +} + +# Local Variables: +# tab-width:2 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=2 shiftwidth=2: + diff --git a/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd b/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd new file mode 100644 index 0000000..a6048ec --- /dev/null +++ b/cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this +source code is governed by a BSD-style license that can be found in the LICENSE +file. +--> + + +<grit latest_public_release="0" current_release="1"> + <outputs> + <output filename="grit/virtual_driver_setup_resources.h" type="rc_header"> + <emit emit_type='prepend'></emit> + </output> + <output filename="virtual_driver_setup_resources_en-US.rc" type="rc_all" lang="en" language_section="lang"/> + <output filename="virtual_driver_setup_resources_es.rc" type="rc_all" lang="es" language_section="lang"/> + </outputs> + <release seq="1"> + <messages> + <message name="IDS_GOOGLE" + meaning="Google" desc="The name of the company that built this."> + Google + </message> + <message name="IDS_DRIVER_NAME" + meaning="Driver Name" desc="The user visible name of the printer we create and its associated driver."> + Google Cloud Print Virtual Printer + </message> + </messages> + </release> +</grit> |