-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.cs
More file actions
377 lines (345 loc) · 10.8 KB
/
Device.cs
File metadata and controls
377 lines (345 loc) · 10.8 KB
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/*
* Copyright (C) 12/10/2020 VX STATS <sales@vxstats.com>
*
* This document is property of VX STATS. It is strictly prohibited
* to modify, sell or publish it in any way. In case you have access
* to this document, you are obligated to ensure its nondisclosure.
* Noncompliances will be prosecuted.
*
* Diese Datei ist Eigentum der VX STATS. Jegliche Änderung, Verkauf
* oder andere Verbreitung und Veröffentlichung ist strikt untersagt.
* Falls Sie Zugang zu dieser Datei haben, sind Sie verpflichtet,
* alles in Ihrer Macht stehende für deren Geheimhaltung zu tun.
* Zuwiderhandlungen werden strafrechtlich verfolgt.
*/
/* using */
using System;
#if __MOBILE__
using Xamarin.Essentials;
#else
using Microsoft.Win32;
#endif
/**
* @~english
* @brief The vxstats namespace.
*
* @~german
* @brief Der vxstats Namensraum.
*/
namespace vxstats
{
public sealed class Device
{
private static string model = "";
private static string vendor = "";
private static string version = "";
private static string osVersion = "0.0.0";
private static bool darkMode = false;
private static readonly bool jailbroken = false;
private static bool tabletMode = false;
private static readonly bool touchScreen = false;
private static readonly Device instance = new Device();
static Device()
{
}
private Device()
{
#if __MOBILE__
model = DeviceInfo.Model;
switch (Xamarin.Forms.Device.RuntimePlatform)
{
case Xamarin.Forms.Device.iOS:
vendor = "Apple Inc.";
if (model.Equals("x86_64"))
{
model = "iOS Simulator";
}
else
{
var versionBegin = model.IndexOf( "," );
if ( versionBegin > 1 && Char.IsDigit( model, versionBegin - 1 ) ) {
--versionBegin;
}
if ( versionBegin > 1 && Char.IsDigit( model, versionBegin - 1 ) ) {
--versionBegin;
}
version = model.Substring(versionBegin, model.Length - versionBegin);
model = model.Substring(0, versionBegin);
}
break;
case Xamarin.Forms.Device.Android:
vendor = "Google Inc.";
if (model.Contains("Android SDK built"))
{
model = "Android Simulator";
}
else
{
string[] androidInfos = model.Split(' ');
if (androidInfos.Length == 2)
{
model = androidInfos[0];
version = androidInfos[1];
}
else
{
androidInfos = model.Split('-');
if (androidInfos.Length == 2)
{
model = androidInfos[0];
version = androidInfos[1];
}
}
}
break;
case Xamarin.Forms.Device.UWP:
default:
string[] infos = model.Split(' ');
if ( infos.Length == 2 )
{
model = infos[0];
version = infos[1];
}
else {
infos = model.Split('-');
if ( infos.Length == 2 )
{
model = infos[0];
version = infos[1];
}
}
break;
}
if (!DeviceInfo.Manufacturer.Equals("unknown"))
{
vendor = DeviceInfo.Manufacturer;
}
osVersion = DeviceInfo.VersionString;
#else
try
{
using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\SystemInformation"))
{
if (key != null)
{
Object value = key.GetValue("SystemManufacturer");
if (value != null)
{
vendor = value as String;
}
value = key.GetValue("SystemProductName");
if (value != null)
{
model = value as String;
string[] infos = model.Split(' ');
if (infos.Length == 2)
{
model = infos[0];
version = infos[1];
}
else
{
infos = model.Split('-');
if (infos.Length == 2)
{
model = infos[0];
version = infos[1];
}
}
}
}
key.Close();
}
}
catch
{
// Nothing to handle here!
}
#endif
}
public static Device Instance
{
get
{
return instance;
}
}
public string UniqueIdentifier()
{
#if __MOBILE__
string uuid = Preferences.Get("uuid", "", "group.com.vxstat.statistics");
if (uuid == null || uuid.Equals(""))
{
uuid = System.Guid.NewGuid().ToString();
Preferences.Set("uuid", uuid, "group.com.vxstat.statistics");
}
return uuid;
#else
string uuid = System.Guid.NewGuid().ToString();
try
{
try
{
RegistryKey createKey = Registry.CurrentUser.OpenSubKey("SOFTWARE");
createKey.CreateSubKey("group.com.vxstat.statistics");
createKey.CreateSubKey("OrganizationDefaults");
createKey.Close();
}
catch
{
// Do nothing, this is called, if the entry is already given.
}
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\group.com.vxstat.statistics\\OrganizationDefaults", true))
{
if (key != null)
{
Object value = key.GetValue("uuid");
if (value != null)
{
uuid = value as string;
}
else
{
key.SetValue("uuid", uuid);
}
key.Close();
}
}
}
catch
{
// Nothing to handle here!
}
return uuid;
#endif
}
public string Model
{
get
{
return model;
}
set
{
model = value;
}
}
public string Vendor
{
get
{
return vendor;
}
set
{
vendor = value;
}
}
public string Version
{
get
{
return version;
}
set
{
version = value;
}
}
public string OsVersion
{
get
{
return osVersion;
}
}
public bool UseDarkMode()
{
#if __MOBILE__
#else
try
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"))
{
if (key != null)
{
Object value = key.GetValue("AppsUseLightTheme");
if (value != null)
{
if (Convert.ToInt32(value) == 0)
{
darkMode = true;
}
}
key.Close();
}
}
}
catch
{
// Nothing to handle here!
}
#endif
return darkMode;
}
public bool IsJailbroken()
{
return jailbroken;
}
public bool IsTabletMode()
{
#if __MOBILE__
switch (Xamarin.Forms.Device.RuntimePlatform)
{
case Xamarin.Forms.Device.iOS:
return true;
case Xamarin.Forms.Device.Android:
return true;
}
#else
try
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ImmersiveShell"))
{
if (key != null)
{
Object value = key.GetValue("TabletMode");
if (value != null)
{
if (Convert.ToInt32(value) == 1)
{
tabletMode = true;
}
}
key.Close();
}
}
}
catch
{
// Nothing to handle here!
}
#endif
return tabletMode;
}
public bool HasTouchScreen()
{
#if __MOBILE__
switch (Xamarin.Forms.Device.RuntimePlatform)
{
case Xamarin.Forms.Device.iOS:
return true;
case Xamarin.Forms.Device.Android:
return true;
}
#endif
// TODO: Check for touchscreen
return touchScreen;
}
// TODO: Check for voiceover
public bool IsVoiceOverActive()
{
return false;
}
}
}