-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetMeterGlobal.pas
More file actions
510 lines (447 loc) · 15.3 KB
/
NetMeterGlobal.pas
File metadata and controls
510 lines (447 loc) · 15.3 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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
// ************************************************************************** //
// NetMeter 1.1.4 BETA //
// Copyright (C) 2009 Oliver Winterholler //
// ************************************************************************** //
// This file is part of NetMeter. //
// //
// NetMeter is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// NetMeter is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with NetMeter. If not, see <http://www.gnu.org/licenses/>. //
// ************************************************************************** //
unit NetMeterGlobal;
interface
uses
Graphics, SysUtils, Windows, Classes, Controls, TypInfo, Registry, Forms,
NetMeterTrafficLog, NetMeterGraph, IPHLPAPI;
type
NotifyRecord =
record
NotifyName: string;
NotifyType: integer;
Cmd : string;
NotifyMonitoringProblems : boolean;
// Traffic alert options
TVAlertEnabled : boolean;
TrafficLimit,
TrafficLimitUnit,
TrafficLimitULorDL,
TrafficLimitPeriod : integer;
end;
NMOptionsRecord =
record
// Window properties
AlwaysOnTop,
ShowCaption,
StartMinimized,
MinimizeWhenIdle,
DisplayAverageValues,
CloseToTray,
SnapToScreenEdges,
ClickThrough,
FadingEnabled,
MouseFadingEnabled,
MouseFadingIn,
TransparencyEnabled : boolean;
TransparencyValue : integer;
RunOnStartup,
UseOldDUDescription,
UseOldTrayIcons : boolean;
// Totals and Report options
WeekStartsOn,
MonthStartsOn,
TotalsDisplayUnit : integer;
LogfileAutosaveEnabled : boolean;
LogfileAutosaveMinutes : integer;
// Interface to monitor
IFToMonitor : integer;
IFDescription : IF_DESCRIPTION;
IFMAC : MAC;
// Visual options
Bandwidth : integer;
Autoscale,
ShowHorGrid,
ShowPanel,
ShowPanelTotals,
ShowMaxValue,
Gradient : boolean;
VertGrid,
UDDisplayUnit,
TUDDisplayUnit,
MVDisplayUnit : integer;
FontUD,
FontMV : GR_FontType;
FontAutosize : boolean;
Color : GR_ColorsType;
// Notifications
Notify: array of NotifyRecord;
end;
DU_DisplaySymbol =
record
Name,
Shortcut,
Alt_Shortcut,
Equals : string;
Digits : integer;
Value : Int64;
end;
DU_DisplayUnit =
record
Name : string;
Bitmultiplier : cardinal;
Symbol : array[0..3] of DU_DisplaySymbol;
end;
const
Version_Int = 114;
BetaVersion = TRUE;
Build_Date = '08-09-2009';
Win2k_or_newer = 5;
WinVista_or_newer = 6;
Autorun_Regkey = 'Software\Microsoft\Windows\CurrentVersion\Run';
FNT_Default_9x : string = ('MS Sans Serif');
FNT_Default_2k : string = ('Microsoft Sans Serif');
FRM_InitPos = Low(integer);
FRM_BorderThreshold = 10;
FRM_MinWidth = 0;
FRM_MinHeight = 0;
FRM_DefWidth = 200;
FRM_DefHeight = 150;
BW_Autodetect = 0;
BW_Custom = -1;
DU_Kilobit = 0;
DU_Kibibit = 1;
DU_Kilobyte = 2;
DU_Kibibyte = 3;
DU_k = 0;
DU_m = 1;
DU_g = 2;
DU_t = 3;
DU_Unit : array[0..3] of DU_DisplayUnit =
(
( Name : 'Kilobit'; Bitmultiplier : 8; Symbol :
(
( Name : 'Kilobit'; Shortcut : 'kb'; Alt_Shortcut : 'Kb'; Equals : '= 1000 Bit'; Digits : 1; Value : 1000 ),
( Name : 'Megabit'; Shortcut : 'Mb'; Alt_Shortcut : 'Mb'; Equals : '= 1000 Kilobit'; Digits : 2; Value : 1000000 ),
( Name : 'Gigabit'; Shortcut : 'Gb'; Alt_Shortcut : 'Gb'; Equals : '= 1000 Megabit'; Digits : 3; Value : 1000000000 ),
( Name : 'Terabit'; Shortcut : 'Tb'; Alt_Shortcut : 'Tb'; Equals : '= 1000 Gigabit'; Digits : 4; Value : 1000000000000 )
)
),
( Name : 'Kibibit'; Bitmultiplier : 8; Symbol :
(
( Name : 'Kibibit'; Shortcut : 'Kibit'; Alt_Shortcut : 'Kb'; Equals : '= 1024 Bit'; Digits : 1; Value : 1024 ),
( Name : 'Mebibit'; Shortcut : 'Mibit'; Alt_Shortcut : 'Mb'; Equals : '= 1024 Kibibit'; Digits : 2; Value : 1048576 ),
( Name : 'Gibibit'; Shortcut : 'Gibit'; Alt_Shortcut : 'Gb'; Equals : '= 1024 Mebibit'; Digits : 3; Value : 1073741824 ),
( Name : 'Tebibit'; Shortcut : 'Tibit'; Alt_Shortcut : 'Tb'; Equals : '= 1024 Gibibit'; Digits : 4; Value : 1099511627776 )
)
),
( Name : 'Kilobyte'; Bitmultiplier : 1; Symbol :
(
( Name : 'Kilobyte'; Shortcut : 'kB'; Alt_Shortcut : 'KB'; Equals : '= 1000 Byte'; Digits : 1; Value : 1000 ),
( Name : 'Megabyte'; Shortcut : 'MB'; Alt_Shortcut : 'MB'; Equals : '= 1000 Kilobyte'; Digits : 2; Value : 1000000 ),
( Name : 'Gigabyte'; Shortcut : 'GB'; Alt_Shortcut : 'GB'; Equals : '= 1000 Megabyte'; Digits : 3; Value : 1000000000 ),
( Name : 'Terabyte'; Shortcut : 'TB'; Alt_Shortcut : 'TB'; Equals : '= 1000 Gigabyte'; Digits : 4; Value : 1000000000000 )
)
),
( Name : 'Kibibyte'; Bitmultiplier : 1; Symbol :
(
( Name : 'Kibibyte'; Shortcut : 'KiB'; Alt_Shortcut : 'KB'; Equals : '= 1024 Byte'; Digits : 1; Value : 1024 ),
( Name : 'Mebibyte'; Shortcut : 'MiB'; Alt_Shortcut : 'MB'; Equals : '= 1024 Kibibyte'; Digits : 2; Value : 1048576 ),
( Name : 'Gibibyte'; Shortcut : 'GiB'; Alt_Shortcut : 'GB'; Equals : '= 1024 Mebibyte'; Digits : 3; Value : 1073741824 ),
( Name : 'Gibibyte'; Shortcut : 'TiB'; Alt_Shortcut : 'TB'; Equals : '= 1024 Gibibyte'; Digits : 4; Value : 1099511627776 )
)
)
);
TLG_FileName = 'NetMeter.tlg';
//Fading stuff
FG_FadeOut = 0;
FG_FadeIn = 1;
FG_FadeLow = 2;
FG_FadeUpToNormal = 3;
FG_FadeFull = 4;
FG_FadeDownToNormal = 5;
FG_StepDef = 8;
FG_IntervalDef = 25;
//Minimize when idle stuff
MWI_MinTimeToWait = 30; {seconds to wait until graph is minimized}
MWI_ResTimeToWait = 5; {seconds to wait until graph is restored}
//Mouse sensitive fading stuff
MA_FadeLow = 0;
MA_FadeUpToNormal = 1;
MA_FadeFull = 2;
MA_FadeDownToNormal = 3;
MF_FadeFullTimeToWait = 0;
MF_FadeDownToNormalTimeToWait = 0;
MF_FadeLowTimeToWait = 0;
MF_FadeUpToNormalTimeToWait = 2 {seconds} * 40 {1 second / MF_Timer.Interval};
PBT_APMQUERYSUSPEND = $0;
PBT_APMQUERYSTANDBY = $1;
PBT_APMQUERYSUSPENDFAILED = $2;
PBT_APMQUERYSTANDBYFAILED = $3;
PBT_APMSUSPEND = $4;
PBT_APMSTANDBY = $5;
PBT_APMRESUMECRITICAL = $6;
PBT_APMRESUMESUSPEND = $7;
PBT_APMRESUMESTANDBY = $8;
NT_Balloon = 0;
NT_Popup = 1;
NT_Cmd = 2;
//Digit imput stuff
Zero = '';
Digits : set of char = ['0','1','2','3','4','5','6','7','8','9'];
Backspace = #8;
//Presets
BW_Values : array[0..15] of integer = (
BW_Autodetect,
56000,
64000,
128000,
384000,
768000,
1536000,
1544000,
10000000,
11000000,
22000000,
44736000,
54000000,
100000000,
1000000000,
BW_Custom);
VertGrid_Values : array[0..4] of integer = (
-1,
10,
20,
30,
60);
DisplayUnit_Values : array[0..3] of integer = (
DU_Kilobit,
DU_Kibibit,
DU_Kilobyte,
DU_Kibibyte);
TrafficLimitUnit_Values : array[0..3] of integer = (
TL_Megabytes,
TL_Mebibytes,
TL_Gigabytes,
TL_Gibibytes);
TrafficLimitULorDL_Values : array[0..2] of integer = (
TL_UpAndDown,
TL_UploadOnly,
TL_DownloadOnly);
TrafficLimitPeriod_Values : array[0..2] of integer = (
TL_Day,
TL_Week,
TL_Month);
NotifyType_Values : array[0..2] of integer = (
NT_Balloon,
NT_Popup,
NT_Cmd);
// INI-file stuff
INI_ReadOK = 0;
INI_WriteOK = 1;
INI_ReadError = -1;
INI_WriteError = -2;
INI_LoadSaveErrMsg : array[-2..-1] of string = (
'Error saving "%s"!',
'Error reading "%s"!' );
Ini_FileName = 'NetMeter.ini';
Ini_VerSection = 'Version'; //Version
Ini_Version = 'ProgramVersion';
Ini_PosSection = 'Position'; //Position
Ini_PosLeft = 'Left';
Ini_PosTop = 'Top';
Ini_PosWidth = 'Width';
Ini_PosHeight = 'Height';
Ini_OptSection = 'Options'; //Options
Ini_OptAOT = 'AlwaysOnTop';
Ini_OptSC = 'ShowCaption';
Ini_OptSM = 'StartMinimized';
Ini_OptMWI = 'MinimizeWhenIdle';
Ini_OptDAV = 'DisplayAverageValues';
Ini_OptCTT = 'CloseToTray';
Ini_OptSSE = 'SnapToScreenEdges';
Ini_OptTE = 'TransparencyEnabled';
Ini_OptTV = 'TransparencyValue';
Ini_OptCT = 'ClickThrough';
Ini_OptFE = 'FadingEnabled';
Ini_OptMFE = 'MouseFadingEnabled';
Ini_OptMFI = 'MouseFadingIn';
Ini_OptTIBH = 'TrayIconBalloonHints';
Ini_OptCMD = 'NotifyCmd';
Ini_OptNT = 'NotifyType';
Ini_OptNMP = 'NotifyMonitoringProblems';
Ini_OptUOD = 'UseOldDUDescription';
Ini_OptUOTI = 'UseOldTrayIcons';
Ini_OptWSO = 'WeekStartsOn';
Ini_OptMSO = 'MonthStartsOn';
Ini_OptTDU = 'TotalsDisplayUnit';
Ini_OptTVAE = 'TrafficVolumeAlertEnabled';
Ini_OptTL = 'TrafficLimit';
Ini_OptTLU = 'TrafficLimitUnit';
Ini_OptTLULDL = 'TrafficLimitULorDL';
Ini_OptTLP = 'TrafficLimitPeriod';
Ini_OptLFAS = 'LogfileAutosave';
Ini_OptLFASM = 'LogfileAutosaveMinutes';
Ini_OptIFTM = 'NetworkInterfaceToMonitor';
Ini_OptIFD = 'NetworkInterfaceDescription';
Ini_OptIFM = 'NetworkInterfaceMAC';
Ini_OptBW = 'Bandwidth';
Ini_OptGRAS = 'GraphAutoScale';
Ini_OptGRSHG = 'GraphShowHorizontalGrid';
Ini_OptGRVG = 'GraphVertGrid';
Ini_OptGRSP = 'GraphShowPanel';
Ini_OptGRSPT = 'GraphShowPanelTotals';
Ini_OptGRSMV = 'GraphShowMaxValue';
Ini_OptUDDU = 'UDDisplayUnit';
Ini_OptTUDDU = 'TUDDisplayUnit';
Ini_OptMVDU = 'MVDisplayUnit';
Ini_OptGRGB = 'GraphGradientBackground';
Ini_OptFNT_UD_N = 'UDPanelFontName';
Ini_OptFNT_UD_S = 'UDPanelFontSize';
Ini_OptFNT_UD_B = 'UDPanelFontBold';
Ini_OptFNT_UD_I = 'UDPanelFontItalic';
Ini_OptFNT_MV_N = 'MVPanelFontName';
Ini_OptFNT_MV_S = 'MVPanelFontSize';
Ini_OptFNT_MV_B = 'MVPanelFontBold';
Ini_OptFNT_MV_I = 'MVPanelFontItalic';
Ini_OptFAS = 'FontAutosize';
Ini_Opt_MV_BC = 'MaxValueBorderColor';
Ini_Opt_MV_BGC = 'MaxValueBackgroundColor';
Ini_Opt_MV_FC = 'MaxValueFontColor';
Ini_Opt_PN_BRC = 'PanelBorderColor';
Ini_Opt_PN_BGC = 'PanelBackgroundColor';
Ini_Opt_PN_ULC = 'PanelULColor';
Ini_Opt_PN_DLC = 'PanelDLColor';
Ini_Opt_GR_BRC = 'GraphBorderColor';
Ini_Opt_GR_BGC1 = 'GraphBackgroundColor1';
Ini_Opt_GR_BGC2 = 'GraphBackgroundColor2';
Ini_Opt_GR_GC = 'GraphGridColor';
Ini_Opt_GR_ULC = 'UploadColor';
Ini_Opt_GR_DLC = 'DownloadColor';
Ini_Opt_GR_UDC = 'UpDnColor';
function MinWinVersion(min_MajorVersion: Cardinal) : boolean;
function GetRunOnStartup : boolean;
procedure SetRunOnStartup;
procedure DeleteRunOnStartup;
function UDValueToStr(displayvalue : Int64; displayunit : integer; old_shortcut : boolean): string;
procedure ModifyFontsFor(ctrl: TWinControl; fontname : string);
var
NMO,
NMO_TMP : NMOptionsRecord;
NM_AppDataDir : string;
implementation
function MinWinVersion(min_MajorVersion: Cardinal) : boolean;
var
OS_VersionInfo : TOSVersionInfo;
begin
OS_VersionInfo.dwOSVersionInfoSize := SizeOf(OS_VersionInfo);
if GetVersionEx(OS_VersionInfo) then
result := (OS_VersionInfo.dwPlatformId = VER_PLATFORM_WIN32_NT) and (OS_VersionInfo.dwMajorVersion >= min_MajorVersion)
else
result := FALSE;
end;
function GetRunOnStartup : boolean;
var
reg: TRegistry;
begin
Result := FALSE;
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey ( Autorun_Regkey, FALSE );
Result := reg.ValueExists( Application.Title );
finally
reg.Free;
end;
end;
procedure SetRunOnStartup;
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey ( Autorun_Regkey, FALSE );
reg.WriteString ( Application.Title, Application.ExeName )
finally
reg.Free;
end;
end;
procedure DeleteRunOnStartup;
var
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
reg.OpenKey ( Autorun_Regkey, FALSE );
if reg.ValueExists( Application.Title ) then
reg.DeleteValue ( Application.Title );
finally
reg.Free;
end;
end;
function UDValueToStr(displayvalue : Int64; displayunit : integer; old_shortcut : boolean): string;
var
divider : Int64;
s : string;
d, sc : integer;
found : boolean;
begin
with DU_Unit[displayunit] do
begin
with Symbol[DU_k] do
begin
divider := Value;
if old_shortcut then s := Alt_Shortcut else s := Shortcut;
d := Digits;
end;
sc := DU_t;
found := FALSE;
repeat
begin
if Abs( displayvalue * Bitmultiplier ) >= Symbol[sc].Value then
with Symbol[sc] do
begin
divider := Value;
if old_shortcut then s := Alt_Shortcut else s := Shortcut;
d := Digits;
found := TRUE;
end;
dec(sc);
end
until ( sc = 0 ) or found;
result := FloatToStrF( displayvalue * Bitmultiplier / divider, ffNumber, 15, d ) + #32 + s;
end;
end;
procedure ModifyFontsFor(ctrl: TWinControl; fontname : string);
var
i: integer;
procedure ModifyFont(ctrl: TControl);
var
f: TFont;
begin
if IsPublishedProp( ctrl, 'Parentfont' ) and
( GetOrdProp( ctrl, 'Parentfont' ) = Ord(false) ) and
IsPublishedProp(ctrl, 'font') then
begin
f := TFont(GetObjectProp(ctrl, 'font', TFont));
f.Name := fontname;
end;
end;
begin
ModifyFont(ctrl);
for i := 0 to ctrl.controlcount - 1 do
if ctrl.controls[i] is Twincontrol then
ModifyFontsfor( TWincontrol( ctrl.controls[i] ), fontname )
else
Modifyfont( ctrl.controls[i] );
end;
end.