-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathuenvironmentchecker.pas
257 lines (230 loc) · 9.17 KB
/
uenvironmentchecker.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
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
unit uEnvironmentChecker; // New to v3.3.0
{$mode objfpc}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
{$ifdef Windows} windows, {$endif} FileUtil, sha1, dbases_sqlite;
type
MEMORYSTATUSEX = record
dwLength : DWORD;
dwMemoryLoad : DWORD;
ullTotalPhys : uint64;
ullAvailPhys : uint64;
ullTotalPageFile : uint64;
ullAvailPageFile : uint64;
ullTotalVirtual : uint64;
ullAvailVirtual : uint64;
ullAvailExtendedVirtual : uint64;
end;
{ TfrmEnvironmentCheck }
TfrmEnvironmentCheck = class(TForm)
btnCheckNow: TButton;
memEnvList: TMemo;
procedure FormCreate(Sender: TObject);
procedure btnCheckNowClick(Sender: TObject);
function DLLScan(expectedPath : rawbytestring) : Boolean; // To scan Windows DLLs
function FormatByteSize(const bytes: QWord): string;
{$ifdef Windows}
function GetSystemMem: string; // Returns installed RAM (as viewed by your OS) in GB, with 2 decimals }
{$endif}
private
public
end;
var
frmEnvironmentCheck: TfrmEnvironmentCheck;
implementation
{ TfrmEnvironmentCheck }
{$IFDEF WINDOWS}
// Populate interface with quick view to RAM status
function GlobalMemoryStatusEx(var Buffer: MEMORYSTATUSEX): BOOL; stdcall; external 'kernel32' name 'GlobalMemoryStatusEx';
// http://stackoverflow.com/questions/7859978/get-total-and-available-memory-when-4-gb-installed
// Returns installed RAM (as viewed by your OS) in Gb\Tb} as string. Empty string on failure.
function TfrmEnvironmentCheck.GetSystemMem: string;
VAR
MS_Ex : MemoryStatusEx;
strTotalPhysMem, strTotalPhysAvail : string;
begin
result := '';
FillChar(MS_Ex{%H-}, SizeOf(MemoryStatusEx), #0);
MS_Ex.dwLength := SizeOf(MemoryStatusEx);
if GlobalMemoryStatusEx(MS_Ex) then
begin
strTotalPhysMem := FormatByteSize(MS_Ex.ullTotalPhys);
strTotalPhysAvail := FormatByteSize(MS_Ex.ullAvailPhys);
Result:= strTotalPhysMem + ' total, ' + #10#13 +
strTotalPhysAvail + ' available' + #10#13;
end
else Result := 'No Data';
end;
{$ENDIF}
function TfrmEnvironmentCheck.FormatByteSize(const bytes: QWord): string;
var
B: byte;
KB: word;
MB: QWord;
GB: QWord;
TB: QWord;
begin
B := 1; //byte
KB := 1024 * B; //kilobyte
MB := 1024 * KB; //megabyte
GB := 1024 * MB; //gigabyte
TB := 1024 * GB; //terabyte
if bytes > TB then
result := FormatFloat('#.## TiB', bytes / TB)
else
if bytes > GB then
result := FormatFloat('#.## GiB', bytes / GB)
else
if bytes > MB then
result := FormatFloat('#.## MiB', bytes / MB)
else
if bytes > KB then
result := FormatFloat('#.## KiB', bytes / KB)
else
if bytes > B then
result := FormatFloat('#.## bytes', bytes)
else
if bytes = 0 then
result := '0 bytes';
end;
function TfrmEnvironmentCheck.DLLScan(expectedPath : rawbytestring) : Boolean;
{// On Windows :
libewf-x64.dll 5D33227712DA76316613DCD88B2749916DBA5ACA
libewf-x86.dll 915E3F26E170A062312A8CD73462AE6ECA6EF7BA
libgcc_s_dw2-1.dll 201924954A5A593C4CA24EE0FE799A764B41598D
libwinpthread-1.dll 34E84ED8F69F05FCAD212B02C2B064A5C7377904
sqlite3-win32.dll 220680d789e002bf2822aa3ef428d2af01496033
sqlite3-win64.dll c82d5cfe8ffb243a670d65258c25e9c101820ab7
zlib1.dll (32-bit copy) B1D1FECBB568EDCF712232738BA3805B47BC6036
zlib1.dll (64-bit copy) A10687C37DEB2CE5422140B541A64AC15534250F
// On Linux :
libewf-Linux-x64.so 2376C9092754ABF401CFA1D17C00801DAAB4D143
}
var
sl : TStringList;
i : integer = Default(integer);
ExpectedFileCount : integer = Default(integer);
ComputedHash : string = Default(string);
LibraryName : string = Default(string);
begin
result := false;
ExpectedFileCount := 5;
{$ifdef Windows}
{$ifdef CPU32}
memEnvList.Text:= 'Number of DLLs expected : ' + IntToStr(ExpectedFileCount) + '. ' + LineEnding +
'Expected DLLs and SHA-1 hashes: ' + LineEnding +
'libewf-x86.dll' + #9#9 + '915E3F26E170A062312A8CD73462AE6ECA6EF7BA' + Lineending+
'libgcc_s_dw2-1.dll' + #9#9 + '201924954A5A593C4CA24EE0FE799A764B41598D' + Lineending+
'libwinpthread-1.dll' + #9#9 + '34E84ED8F69F05FCAD212B02C2B064A5C7377904' + Lineending+
'sqlite3-win32.dll' + #9#9 + '220680d789e002bf2822aa3ef428d2af01496033' + Lineending+
'zlib1.dll (x86 copy)' + #9#9 + 'B1D1FECBB568EDCF712232738BA3805B47BC6036' + Lineending+
'===================================================================' + Lineending;
{$else ifdef CPU64}
memEnvList.Text:= 'Number of DLLs expected : ' + IntToStr(ExpectedFileCount) + '. ' + LineEnding +
'Expected DLLs and SHA-1 hashes: ' + LineEnding +
'libewf-x64.dll' + #9#9 + '5D33227712DA76316613DCD88B2749916DBA5ACA' + Lineending +
'libgcc_s_dw2-1.dll' + #9#9 + '201924954A5A593C4CA24EE0FE799A764B41598D' + Lineending +
'libwinpthread-1.dll' + #9#9 + '34E84ED8F69F05FCAD212B02C2B064A5C7377904' + Lineending +
'sqlite3-win64.dll' + #9#9 + 'C82D5CFE8FFB243A670D65258C25E9C101820AB7' + Lineending +
'zlib1.dll (x64 copy)' + #9#9 + 'A10687C37DEB2CE5422140B541A64AC15534250F' + Lineending +
'=========================================================================' + Lineending;
{$endif}
{$endif}
{$ifdef Linux}
memEnvList.Text:= 'Number of SO files expected : 1' + LineEnding +
'Expected SO file: libewf-Linux-x64.so' + Lineending;
{$endif}
try
memEnvList.Lines.Add('Found these libraries and computed SHA-1 hashes:');
sl := TStringList.Create;
{$ifdef Windows}
FindAllFiles(sl, expectedPath, '*.dll', true, faAnyFile);
{$endif}
{$ifdef Linux}
FindAllFiles(sl, expectedPath, '*.so', true, faAnyFile);
{$endif}
{$ifdef Darwin}
// do nothing but keep the compiler happy . This function isnt even called on OSX
// but compiling on OSX will require rewriting the code below with the following if statement
if sl.count = 1 then
{$endif}
begin
for i := 0 to sl.count -1 do
begin
LibraryName := ExtractFileName(sl.strings[i]);
ComputedHash := Uppercase(SHA1Print(SHA1File(sl.strings[i])));
memEnvList.Lines.Add(LibraryName + #9#9 + ComputedHash);
end;
end;
finally
memEnvList.Lines.Add('Number of libraries found : ' + IntToStr(sl.count));
memEnvList.Lines.Add('=========================================================================' + Lineending);
sl.Free;
result := true;
end;
end;
procedure TfrmEnvironmentCheck.FormCreate(Sender: TObject);
begin
memEnvList.Clear;
end;
procedure TfrmEnvironmentCheck.btnCheckNowClick(Sender: TObject);
var
{$ifdef Windows}
{$ifdef CPU32}
LIB_FOLDER : ansistring = 'libs\x86';
{$else ifdef CPU64}
LIB_FOLDER : ansistring = 'libs\x64';
{$endif}
{$endif}
{$ifdef Linux}
{$ifdef CPU32}
LIB_FOLDER : ansistring = 'libs/x86';
{$else ifdef CPU64}
LIB_FOLDER : ansistring = 'libs/x64';
{$endif}
{$endif}
ExpectedDLLPath : rawbytestring;
AreDLLsPresent : Boolean = Default(Boolean);
strActiveDB : string = Default(string);
strDBVersion : string = Default(string);
strRAMData : string = Default(string);
begin
memEnvList.Lines.Add('Checking environment. Please wait...');
{$ifdef Windows}
// Check DLLs for Windows installs and other Windows based checks
ExpectedDLLPath := ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER);
AreDLLsPresent := DLLScan(ExpectedDLLPath);
if AreDLLsPresent = false then
begin
memEnvList.Lines.Add('At least 1 DLL is missing. QuickHash may not function fully.');
end;
strRAMData := GetSystemMem;
if Length(strRAMData) > 0 then
begin
memEnvList.Lines.Add('RAM Data : '+ strRAMData);
end;
{$endif}
{$ifdef Darwin}
memEnvList.Lines.Add('Libraries are mostly part of OSX natively since Big Sur except libewf which is not available on OSX with Quickhash yet. So skipping library check.');
{$endif}
{$ifdef Linux}
ExpectedDLLPath := ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER);
AreDLLsPresent := DLLScan(ExpectedDLLPath);
if AreDLLsPresent = false then memEnvList.Lines.Add('At least 1 SO file is missing. QuickHash may not function fully.');
{$endif}
// Show SQLite Name
strActiveDB := dbases_sqlite.frmSQLiteDBases.DBName;
if Length(strActiveDB) > 0 then memEnvList.Lines.Add('SQLite Database Name : ' + strActiveDB)
else memEnvList.Lines.Add('SQLite Database name : Unknown');
// Show SQLite version
strDBVersion := frmSQLiteDBases.DBVersionLookup;
if Length(strDBVersion) > 0 then
memEnvList.Lines.Add(strDBVersion) else
memEnvList.Lines.Add('SQlite version could not be determined');
Application.ProcessMessages;
frmEnvironmentCheck.Visible:= true;
end;
initialization
{$I uenvironmentchecker.lrs}
end.