summaryrefslogtreecommitdiff
path: root/Runtime/Misc/SystemInfo.h
blob: 7e25cf69d87a418682f09e4cba7d718c324f8023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#ifndef SYSTEM_INFO_H
#define SYSTEM_INFO_H

#include "Runtime/Modules/ExportModules.h"
#include <string>

enum RuntimePlatform
{
	// NEVER change constants of existing platforms!
	OSXEditor = 0,
	OSXPlayer = 1,
	WindowsPlayer = 2,
	OSXWebPlayer = 3,
	OSXDashboardPlayer = 4,
	WindowsWebPlayer = 5,
	WiiPlayer = 6,
	WindowsEditor = 7,
	iPhonePlayer = 8,
	PS3Player = 9,
	XenonPlayer = 10,
	AndroidPlayer = 11,
	NaClWebPlayer = 12,
	LinuxPlayer = 13,
	LinuxWebPlayer = 14,
	FlashPlayer = 15,
	LinuxEditor = 16,
	WebGLPlayer = 17,
	MetroPlayerX86 = 18,
	MetroPlayerX64 = 19,
	MetroPlayerARM = 20,
	WP8Player = 21,
	BB10Player = 22,
	TizenPlayer = 23,

	RuntimePlatformCount // keep this last
};

enum DeviceType
{
	kDeviceTypeUnknown = 0,
	kDeviceTypeHandheld,
	kDeviceTypeConsole,
	kDeviceTypeDesktop,
	kDeviceTypeCount // keep this last
};

enum SystemLanguage {
	SystemLanguageAfrikaans,
	SystemLanguageArabic,
	SystemLanguageBasque,
	SystemLanguageBelarusian,
	SystemLanguageBulgarian,
	SystemLanguageCatalan,
	SystemLanguageChinese,
	SystemLanguageCzech,
	SystemLanguageDanish,
	SystemLanguageDutch,
	SystemLanguageEnglish,
	SystemLanguageEstonian,
	SystemLanguageFaroese,
	SystemLanguageFinnish,
	SystemLanguageFrench,
	SystemLanguageGerman,
	SystemLanguageGreek,
	SystemLanguageHebrew,
	SystemLanguageHugarian,
	SystemLanguageIcelandic,
	SystemLanguageIndonesian,
	SystemLanguageItalian,
	SystemLanguageJapanese,
	SystemLanguageKorean,
	SystemLanguageLatvian,
	SystemLanguageLithuanian,
	SystemLanguageNorwegian,
	SystemLanguagePolish,
	SystemLanguagePortuguese,
	SystemLanguageRomanian,
	SystemLanguageRussian,
	SystemLanguageSerboCroatian,
	SystemLanguageSlovak,
	SystemLanguageSlovenian,
	SystemLanguageSpanish,
	SystemLanguageSwedish,
	SystemLanguageThai,
	SystemLanguageTurkish,
	SystemLanguageUkrainian,
	SystemLanguageVietnamese,
	SystemLanguageUnknown
};

namespace systeminfo {

	std::string GetOperatingSystem();
	std::string GetProcessorType();
	int EXPORT_COREMODULE GetProcessorCount();
	int GetNumberOfCores();
	int GetPhysicalMemoryMB();
	int GetUsedVirtualMemoryMB();
	int GetExecutableSizeMB();
	int GetSystemLanguage();
	std::string GetSystemLanguageISO();

#if UNITY_WIN
	ULONG_PTR GetCoreAffinityMask(DWORD core);
	std::string GetBIOSIdentifier();
#endif

#if UNITY_XENON
	void SetExecutableSizeMB(UInt32 sizeMB);
#endif

#if UNITY_WIN || UNITY_OSX || UNITY_LINUX
// Windows: 500=2000, 510=XP, 520=2003, 600=Vista
// Mac: 1006=Snow Leopard
// Linux: kernel version 206 = 2.6
int GetOperatingSystemNumeric();

int GetProcessorSpeed();
std::string GetMacAddress();
#endif

#if UNITY_EDITOR && (UNITY_WIN || UNITY_OSX)
unsigned char* GetMacAddressForBeast ();
#endif

#if WEBPLUG && UNITY_OSX
bool IsRunningInDashboardWidget();
#endif

#if UNITY_WP8
int GetCommitedMemoryLimitMB();
int GetCommitedMemoryMB();
#endif

inline RuntimePlatform GetRuntimePlatform()
{

	#if UNITY_EDITOR
		#if UNITY_OSX
		return OSXEditor;
		#elif UNITY_WIN
		return WindowsEditor;
		#elif UNITY_LINUX
		return LinuxEditor;
		#else
		#error Unknown platform
		#endif
	#else
		#if UNITY_OSX
			#if WEBPLUG
			#if !UNITY_PEPPER
			if (systeminfo::IsRunningInDashboardWidget ())
				return OSXDashboardPlayer;
			else
			#endif
				return OSXWebPlayer;
			#else
			return OSXPlayer;
			#endif
		#elif UNITY_WIN && !UNITY_WINRT
			#if WEBPLUG
			return WindowsWebPlayer;
			#else
			return WindowsPlayer;
			#endif
		#elif UNITY_WP8
			return WP8Player;
		#elif UNITY_METRO
			#if __arm__
				return MetroPlayerARM;
			#else
				return MetroPlayerX86;
			#endif
		#elif UNITY_WII
			return WiiPlayer;
		#elif UNITY_XENON
			return XenonPlayer;
		#elif UNITY_PS3
			return PS3Player;
		#elif UNITY_IPHONE
			return iPhonePlayer;
		#elif UNITY_ANDROID
			return AndroidPlayer;
		#elif UNITY_BB10
			return BB10Player;
		#elif UNITY_TIZEN
			return TizenPlayer;
		#elif UNITY_PEPPER
			#if UNITY_NACL_WEBPLAYER
				// Since we want to be fully compatible with existing content
				// we need to pretend we are a normal web player.
				return WindowsWebPlayer;
			#else
				return NaClWebPlayer;
			#endif
		#elif UNITY_LINUX
			#if WEBPLUG
				return LinuxWebPlayer;
			#else
				return LinuxPlayer;
			#endif
		#elif UNITY_FLASH
			return FlashPlayer;
		#elif UNITY_WEBGL
			return WebGLPlayer;
		#else
			#error Unknown platform
		#endif
	#endif
}

inline bool IsPlatformStandalone( RuntimePlatform p ) {
	return p==WindowsPlayer || p==OSXPlayer || p == LinuxPlayer;
}
inline bool IsPlatformWebPlayer( RuntimePlatform p ) {
	return p==WindowsWebPlayer || p==OSXWebPlayer || p==OSXDashboardPlayer;
}

inline std::string GetRuntimePlatformString(RuntimePlatform p)
{
	switch (p)
	{
	case OSXEditor:          return "OSXEditor";
	case OSXPlayer:          return "OSXPlayer";
	case WindowsPlayer:      return "WindowsPlayer";
	case OSXWebPlayer:       return "OSXWebPlayer";
	case OSXDashboardPlayer: return "OSXDashboardPlayer";
	case WindowsWebPlayer:   return "WindowsWebPlayer";
	case WiiPlayer:          return "WiiPlayer";
	case WindowsEditor:      return "WindowsEditor";
	case iPhonePlayer:       return "iPhonePlayer";
	case PS3Player:          return "PS3Player";
	case XenonPlayer:        return "XenonPlayer";
	case AndroidPlayer:      return "AndroidPlayer";
	case NaClWebPlayer:      return "NaClWebPlayer";
	case LinuxPlayer:        return "LinuxPlayer";
	case LinuxWebPlayer:     return "LinuxWebPlayer";
	case FlashPlayer:        return "FlashPlayer";
	case LinuxEditor:        return "LinuxEditor";
	case WebGLPlayer:        return "WebGL";
	case MetroPlayerX86:     return "MetroPlayerX86";
	case MetroPlayerX64:     return "MetroPlayerX64";
	case MetroPlayerARM:     return "MetroPlayerARM";
	case WP8Player:          return "WP8Player";
	case BB10Player:         return "BB10Player";
	case TizenPlayer:        return "TizenPlayer";
	default:
		#if !UNITY_EXTERNAL_TOOL
		AssertString("Unknown platform.");
		#endif
		return "Unknown";
	}
}

inline std::string GetRuntimePlatformString()
{
	return GetRuntimePlatformString(GetRuntimePlatform());
}

	std::string GetPersistentDataPath();		/// A path for data that can be considered "long-lived", possibly to time of un-installation.
	std::string GetTemporaryCachePath();		/// A path for "short-term" data, that may out-live the running session.
#if !UNITY_FLASH
	char const* GetDeviceUniqueIdentifier ();
	char const* GetDeviceName ();
	char const* GetDeviceModel ();
	char const* GetDeviceSystemName ();
	char const* GetDeviceSystemVersion ();
#endif

	inline bool IsHandheldPlatform ()
	{
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_BB10 || UNITY_WP8 || UNITY_TIZEN
		return true;
#else
		return false;
#endif
	}

#if UNITY_WINRT
	bool SupportsAccelerometer ();
#else
	inline bool SupportsAccelerometer ()
	{
		return IsHandheldPlatform ();
	}
#endif

	inline bool SupportsLocationService ()
	{
		return IsHandheldPlatform ();
	}


#if UNITY_ANDROID || UNITY_IPHONE
	bool SupportsVibration ();
#else
	inline bool SupportsVibration ()
	{
		return IsHandheldPlatform ();
	}
#endif


	inline DeviceType DeviceType ()
	{
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_BB10 || UNITY_WP8 || UNITY_TIZEN
		return kDeviceTypeHandheld;
#elif UNITY_EDITOR || UNITY_PEPPER || UNITY_FLASH \
      || UNITY_OSX || (UNITY_WIN && !UNITY_WP8) || UNITY_LINUX || UNITY_WEBGL
		return kDeviceTypeDesktop;
#elif UNITY_WII || UNITY_XENON || UNITY_PS3
		return kDeviceTypeConsole;
#else
		#error Should never get here. Add your platform.
		return kDeviceTypeUknown;
#endif
	}
} // namespace

#endif