-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVAT.Headers.Utils.pas
107 lines (86 loc) · 2.44 KB
/
VAT.Headers.Utils.pas
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
unit VAT.Headers.Utils;
//************************************************//
// Support for VAT MTD //
// VAT.Headers.Utils //
// provided as is, no warranties //
//************************************************//
interface
uses Winapi.Windows;
type
THMRCMTDUtils = Class
class function ScreensInfo: string;
class function getTimeZone: string;
class function getOSUserName: string;
class function getUserAgent: string;
End;
implementation
uses FMX.Platform, System.SysUtils, FMX.Forms, System.DateUtils, System.StrUtils, System.TimeSpan,
REST.Utils, uSMBIOS;
{ THMRCMTDUtils }
Function GetDisplayBits: Integer;
var
ZeroDC: HDC;
begin
ZeroDC := GetDC(0);
Try
Result := GetDeviceCaps(ZeroDC,BITSPIXEL)*GetDeviceCaps(ZeroDC,PLANES);
Finally
ReleaseDC (0,ZeroDC);
End;
end;
class function THMRCMTDUtils.getOSUserName: string;
Var
lSize: DWORD;
Begin
lSize := 1024;
SetLength(Result, lSize);
If winapi.Windows.GetUserName(PChar(Result), lSize) Then
SetLength(Result, lSize - 1)
Else
RaiseLastOSError;
end;
class function THMRCMTDUtils.ScreensInfo: string;
Resourcestring
tpl = 'width=$W&height=$H&scaling-factor=$S&colour-depth=$C';
Var
ScreenService: IFMXScreenService;
lScale: Single;
Begin
Result := tpl.Replace('$W', Screen.Width.ToString).Replace('$H', Screen.Height.ToString)
.Replace('$C', GetDisplayBits.ToString);
If TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, IInterface(ScreenService)) Then
Begin
Result := Result.Replace('$S', ScreenService.GetScreenScale.ToString);
ScreenService.GetScreenSize
End
Else
Begin
Result := Result.Replace('$S', '1');
End;
end;
class function THMRCMTDUtils.getTimeZone: string;
Var
retval: TTimeSpan;
Begin
retval := TTimeZone.Local.GetUtcOffset(Now);
result := 'UTC' + ifThen(retval.Hours >= 0, '+') + FormatFloat('00', retval.Hours) + ':' +
FormatFloat('00', retval.Minutes);
End;
Class Function THMRCMTDUtils.getUserAgent: String;
Var
i, p: Integer;
ldata: TArray<String>;
bios: TSMBios;
Begin
ldata := TOSVersion.ToString.Split(['(']);
Result := ldata[0].Trim.Replace(' ', '/');
// wmic computersystem get model, manufacturer
bios := TSMBios.Create();
Try
Result := Result + ' (' + URIEncode(bios.SysInfo.ManufacturerStr) + '/' +
URIEncode(bios.SysInfo.ProductNameStr) + ')';
Finally
bios.Free;
End;
End;
end.