ovr_sdk

diff LibOVR/Src/Util/Util_SystemInfo.cpp @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Util/Util_SystemInfo.cpp	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,289 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   Util_SystemInfo.cpp
     1.7 +Content     :   Various operations to get information about the system
     1.8 +Created     :   September 26, 2014
     1.9 +Author      :   Kevin Jenkins
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#include "Util_SystemInfo.h"
    1.31 +#include "../Kernel/OVR_Timer.h"
    1.32 +#include "../Kernel/OVR_Threads.h"
    1.33 +#include "../Kernel/OVR_Log.h"
    1.34 +#include "../Kernel/OVR_Array.h"
    1.35 +
    1.36 +/*
    1.37 +// Disabled, can't link RiftConfigUtil
    1.38 +#ifdef OVR_OS_WIN32
    1.39 +#define _WIN32_DCOM
    1.40 +#include <comdef.h>
    1.41 +#include <Wbemidl.h>
    1.42 +
    1.43 +# pragma comment(lib, "wbemuuid.lib")
    1.44 +#endif
    1.45 +*/
    1.46 +
    1.47 +
    1.48 +namespace OVR { namespace Util {
    1.49 +
    1.50 +// From http://blogs.msdn.com/b/oldnewthing/archive/2005/02/01/364563.aspx
    1.51 +#if defined (OVR_OS_WIN64) || defined (OVR_OS_WIN32)
    1.52 +
    1.53 +#pragma comment(lib, "version.lib")
    1.54 +
    1.55 +typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
    1.56 +BOOL Is64BitWindows()
    1.57 +{
    1.58 +#if defined(_WIN64)
    1.59 +    return TRUE;  // 64-bit programs run only on Win64
    1.60 +#elif defined(_WIN32)
    1.61 +    // 32-bit programs run on both 32-bit and 64-bit Windows
    1.62 +    // so must sniff
    1.63 +    BOOL f64 = FALSE;
    1.64 +    LPFN_ISWOW64PROCESS fnIsWow64Process;
    1.65 +
    1.66 +    fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process");
    1.67 +    if (NULL != fnIsWow64Process)
    1.68 +    {
    1.69 +        return fnIsWow64Process(GetCurrentProcess(), &f64) && f64;
    1.70 +    }
    1.71 +    return FALSE;
    1.72 +#else
    1.73 +    return FALSE; // Win64 does not support Win16
    1.74 +#endif
    1.75 +}
    1.76 +#endif
    1.77 +
    1.78 +const char * OSAsString()
    1.79 +{
    1.80 +#if defined (OVR_OS_IPHONE)
    1.81 +    return "IPhone";
    1.82 +#elif defined (OVR_OS_DARWIN)
    1.83 +    return "Darwin";
    1.84 +#elif defined (OVR_OS_MAC)
    1.85 +    return "Mac";
    1.86 +#elif defined (OVR_OS_BSD)
    1.87 +    return "BSD";
    1.88 +#elif defined (OVR_OS_WIN64) || defined (OVR_OS_WIN32)
    1.89 +    if (Is64BitWindows())
    1.90 +        return "Win64";
    1.91 +    else
    1.92 +        return "Win32";
    1.93 +#elif defined (OVR_OS_ANDROID)
    1.94 +    return "Android";
    1.95 +#elif defined (OVR_OS_LINUX)
    1.96 +    return "Linux";
    1.97 +#elif defined (OVR_OS_BSD)
    1.98 +    return "BSD";
    1.99 +#else
   1.100 +    return "Other";
   1.101 +#endif
   1.102 +}
   1.103 +
   1.104 +uint64_t GetGuidInt()
   1.105 +{
   1.106 +    uint64_t g = Timer::GetTicksNanos();
   1.107 +
   1.108 +    uint64_t lastTime, thisTime;
   1.109 +    int j;
   1.110 +    // Sleep a small random time, then use the last 4 bits as a source of randomness
   1.111 +    for (j = 0; j < 8; j++)
   1.112 +    {
   1.113 +        lastTime = Timer::GetTicksNanos();
   1.114 +        Thread::MSleep(1);
   1.115 +        Thread::MSleep(0);
   1.116 +        thisTime = Timer::GetTicksNanos();
   1.117 +        uint64_t diff = thisTime - lastTime;
   1.118 +        unsigned int diff4Bits = (unsigned int)(diff & 15);
   1.119 +        diff4Bits <<= 32 - 4;
   1.120 +        diff4Bits >>= j * 4;
   1.121 +        ((char*)&g)[j] ^= diff4Bits;
   1.122 +    }
   1.123 +
   1.124 +    return g;
   1.125 +}
   1.126 +String GetGuidString()
   1.127 +{
   1.128 +    uint64_t guid = GetGuidInt();
   1.129 +
   1.130 +    char buff[64];
   1.131 +#if defined(OVR_CC_MSVC)
   1.132 +    OVR_sprintf(buff, sizeof(buff), "%I64u", guid);
   1.133 +#else
   1.134 +    OVR_sprintf(buff, sizeof(buff), "%llu", (unsigned long long) guid);
   1.135 +#endif
   1.136 +    return String(buff);
   1.137 +}
   1.138 +
   1.139 +const char * GetProcessInfo()
   1.140 +{
   1.141 +	#if defined (OVR_CPU_X86_64	)
   1.142 +    return "64 bit";
   1.143 +#elif defined (OVR_CPU_X86)
   1.144 +    return "32 bit";
   1.145 +#else
   1.146 +    return "TODO";
   1.147 +#endif
   1.148 +}
   1.149 +#ifdef OVR_OS_WIN32
   1.150 +
   1.151 +
   1.152 +String OSVersionAsString()
   1.153 +{
   1.154 +    return GetSystemFileVersionString("\\kernel32.dll");
   1.155 +}
   1.156 +String GetSystemFileVersionString(String filePath)
   1.157 +{
   1.158 +    char strFilePath[MAX_PATH]; // Local variable
   1.159 +    UINT sysDirLen = GetSystemDirectoryA(strFilePath, ARRAYSIZE(strFilePath));
   1.160 +    if (sysDirLen != 0)
   1.161 +    {
   1.162 +        OVR_strcat(strFilePath, MAX_PATH, filePath.ToCStr());
   1.163 +        return GetFileVersionString(strFilePath);
   1.164 +    }
   1.165 +    else
   1.166 +    {
   1.167 +        return "GetSystemDirectoryA failed";
   1.168 +    }
   1.169 +}
   1.170 +// See http://stackoverflow.com/questions/940707/how-do-i-programatically-get-the-version-of-a-dll-or-exe-file
   1.171 +String GetFileVersionString(String filePath)
   1.172 +{
   1.173 +    String result;
   1.174 +
   1.175 +    DWORD dwSize = GetFileVersionInfoSizeA(filePath.ToCStr(), NULL);
   1.176 +    if (dwSize == 0)
   1.177 +    {
   1.178 +        OVR_DEBUG_LOG(("Error in GetFileVersionInfoSizeA: %d (for %s)", GetLastError(), filePath.ToCStr()));
   1.179 +        result = filePath + " not found";
   1.180 +    }
   1.181 +    else
   1.182 +    {
   1.183 +        BYTE* pVersionInfo = new BYTE[dwSize];
   1.184 +        if (!pVersionInfo)
   1.185 +        {
   1.186 +            OVR_DEBUG_LOG(("Out of memory allocating %d bytes (for %s)", dwSize, filePath.ToCStr()));
   1.187 +            result = "Out of memory";
   1.188 +        }
   1.189 +        else
   1.190 +        {
   1.191 +            if (!GetFileVersionInfoA(filePath.ToCStr(), 0, dwSize, pVersionInfo))
   1.192 +            {
   1.193 +                OVR_DEBUG_LOG(("Error in GetFileVersionInfo: %d (for %s)", GetLastError(), filePath.ToCStr()));
   1.194 +                result = "Cannot get version info";
   1.195 +            }
   1.196 +            else
   1.197 +            {
   1.198 +                VS_FIXEDFILEINFO* pFileInfo = NULL;
   1.199 +                UINT              pLenFileInfo = 0;
   1.200 +                if (!VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*)&pFileInfo, &pLenFileInfo))
   1.201 +                {
   1.202 +                    OVR_DEBUG_LOG(("Error in VerQueryValue: %d (for %s)", GetLastError(), filePath.ToCStr()));
   1.203 +                    result = "File has no version info";
   1.204 +                }
   1.205 +                else
   1.206 +                {
   1.207 +                    int major = (pFileInfo->dwFileVersionMS >> 16) & 0xffff;
   1.208 +                    int minor = (pFileInfo->dwFileVersionMS) & 0xffff;
   1.209 +                    int hotfix = (pFileInfo->dwFileVersionLS >> 16) & 0xffff;
   1.210 +                    int other = (pFileInfo->dwFileVersionLS) & 0xffff;
   1.211 +
   1.212 +                    char str[128];
   1.213 +                    OVR::OVR_sprintf(str, 128, "%d.%d.%d.%d", major, minor, hotfix, other);
   1.214 +
   1.215 +                    result = str;
   1.216 +                }
   1.217 +            }
   1.218 +
   1.219 +            delete[] pVersionInfo;
   1.220 +        }
   1.221 +    }
   1.222 +
   1.223 +    return result;
   1.224 +}
   1.225 +
   1.226 +
   1.227 +String GetDisplayDriverVersion()
   1.228 +{
   1.229 +    return GetSystemFileVersionString("\\OVRDisplay32.dll");
   1.230 +}
   1.231 +String GetCameraDriverVersion()
   1.232 +{
   1.233 +    return GetSystemFileVersionString("\\drivers\\OCUSBVID.sys");
   1.234 +}
   1.235 +
   1.236 +// From http://stackoverflow.com/questions/9524309/enumdisplaydevices-function-not-working-for-me
   1.237 +void GetGraphicsCardList( Array< String > &gpus)
   1.238 +{
   1.239 +	gpus.Clear();
   1.240 +
   1.241 +	DISPLAY_DEVICEA dd;
   1.242 +
   1.243 +	dd.cb = sizeof(dd);
   1.244 +
   1.245 +	DWORD deviceNum = 0;
   1.246 +	while( EnumDisplayDevicesA(NULL, deviceNum, &dd, 0) ){
   1.247 +        if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
   1.248 +		    gpus.PushBack(dd.DeviceString);
   1.249 +		deviceNum++;
   1.250 +	}
   1.251 +}
   1.252 +#else
   1.253 +
   1.254 +// used for driver files
   1.255 +
   1.256 +String GetFileVersionString(String /*filePath*/)
   1.257 +{
   1.258 +	return String();
   1.259 +}
   1.260 +
   1.261 +String GetSystemFileVersionString(String /*filePath*/)
   1.262 +{
   1.263 +	return String();
   1.264 +}
   1.265 +
   1.266 +String GetDisplayDriverVersion()
   1.267 +{
   1.268 +	return String();
   1.269 +}
   1.270 +
   1.271 +String GetCameraDriverVersion()
   1.272 +{
   1.273 +	return String();
   1.274 +}
   1.275 +
   1.276 +#ifdef OVR_OS_MAC
   1.277 +    //use objective c source
   1.278 +#else
   1.279 +    
   1.280 +//todo linux, this requires searching /var/ files
   1.281 +void GetGraphicsCardList(OVR::Array< OVR::String > &gpus)
   1.282 +{
   1.283 +	gpus.Clear();
   1.284 +}
   1.285 +String OSVersionAsString()
   1.286 +{
   1.287 +    return String();
   1.288 +}
   1.289 +#endif //OVR_OS_MAC
   1.290 +#endif // WIN32
   1.291 +
   1.292 +} } // namespace OVR { namespace Util {