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