Roll leveldb to r78 / 1.15.
[chromium-blink-merge.git] / cloud_print / virtual_driver / win / virtual_driver_helpers.cc
blob26a2bdfb7019fef7051ebd40c645615d06aa7aad
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
7 #include <windows.h>
8 #include <winspool.h>
10 #include "base/file_util.h"
11 #include "base/logging.h"
12 #include "base/strings/string16.h"
13 #include "base/win/windows_version.h"
14 #include "cloud_print/common/win/cloud_print_utils.h"
16 namespace cloud_print {
18 const size_t kMaxMessageLen = 100;
20 void DisplayWindowsMessage(HWND hwnd, HRESULT hr,
21 const base::string16 &caption) {
22 ::MessageBox(hwnd, GetErrorMessage(hr).c_str(), caption.c_str(), MB_OK);
25 base::string16 GetPortMonitorDllName() {
26 if (IsSystem64Bit()) {
27 return base::string16(L"gcp_portmon64.dll");
28 } else {
29 return base::string16(L"gcp_portmon.dll");
33 HRESULT GetPrinterDriverDir(base::FilePath* path) {
34 BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)];
35 DWORD needed = 0;
36 if (!GetPrinterDriverDirectory(NULL,
37 NULL,
39 driver_dir_buffer,
40 MAX_PATH * sizeof(wchar_t),
41 &needed)) {
42 // We could try to allocate a larger buffer if needed > MAX_PATH
43 // but that really shouldn't happen.
44 return cloud_print::GetLastHResult();
46 *path = base::FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer));
48 // The XPS driver is a "Level 3" driver
49 *path = path->Append(L"3");
50 return S_OK;
53 bool IsSystem64Bit() {
54 base::win::OSInfo::WindowsArchitecture arch =
55 base::win::OSInfo::GetInstance()->architecture();
56 return (arch == base::win::OSInfo::X64_ARCHITECTURE) ||
57 (arch == base::win::OSInfo::IA64_ARCHITECTURE);