ovr_sdk

view 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 source
1 /************************************************************************************
3 Filename : Util_SystemInfo.cpp
4 Content : Various operations to get information about the system
5 Created : September 26, 2014
6 Author : Kevin Jenkins
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
12 which is provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 You may obtain a copy of the License at
17 http://www.oculusvr.com/licenses/LICENSE-3.2
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
25 ************************************************************************************/
27 #include "Util_SystemInfo.h"
28 #include "../Kernel/OVR_Timer.h"
29 #include "../Kernel/OVR_Threads.h"
30 #include "../Kernel/OVR_Log.h"
31 #include "../Kernel/OVR_Array.h"
33 /*
34 // Disabled, can't link RiftConfigUtil
35 #ifdef OVR_OS_WIN32
36 #define _WIN32_DCOM
37 #include <comdef.h>
38 #include <Wbemidl.h>
40 # pragma comment(lib, "wbemuuid.lib")
41 #endif
42 */
45 namespace OVR { namespace Util {
47 // From http://blogs.msdn.com/b/oldnewthing/archive/2005/02/01/364563.aspx
48 #if defined (OVR_OS_WIN64) || defined (OVR_OS_WIN32)
50 #pragma comment(lib, "version.lib")
52 typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
53 BOOL Is64BitWindows()
54 {
55 #if defined(_WIN64)
56 return TRUE; // 64-bit programs run only on Win64
57 #elif defined(_WIN32)
58 // 32-bit programs run on both 32-bit and 64-bit Windows
59 // so must sniff
60 BOOL f64 = FALSE;
61 LPFN_ISWOW64PROCESS fnIsWow64Process;
63 fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process");
64 if (NULL != fnIsWow64Process)
65 {
66 return fnIsWow64Process(GetCurrentProcess(), &f64) && f64;
67 }
68 return FALSE;
69 #else
70 return FALSE; // Win64 does not support Win16
71 #endif
72 }
73 #endif
75 const char * OSAsString()
76 {
77 #if defined (OVR_OS_IPHONE)
78 return "IPhone";
79 #elif defined (OVR_OS_DARWIN)
80 return "Darwin";
81 #elif defined (OVR_OS_MAC)
82 return "Mac";
83 #elif defined (OVR_OS_BSD)
84 return "BSD";
85 #elif defined (OVR_OS_WIN64) || defined (OVR_OS_WIN32)
86 if (Is64BitWindows())
87 return "Win64";
88 else
89 return "Win32";
90 #elif defined (OVR_OS_ANDROID)
91 return "Android";
92 #elif defined (OVR_OS_LINUX)
93 return "Linux";
94 #elif defined (OVR_OS_BSD)
95 return "BSD";
96 #else
97 return "Other";
98 #endif
99 }
101 uint64_t GetGuidInt()
102 {
103 uint64_t g = Timer::GetTicksNanos();
105 uint64_t lastTime, thisTime;
106 int j;
107 // Sleep a small random time, then use the last 4 bits as a source of randomness
108 for (j = 0; j < 8; j++)
109 {
110 lastTime = Timer::GetTicksNanos();
111 Thread::MSleep(1);
112 Thread::MSleep(0);
113 thisTime = Timer::GetTicksNanos();
114 uint64_t diff = thisTime - lastTime;
115 unsigned int diff4Bits = (unsigned int)(diff & 15);
116 diff4Bits <<= 32 - 4;
117 diff4Bits >>= j * 4;
118 ((char*)&g)[j] ^= diff4Bits;
119 }
121 return g;
122 }
123 String GetGuidString()
124 {
125 uint64_t guid = GetGuidInt();
127 char buff[64];
128 #if defined(OVR_CC_MSVC)
129 OVR_sprintf(buff, sizeof(buff), "%I64u", guid);
130 #else
131 OVR_sprintf(buff, sizeof(buff), "%llu", (unsigned long long) guid);
132 #endif
133 return String(buff);
134 }
136 const char * GetProcessInfo()
137 {
138 #if defined (OVR_CPU_X86_64 )
139 return "64 bit";
140 #elif defined (OVR_CPU_X86)
141 return "32 bit";
142 #else
143 return "TODO";
144 #endif
145 }
146 #ifdef OVR_OS_WIN32
149 String OSVersionAsString()
150 {
151 return GetSystemFileVersionString("\\kernel32.dll");
152 }
153 String GetSystemFileVersionString(String filePath)
154 {
155 char strFilePath[MAX_PATH]; // Local variable
156 UINT sysDirLen = GetSystemDirectoryA(strFilePath, ARRAYSIZE(strFilePath));
157 if (sysDirLen != 0)
158 {
159 OVR_strcat(strFilePath, MAX_PATH, filePath.ToCStr());
160 return GetFileVersionString(strFilePath);
161 }
162 else
163 {
164 return "GetSystemDirectoryA failed";
165 }
166 }
167 // See http://stackoverflow.com/questions/940707/how-do-i-programatically-get-the-version-of-a-dll-or-exe-file
168 String GetFileVersionString(String filePath)
169 {
170 String result;
172 DWORD dwSize = GetFileVersionInfoSizeA(filePath.ToCStr(), NULL);
173 if (dwSize == 0)
174 {
175 OVR_DEBUG_LOG(("Error in GetFileVersionInfoSizeA: %d (for %s)", GetLastError(), filePath.ToCStr()));
176 result = filePath + " not found";
177 }
178 else
179 {
180 BYTE* pVersionInfo = new BYTE[dwSize];
181 if (!pVersionInfo)
182 {
183 OVR_DEBUG_LOG(("Out of memory allocating %d bytes (for %s)", dwSize, filePath.ToCStr()));
184 result = "Out of memory";
185 }
186 else
187 {
188 if (!GetFileVersionInfoA(filePath.ToCStr(), 0, dwSize, pVersionInfo))
189 {
190 OVR_DEBUG_LOG(("Error in GetFileVersionInfo: %d (for %s)", GetLastError(), filePath.ToCStr()));
191 result = "Cannot get version info";
192 }
193 else
194 {
195 VS_FIXEDFILEINFO* pFileInfo = NULL;
196 UINT pLenFileInfo = 0;
197 if (!VerQueryValue(pVersionInfo, TEXT("\\"), (LPVOID*)&pFileInfo, &pLenFileInfo))
198 {
199 OVR_DEBUG_LOG(("Error in VerQueryValue: %d (for %s)", GetLastError(), filePath.ToCStr()));
200 result = "File has no version info";
201 }
202 else
203 {
204 int major = (pFileInfo->dwFileVersionMS >> 16) & 0xffff;
205 int minor = (pFileInfo->dwFileVersionMS) & 0xffff;
206 int hotfix = (pFileInfo->dwFileVersionLS >> 16) & 0xffff;
207 int other = (pFileInfo->dwFileVersionLS) & 0xffff;
209 char str[128];
210 OVR::OVR_sprintf(str, 128, "%d.%d.%d.%d", major, minor, hotfix, other);
212 result = str;
213 }
214 }
216 delete[] pVersionInfo;
217 }
218 }
220 return result;
221 }
224 String GetDisplayDriverVersion()
225 {
226 return GetSystemFileVersionString("\\OVRDisplay32.dll");
227 }
228 String GetCameraDriverVersion()
229 {
230 return GetSystemFileVersionString("\\drivers\\OCUSBVID.sys");
231 }
233 // From http://stackoverflow.com/questions/9524309/enumdisplaydevices-function-not-working-for-me
234 void GetGraphicsCardList( Array< String > &gpus)
235 {
236 gpus.Clear();
238 DISPLAY_DEVICEA dd;
240 dd.cb = sizeof(dd);
242 DWORD deviceNum = 0;
243 while( EnumDisplayDevicesA(NULL, deviceNum, &dd, 0) ){
244 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
245 gpus.PushBack(dd.DeviceString);
246 deviceNum++;
247 }
248 }
249 #else
251 // used for driver files
253 String GetFileVersionString(String /*filePath*/)
254 {
255 return String();
256 }
258 String GetSystemFileVersionString(String /*filePath*/)
259 {
260 return String();
261 }
263 String GetDisplayDriverVersion()
264 {
265 return String();
266 }
268 String GetCameraDriverVersion()
269 {
270 return String();
271 }
273 #ifdef OVR_OS_MAC
274 //use objective c source
275 #else
277 //todo linux, this requires searching /var/ files
278 void GetGraphicsCardList(OVR::Array< OVR::String > &gpus)
279 {
280 gpus.Clear();
281 }
282 String OSVersionAsString()
283 {
284 return String();
285 }
286 #endif //OVR_OS_MAC
287 #endif // WIN32
289 } } // namespace OVR { namespace Util {