1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/win_util.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,115 @@ 1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/win_util.h" 1.9 + 1.10 +#include <map> 1.11 +#include <sddl.h> 1.12 + 1.13 +#include "base/logging.h" 1.14 +#include "base/registry.h" 1.15 +#include "base/scoped_handle.h" 1.16 +#include "base/scoped_ptr.h" 1.17 +#include "base/singleton.h" 1.18 +#include "base/string_util.h" 1.19 +#include "base/tracked.h" 1.20 + 1.21 +namespace win_util { 1.22 + 1.23 +WinVersion GetWinVersion() { 1.24 + static bool checked_version = false; 1.25 + static WinVersion win_version = WINVERSION_PRE_2000; 1.26 + if (!checked_version) { 1.27 + OSVERSIONINFOEX version_info; 1.28 + version_info.dwOSVersionInfoSize = sizeof version_info; 1.29 + GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); 1.30 + if (version_info.dwMajorVersion == 5) { 1.31 + switch (version_info.dwMinorVersion) { 1.32 + case 0: 1.33 + win_version = WINVERSION_2000; 1.34 + break; 1.35 + case 1: 1.36 + win_version = WINVERSION_XP; 1.37 + break; 1.38 + case 2: 1.39 + default: 1.40 + win_version = WINVERSION_SERVER_2003; 1.41 + break; 1.42 + } 1.43 + } else if (version_info.dwMajorVersion == 6) { 1.44 + if (version_info.wProductType != VER_NT_WORKSTATION) { 1.45 + // 2008 is 6.0, and 2008 R2 is 6.1. 1.46 + win_version = WINVERSION_2008; 1.47 + } else { 1.48 + if (version_info.dwMinorVersion == 0) { 1.49 + win_version = WINVERSION_VISTA; 1.50 + } else { 1.51 + win_version = WINVERSION_WIN7; 1.52 + } 1.53 + } 1.54 + } else if (version_info.dwMajorVersion > 6) { 1.55 + win_version = WINVERSION_WIN7; 1.56 + } 1.57 + checked_version = true; 1.58 + } 1.59 + return win_version; 1.60 +} 1.61 + 1.62 +bool IsShiftPressed() { 1.63 + return (::GetKeyState(VK_SHIFT) & 0x80) == 0x80; 1.64 +} 1.65 + 1.66 +bool IsCtrlPressed() { 1.67 + return (::GetKeyState(VK_CONTROL) & 0x80) == 0x80; 1.68 +} 1.69 + 1.70 +bool IsAltPressed() { 1.71 + return (::GetKeyState(VK_MENU) & 0x80) == 0x80; 1.72 +} 1.73 + 1.74 +std::wstring FormatMessage(unsigned messageid) { 1.75 + wchar_t* string_buffer = NULL; 1.76 + unsigned string_length = ::FormatMessage( 1.77 + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | 1.78 + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, messageid, 0, 1.79 + reinterpret_cast<wchar_t *>(&string_buffer), 0, NULL); 1.80 + 1.81 + std::wstring formatted_string; 1.82 + if (string_buffer) { 1.83 + formatted_string = string_buffer; 1.84 + LocalFree(reinterpret_cast<HLOCAL>(string_buffer)); 1.85 + } else { 1.86 + // The formating failed. simply convert the message value into a string. 1.87 + SStringPrintf(&formatted_string, L"message number %d", messageid); 1.88 + } 1.89 + return formatted_string; 1.90 +} 1.91 + 1.92 +std::wstring FormatLastWin32Error() { 1.93 + return FormatMessage(GetLastError()); 1.94 +} 1.95 + 1.96 +} // namespace win_util 1.97 + 1.98 +#ifdef _MSC_VER 1.99 +// 1.100 +// If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1. 1.101 +// 1.102 +extern char VisualStudio2005ServicePack1Detection[10]; 1.103 +COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*), 1.104 + VS2005SP1Detect); 1.105 +// 1.106 +// Chrome requires at least Service Pack 1 for Visual Studio 2005. 1.107 +// 1.108 +#endif // _MSC_VER 1.109 + 1.110 +#if 0 1.111 +#error You must install the Windows 2008 or Vista Software Development Kit and \ 1.112 +set it as your default include path to build this library. You can grab it by \ 1.113 +searching for "download windows sdk 2008" in your favorite web search engine. \ 1.114 +Also make sure you register the SDK with Visual Studio, by selecting \ 1.115 +"Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ 1.116 +menu (see Start - All Programs - Microsoft Windows SDK - \ 1.117 +Visual Studio Registration). 1.118 +#endif