- add sources.
[platform/framework/web/crosswalk.git] / src / cloud_print / virtual_driver / win / virtual_driver_helpers.cc
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.
4
5 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
6
7 #include <windows.h>
8 #include <winspool.h>
9
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"
15
16 namespace cloud_print {
17
18 const size_t kMaxMessageLen = 100;
19
20 void DisplayWindowsMessage(HWND hwnd, HRESULT hr, const string16 &caption) {
21   ::MessageBox(hwnd, GetErrorMessage(hr).c_str(), caption.c_str(), MB_OK);
22 }
23
24 string16 GetPortMonitorDllName() {
25   if (IsSystem64Bit()) {
26     return string16(L"gcp_portmon64.dll");
27   } else {
28     return string16(L"gcp_portmon.dll");
29   }
30 }
31
32 HRESULT GetPrinterDriverDir(base::FilePath* path) {
33   BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)];
34   DWORD needed = 0;
35   if (!GetPrinterDriverDirectory(NULL,
36                                  NULL,
37                                  1,
38                                  driver_dir_buffer,
39                                  MAX_PATH * sizeof(wchar_t),
40                                  &needed)) {
41     // We could try to allocate a larger buffer if needed > MAX_PATH
42     // but that really shouldn't happen.
43     return cloud_print::GetLastHResult();
44   }
45   *path = base::FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer));
46
47   // The XPS driver is a "Level 3" driver
48   *path = path->Append(L"3");
49   return S_OK;
50 }
51
52 bool IsSystem64Bit() {
53   base::win::OSInfo::WindowsArchitecture arch =
54       base::win::OSInfo::GetInstance()->architecture();
55   return (arch == base::win::OSInfo::X64_ARCHITECTURE) ||
56          (arch == base::win::OSInfo::IA64_ARCHITECTURE);
57 }
58
59 }
60