-
Notifications
You must be signed in to change notification settings - Fork 8
/
TMConfig.pas
2055 lines (1970 loc) · 74.8 KB
/
TMConfig.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
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit TMConfig;
{
Aestan Tray Menu
Made by Onno Broekmans; visit http://www.xs4all.nl/~broekroo/aetraymenu
for more information.
This work is hereby released into the Public Domain. To view a copy of the
public domain dedication, visit:
http://creativecommons.org/licenses/publicdomain/
or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford,
California 94305, USA.
This unit contains the code that handles reading, parsing and handling
the AeTrayMenu configuration file.
}
{
NOTE:
Lots of code from this unit are based on the Inno Setup source code,
which was written by Jordan Russell (portions by Martijn Laan).
Inno Setup is a great, free installer for Windows; see:
http://www.jrsoftware.org
>>PLEASE DO NOT REMOVE THIS NOTE<<
}
interface
uses Windows, SysUtils, Consts, Classes, Contnrs, JvComponent, JvTrayIcon,
ImgList, BarMenus, Controls, Menus, ExtCtrls, Graphics,
TMStruct, TMCmnFunc, TMSrvCtrl;
const
MENUSETTINGSSUFFIX = '.Settings';
//suffix used in TTMConfigReader.ReadBcBarPopupMenu
type
EParseError = class(Exception)
{ This exception class is raised when the TTMConfigReader class
can't read the script because of syntax errors in the script }
public
LineNumber: Integer;
{ The line number on which the parse error occurred }
{ (LineNumber is -1 if it is some kind of 'general' error) }
constructor CreateLine(const Msg: String; const LineNumber: Integer = -1);
constructor CreateLineFmt(const Msg: String; Args: array of const;
const LineNumber: Integer = -1);
end;
TEnumIniSectionProc = procedure(const Line: PChar; const Ext: Longint) of object;
TTMConfigReader = class
private
FTrayIcon: TJvTrayIcon;
FImageList: TImageList;
FServices: TObjectList;
FCheckServicesTimer: TTimer;
FTrayIconSomeRunning: Integer;
FTrayIconNoneRunning: Integer;
FTrayIconAllRunning: Integer;
FSomeRunningHint: String;
FNoneRunningHint: String;
FAllRunningHint: String;
FVariables: TObjectList;
FServiceGlyphRunning: Integer;
FServiceGlyphStopped: Integer;
FServiceGlyphPaused: Integer;
FOnSelectMenuItem: TNotifyEvent;
FDoubleClickAction: TTMMultiAction;
FStartupAction: TTMMultiAction;
FScript: TStringList;
FOnBuiltInActionExecute: TNotifyEvent;
FID: String;
FCustomAboutVersion: String;
FCustomAboutHeader: String;
FCustomAboutText: TStrings;
FHtmlActions: TStringList;
procedure SetScript(const Value: TStringList);
procedure SetCustomAboutText(const Value: TStrings);
protected
{ FIELDS }
{ Miscellaneous internal data }
LineNumber: Integer;
{ The line number of the line the parser is currently working on }
{ This value is used in combination with the AbortParsing(..) procs }
ConfigDirectiveLines: array[TConfigSectionDirective] of Integer;
MessagesDirectiveLines: array[TMessagesSectionDirective] of Integer;
MenuDirectiveLines: array[TMenuSectionDirective] of Integer;
{ METHODS }
{ Exception methods }
procedure AbortParsing(const Msg: String);
{ Raises an EScriptParseError exception; used while reading
the script }
{ The line number is automatically read from "LineNumber" (see above) }
procedure AbortParsingFmt(const Msg: String; const Args: array of const);
{ As AbortParsing, but calls Format(Msg, Args) }
{ Reader methods }
procedure EnumIniSection(const EnumProc: TEnumIniSectionProc;
const SectionName: String; const Ext: Longint);
{ Enumerates values in a specified section, using the EnumProc
procedure as a callback function. "Ext" will be used in the call
to the EnumProc procedure. }
procedure EnumAboutText(const Line: PChar; const Ext: Longint);
procedure EnumConfig(const Line: PChar; const Ext: Longint);
procedure EnumMenuItems(const Line: PChar; const Ext: Integer);
procedure EnumMenuSettings(const Line: PChar; const Ext: Integer);
procedure EnumMultiAction(const Line: PChar; const Ext: Integer);
procedure EnumMessages(const Line: PChar; const Ext: Longint);
procedure EnumServices(const Line: PChar; const Ext: Integer);
procedure EnumVariables(const Line: PChar; const Ext: Integer);
{ Miscellaneous procs }
procedure BreakString(S: PChar; var Output: TBreakStringArray);
function CompareParamName (const S: TBreakStringRec;
const ParamInfo: array of TParamInfo;
var ParamNamesFound: array of Boolean): Integer;
function ISStrToBool(S: String): Boolean;
procedure ISStrToFont(const S: String; F: TFont);
procedure ValidateProperties;
public
{ PROPERTIES }
{ *** Script file buffer *** }
property Script: TStringList read FScript write SetScript;
{ *** Customizable objects *** }
property TrayIcon: TJvTrayIcon read FTrayIcon write FTrayIcon;
property ImageList: TImageList read FImageList write FImageList;
property Services: TObjectList read FServices write FServices;
property CheckServicesTimer: TTimer read FCheckServicesTimer write FCheckServicesTimer;
property Variables: TObjectList read FVariables write FVariables;
property DoubleClickAction: TTMMultiAction read FDoubleClickAction write FDoubleClickAction;
property StartupAction: TTMMultiAction read FStartupAction write FStartupAction;
property HtmlActions: TStringList read FHtmlActions write FHtmlActions;
{ *** Customizable settings *** }
property TrayIconAllRunning: Integer read FTrayIconAllRunning;
property TrayIconSomeRunning: Integer read FTrayIconSomeRunning;
property TrayIconNoneRunning: Integer read FTrayIconNoneRunning;
property AllRunningHint: String read FAllRunningHint;
property SomeRunningHint: String read FSomeRunningHint;
property NoneRunningHint: String read FNoneRunningHint;
property ServiceGlyphRunning: Integer read FServiceGlyphRunning;
property ServiceGlyphPaused: Integer read FServiceGlyphPaused;
property ServiceGlyphStopped: Integer read FServiceGlyphStopped;
property ID: String read FID;
property CustomAboutHeader: String read FCustomAboutHeader write FCustomAboutHeader;
property CustomAboutVersion: String read FCustomAboutVersion write FCustomAboutVersion;
property CustomAboutText: TStrings read FCustomAboutText write SetCustomAboutText;
{ *** Events *** }
property OnSelectMenuItem: TNotifyEvent read FOnSelectMenuItem write FOnSelectMenuItem;
property OnBuiltInActionExecute: TNotifyEvent read FOnBuiltInActionExecute write FOnBuiltInActionExecute;
{ METHODS }
{ *** General procs *** }
constructor Create;
destructor Destroy; override;
{ *** Key procs *** }
procedure ReadSettings;
procedure ReadBcBarPopupMenu(const BcBarPopupMenu: TBcBarPopupMenu;
const SectionName: String);
{ This procedure reads popup menu settings from a section
with name SectionName + MENUSETTINGSSUFFIX, and the menu
from the section with name SectionName }
procedure ReadMenu(const MenuItems: TMenuItem; const SectionName: String);
procedure ReadMultiAction(const MultiAction: TTMMultiAction;
const SectionName: String);
end;
implementation
uses TypInfo, JclStrings, Forms, Registry, JclFileUtils,
TMMsgs;
{ EParseError }
constructor EParseError.CreateLine(const Msg: String;
const LineNumber: Integer = -1);
begin
inherited Create(Msg);
Self.LineNumber := LineNumber;
end;
constructor EParseError.CreateLineFmt(const Msg: String;
Args: array of const; const LineNumber: Integer);
begin
inherited CreateFmt(Msg, Args);
Self.LineNumber := LineNumber;
end;
{ TTMConfigReader }
procedure TTMConfigReader.AbortParsing(const Msg: String);
begin
raise EParseError.CreateLine(Msg, LineNumber);
end;
procedure TTMConfigReader.AbortParsingFmt(const Msg: String;
const Args: array of const);
begin
raise EParseError.CreateLineFmt(Msg, Args, LineNumber);
end;
procedure TTMConfigReader.BreakString(S: PChar;
var Output: TBreakStringArray);
var
ColonPos, SemicolonPos, QuotePos, P, P2: PChar;
ParamName, Data: String;
QuoteFound, FirstQuoteFound, LastQuoteFound, AddChar, FirstNonspaceFound: Boolean;
CurParm, Len, I: Integer;
begin
CurParm := 0;
while (S <> nil) and (CurParm <= High(TBreakStringArray)) do begin
ColonPos := StrScan(S, ':');
if ColonPos = nil then
ParamName := StrPas(S)
else
SetString (ParamName, S, ColonPos-S);
ParamName := Trim(ParamName);
if ParamName = '' then Break;
if ColonPos = nil then
AbortParsingFmt(SParsingParamHasNoValue, [ParamName]);
S := ColonPos + 1;
SemicolonPos := StrScan(S, ';');
QuotePos := StrScan(S, '"');
QuoteFound := QuotePos <> nil;
if QuoteFound and (SemicolonPos <> nil) and (QuotePos > SemicolonPos) then
QuoteFound := False;
if not QuoteFound then begin
Data := '';
P := S;
if SemicolonPos <> nil then
P2 := SemicolonPos
else
P2 := StrEnd(S);
FirstNonspaceFound := False;
Len := 0;
I := 0;
while P < P2 do begin
if (P^ <> ' ') or FirstNonspaceFound then begin
FirstNonspaceFound := True;
Data := Data + P^;
Inc (I);
if P^ <> ' ' then Len := I;
end;
Inc (P);
end;
SetLength (Data, Len);
end
else begin
Data := '';
SemicolonPos := nil;
P := S;
FirstQuoteFound := False;
LastQuoteFound := False;
while P^ <> #0 do begin
AddChar := False;
case P^ of
' ': AddChar := FirstQuoteFound;
'"': if not FirstQuoteFound then
FirstQuoteFound := True
else begin
Inc (P);
if P^ = '"' then
AddChar := True
else begin
LastQuoteFound := True;
while P^ <> #0 do begin
case P^ of
' ': ;
';': begin
SemicolonPos := P;
Break;
end;
else
AbortParsingFmt(SParsingParamQuoteError, [ParamName]);
end;
Inc (P);
end;
Break;
end;
end;
else
if not FirstQuoteFound then
AbortParsingFmt(SParsingParamQuoteError, [ParamName]);
AddChar := True;
end;
if AddChar then
Data := Data + P^;
Inc (P);
end;
if not LastQuoteFound then
AbortParsingFmt(SParsingParamMissingClosingQuote, [ParamName]);
end;
S := SemicolonPos;
if S <> nil then Inc (S);
Output[CurParm].ParamName := ParamName;
Output[CurParm].ParamData := Data;
Inc (CurParm);
end;
end;
function TTMConfigReader.CompareParamName (const S: TBreakStringRec;
const ParamInfo: array of TParamInfo;
var ParamNamesFound: array of Boolean): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to High(ParamInfo) do
if StrIComp(ParamInfo[I].Name, PChar(S.ParamName)) = 0 then begin
Result := I;
if ParamNamesFound[I] then
AbortParsingFmt(SParsingParamDuplicated, [ParamInfo[I].Name]);
ParamNamesFound[I] := True;
if (piNoEmpty in ParamInfo[I].Flags) and (S.ParamData = '') then
AbortParsingFmt(SParsingParamEmpty2, [ParamInfo[I].Name]);
if (piNoQuotes in ParamInfo[I].Flags) and (Pos('"', S.ParamData) <> 0) then
AbortParsingFmt(SParsingParamNoQuotes2, [ParamInfo[I].Name]);
Exit;
end;
{ Unknown parameter }
AbortParsingFmt(SParsingParamUnknownParam, [S.ParamName]);
end;
constructor TTMConfigReader.Create;
begin
inherited Create;
{ Memory initialization }
FScript := TStringList.Create;
FCustomAboutText := TStringList.Create;
{ Other inits }
FTrayIconAllRunning := -1;
FTrayIconSomeRunning := -1;
FTrayIconNoneRunning := -1;
FAllRunningHint := SDefAllRunningHint;
FSomeRunningHint := SDefSomeRunningHint;
FNoneRunningHint := SDefNoneRunningHint;
FServiceGlyphRunning := -1;
FServiceGlyphPaused := -1;
FServiceGlyphStopped := -1;
end;
destructor TTMConfigReader.Destroy;
begin
{ Free memory }
FreeAndNil(FCustomAboutText);
FreeAndNil(FScript);
inherited Destroy;
end;
procedure TTMConfigReader.EnumAboutText(const Line: PChar;
const Ext: Integer);
begin
CustomAboutText.Add(String(Line));
end;
procedure TTMConfigReader.EnumConfig(const Line: PChar; const Ext: Longint);
procedure LoadImageList(BitmapFile: String);
var
Bmp: TBitmap;
begin
Bmp := TBitmap.Create();
try
Bmp.LoadFromFile(BitmapFile);
with ImageList do
begin
Clear;
AddMasked(Bmp, Bmp.Canvas.Pixels[0, Bmp.Height-1]);
end; //with imagelist
finally
FreeAndNil(Bmp);
end; //try..finally
end;
var
KeyName, Value: String;
I, J: Integer;
Directive: TConfigSectionDirective;
MultiAction: TTMMultiAction;
begin
SeparateDirective(Line, KeyName, Value);
if KeyName = '' then
Exit;
I := GetEnumValue(TypeInfo(TConfigSectionDirective), 'cs' + KeyName);
if I = -1 then
AbortParsingFmt(SParsingUnknownDirective, ['Config', KeyName]);
Directive := TConfigSectionDirective(I);
if ConfigDirectiveLines[Directive] <> 0 then
AbortParsingFmt(SParsingEntryAlreadySpecified, ['Config', KeyName]);
ConfigDirectiveLines[Directive] := LineNumber;
case Directive of
csImageList: begin
try
Value := ExpandVariables(Value, Variables);
if PathIsAbsolute(Value) then
LoadImageList(Value)
else
LoadImageList(
PathAppend(ExtractFileDir(Application.ExeName), Value));
except
AbortParsingFmt(SParsingCouldNotLoadFile, [Value, KeyName]);
end;
end;
csServiceCheckInterval: begin
try
CheckServicesTimer.Interval := 1000 * StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csTrayIconAllRunning: begin
if ConfigDirectiveLines[csTrayIcon] <> 0 then
AbortParsing(SParsingAmbiguousTrayIcon);
try
FTrayIconAllRunning := StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csTrayIconSomeRunning: begin
if ConfigDirectiveLines[csTrayIcon] <> 0 then
AbortParsing(SParsingAmbiguousTrayIcon);
try
FTrayIconSomeRunning := StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csTrayIconNoneRunning: begin
if ConfigDirectiveLines[csTrayIcon] <> 0 then
AbortParsing(SParsingAmbiguousTrayIcon);
try
FTrayIconNoneRunning := StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csTrayIcon: begin
if (ConfigDirectiveLines[csTrayIconAllRunning] <> 0) or
(ConfigDirectiveLines[csTrayIconSomeRunning] <> 0) or
(ConfigDirectiveLines[csTrayIconNoneRunning] <> 0) then
AbortParsing(SParsingAmbiguousTrayIcon);
try
Value := ExpandVariables(Value, Variables);
if PathIsAbsolute(Value) then
TrayIcon.Icon.LoadFromFile(Value)
else
TrayIcon.Icon.LoadFromFile(
PathAppend(ExtractFileDir(Application.ExeName), Value));
except
AbortParsingFmt(SParsingCouldNotLoadFile, [Value, KeyName]);
end;
end;
csServiceGlyphRunning: begin
try
FServiceGlyphRunning := StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csServiceGlyphPaused: begin
try
FServiceGlyphPaused := StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csServiceGlyphStopped: begin
try
FServiceGlyphStopped := StrToInt(Value);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [KeyName]);
end;
end;
csID:
FID := Value;
csAboutHeader:
CustomAboutHeader := Value;
csAboutVersion: begin
StrReplace(Value, '\n', #13#10, [rfReplaceAll, rfIgnoreCase]);
CustomAboutVersion := Value;
end;
csAboutTextFile: begin
if CustomAboutText.Count > 0 then
AbortParsing(SParsingAmbiguousAboutText);
try
Value := ExpandVariables(Value, Variables);
if PathIsAbsolute(Value) then
CustomAboutText.LoadFromFile(Value)
else
CustomAboutText.LoadFromFile(
PathAppend(ExtractFileDir(Application.ExeName), Value));
except
AbortParsingFmt(SParsingCouldNotLoadFile, [Value, KeyName]);
end;
end;
csHtmlActions: begin
StrTokenToStrings(Value, ' ', HtmlActions);
for J := 0 to (HtmlActions.Count - 1) do
begin
MultiAction := TTMMultiAction.Create;
try
ReadMultiAction(MultiAction, HtmlActions[J]);
except
FreeAndNil(MultiAction);
raise;
end; //try..except
HtmlActions.Objects[J] := MultiAction;
end;
end;
end; //case directive of
end;
procedure TTMConfigReader.EnumIniSection(const EnumProc: TEnumIniSectionProc;
const SectionName: String; const Ext: Longint);
var
FoundSection: Boolean;
B, L, LastSection: String;
I: Integer;
begin
FoundSection := False;
LineNumber := 0;
LastSection := '';
while LineNumber < Script.Count do
begin
B := Script[LineNumber];
Inc(LineNumber);
L := Trim(B);
{ Check for blank lines or comments }
if (L = '') then
Continue
else
if L[1] = ';' then
Continue;
if L[1] = '[' then
begin
{ Section tag }
I := Pos(']', L);
if I < 3 then
AbortParsing(SParsingSectionTagInvalid);
L := Copy(L, 2, I-2);
if L[1] = '/' then
begin
L := Copy(L, 2, Maxint);
if (LastSection = '') or (not SameText(L, LastSection)) then
AbortParsingFmt(SParsingSectionBadEndTag, [L]);
FoundSection := False;
LastSection := '';
end
else
begin
FoundSection := (CompareText(L, SectionName) = 0);
LastSection := L;
end;
end
else
begin
if not FoundSection then
begin
if LastSection = '' then
AbortParsing(SParsingTextNotInSection);
Continue; { not on the right section }
end;
EnumProc(PChar(B), Ext);
end;
end;
end;
procedure TTMConfigReader.EnumMenuItems(const Line: PChar;
const Ext: Longint);
const
ParamNames: array[0..20] of TParamInfo = (
(Name: ParamMenuItemType; Flags: [piNoEmpty]), //0
(Name: ParamMenuItemCaption; Flags: []), //1
(Name: ParamMenuItemGlyph; Flags: []),
(Name: ParamMenuItemSection; Flags: []),
(Name: ParamActionAction; Flags: []),
(Name: ParamActionFileName; Flags: [piNoQuotes]), //5
(Name: ParamActionParams; Flags: []),
(Name: ParamActionWorkingDir; Flags: []),
(Name: ParamActionShowCmd; Flags: []),
(Name: ParamActionShellExecVerb; Flags: []),
(Name: ParamActionMultiSection; Flags: []), //10
(Name: ParamServiceService; Flags: []),
(Name: ParamActionServiceAction; Flags: []),
(Name: ParamActionHtmlSrc; Flags: []),
(Name: ParamActionHtmlHeader; Flags: []),
(Name: ParamActionHtmlWindowFlags; Flags: []), //15
(Name: ParamActionHtmlHeight; Flags: []),
(Name: ParamActionHtmlWidth; Flags: []),
(Name: ParamActionHtmlLeft; Flags: []),
(Name: ParamActionHtmlTop; Flags: []),
(Name: ParamActionFlags; Flags: [])); //20
var
Params: TBreakStringArray;
ParamNameFound: array[Low(ParamNames)..High(ParamNames)] of Boolean;
NewMenuItem: TMenuItem;
P, I, FoundIndex: Integer;
B: TBuiltInAction;
ParentMenu: TMenuItem;
TMAction: TTMAction;
ItemType: TMenuItemType;
begin
ParentMenu := TMenuItem(Ext);
ItemType := mitItem;
TMAction := nil;
FillChar(ParamNameFound, SizeOf(ParamNameFound), 0);
BreakString(Line, Params);
NewMenuItem := TMenuItem.Create(ParentMenu);
try
with NewMenuItem do
begin
for P := Low(Params) to High(Params) do
with Params[P] do
begin
if ParamName = '' then
System.Break;
case CompareParamName(Params[P], ParamNames, ParamNameFound) of
0: begin
ParamData := UpperCase(Trim(ParamData));
if ParamData = 'ITEM' then
ItemType := mitItem
else if ParamData = 'SEPARATOR' then
begin
ItemType := mitSeparator;
Caption := '-';
end
else if ParamData = 'SERVICESUBMENU' then
ItemType := mitServiceSubMenu
else if ParamData = 'SUBMENU' then
ItemType := mitSubMenu
else
AbortParsingFmt(SParsingUnknownMenuItemType, [ParamData]);
end;
1: begin
if ItemType = mitSeparator then
Hint := ParamData
else
Caption := ParamData;
end;
2: begin
if ItemType in [mitSeparator, mitServiceSubMenu] then
AbortParsingFmt(SParsingInvalidMenuItemParam, [ParamName]);
try
ImageIndex := StrToInt(ParamData);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [ParamName]);
end;
end;
3: begin
if not (ItemType in [mitSubMenu, mitServiceSubMenu]) then
AbortParsingFmt(SParsingInvalidMenuItemParam, [ParamName]);
ReadMenu(NewMenuItem, ParamData);
end;
4: begin
if ItemType <> mitItem then
AbortParsingFmt(SParsingInvalidMenuItemParam, [ParamName]);
ParamData := UpperCase(Trim(ParamData));
if ParamData = 'RUN' then
begin
TMAction := TTMRunAction.Create;
(TMAction as TTMRunAction).Variables := Variables;
end
else if ParamData = 'SHELLEXECUTE' then
begin
TMAction := TTMShellExecuteAction.Create;
(TMAction as TTMShellExecuteAction).Variables := Variables;
end
else if ParamData = 'SERVICE' then
TMAction := TTMServiceAction.Create
else if ParamData = 'MULTI' then
TMAction := TTMMultiAction.Create
else if ParamData = 'HTMLWINDOW' then
begin
TMAction := TTMHtmlWindowAction.Create;
with (TMAction as TTMHtmlWindowAction) do
begin
Variables := Self.Variables;
HtmlActions := Self.HtmlActions;
end; //tmaction as ttmhtmlwindowaction
end
else
begin
FoundIndex := -1;
for B := Low(B) to High(B) do
if SameText('BIA' + ParamData,
UpperCase(GetEnumName(TypeInfo(TBuiltInAction), Ord(B)))) then
begin
FoundIndex := 0;
TMAction := TTMBuiltInAction.Create(B);
with TMAction as TTMBuiltInAction do
OnExecute := OnBuiltInActionExecute;
System.Break;
end; //if sametext
if FoundIndex = -1 then
AbortParsingFmt(SParsingUnknownActionType, [ParamData]);
end;
end;
5: begin
if (TMAction is TTMRunAction) then
(TMAction as TTMRunAction).FileName := ParamData
else if (TMAction is TTMShellExecuteAction) then
(TMAction as TTMShellExecuteAction).FileName := ParamData
else
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
end;
6: begin
if (TMAction is TTMRunAction) then
(TMAction as TTMRunAction).Parameters := ParamData
else if (TMAction is TTMShellExecuteAction) then
(TMAction as TTMShellExecuteAction).Parameters := ParamData
else
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
end;
7: begin
if (TMAction is TTMRunAction) then
(TMAction as TTMRunAction).WorkingDir := ParamData
else if (TMAction is TTMShellExecuteAction) then
(TMAction as TTMShellExecuteAction).WorkingDir := ParamData
else
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
end;
8: begin
ParamData := UpperCase(Trim(ParamData));
if (TMAction is TTMRunAction) then
with TMAction as TTMRunAction do
if ParamData = 'NORMAL' then
ShowCmd := swNormal
else if ParamData = 'HIDDEN' then
ShowCmd := swHidden
else if ParamData = 'MAXIMIZED' then
ShowCmd := swMaximized
else if ParamData = 'MINIMIZED' then
ShowCmd := swMinimized
else
AbortParsingFmt(SParsingUnknownShowCmd, [ParamData])
else if (TMAction is TTMShellExecuteAction) then
with TMAction as TTMShellExecuteAction do
if ParamData = 'NORMAL' then
ShowCmd := swNormal
else if ParamData = 'HIDDEN' then
ShowCmd := swHidden
else if ParamData = 'MAXIMIZED' then
ShowCmd := swMaximized
else if ParamData = 'MINIMIZED' then
ShowCmd := swMinimized
else
AbortParsingFmt(SParsingUnknownShowCmd, [ParamData])
else
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
end;
9: begin
if not (TMAction is TTMShellExecuteAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName])
else
(TMAction as TTMShellExecuteAction).Verb := ParamData;
end;
10: begin
if not (TMAction is TTMMultiAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName])
else
ReadMultiAction(TMAction as TTMMultiAction, ParamData);
end;
11: begin
if (TMAction is TTMServiceAction) or (ItemType = mitServiceSubMenu) then
begin
//We first have to search for the service in the
// "Services" list
FoundIndex := -1;
for I := 0 to Services.Count - 1 do
if SameText((Services[I] as TTMService).ServiceName, Trim(ParamData)) then
begin
FoundIndex := I;
System.Break;
end;
if FoundIndex = -1 then
AbortParsingFmt(SParsingParamUnknownService, [ParamName]);
if TMAction is TTMServiceAction then
(TMAction as TTMServiceAction).Service :=
(Services[FoundIndex] as TTMService)
else
Tag := Longint(Services[FoundIndex]);
end
else //tmaction is ttmserviceaction or itemtype = mitservicesubmenu
AbortParsing(SParsingServiceParamInvalid);
end;
12: begin
if not (TMAction is TTMServiceAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
ParamData := UpperCase(Trim(ParamData));
with TMAction as TTMServiceAction do
if ParamData = 'STARTRESUME' then
Action := saStartResume
else if ParamData = 'PAUSE' then
Action := saPause
else if ParamData = 'STOP' then
Action := saStop
else if ParamData = 'RESTART' then
Action := saRestart
else
AbortParsingFmt(SParsingInvalidServiceAction, [ParamData]);
end;
13: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
(TMAction as TTMHtmlWindowAction).Src := ParamData;
end;
14: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
(TMAction as TTMHtmlWindowAction).Header := ParamData;
end;
15: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
with (TMAction as TTMHtmlWindowAction) do
while True do
case ExtractFlag(ParamData, TMStruct.HtmlWindowFlags) of
-2: System.Break;
-1: AbortParsingFmt(SParsingParamUnknownFlag2, [ParamName]);
0: HtmlWindowFlags := HtmlWindowFlags + [hwfMaximized];
1: HtmlWindowFlags := HtmlWindowFlags + [hwfNoResize];
2: HtmlWindowFlags := HtmlWindowFlags + [hwfNoScrollbars];
3: HtmlWindowFlags := HtmlWindowFlags + [hwfEnableContextMenu];
4: HtmlWindowFlags := HtmlWindowFlags + [hwfNoCloseButton];
5: HtmlWindowFlags := HtmlWindowFlags + [hwfNoHeader];
6: HtmlWindowFlags := HtmlWindowFlags + [hwfAlwaysOnTop];
end; //with (..) do while true do case extractflag of
end;
16: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
try
(TMAction as TTMHtmlWindowAction).Height := StrToInt(ParamData);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [ParamName]);
end;
end;
17: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
try
(TMAction as TTMHtmlWindowAction).Width := StrToInt(ParamData);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [ParamName]);
end;
end;
18: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
try
(TMAction as TTMHtmlWindowAction).Left := StrToInt(ParamData);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [ParamName]);
end;
end;
19: begin
if not (TMAction is TTMHtmlWindowAction) then
AbortParsingFmt(SParsingInvalidActionParam, [ParamName]);
try
(TMAction as TTMHtmlWindowAction).Top := StrToInt(ParamData);
except
AbortParsingFmt(SParsingParamInvalidIntValue, [ParamName]);
end;
end;
20: begin
if not Assigned(TMAction) then
AbortParsing(SParsingCannotAssignActionFlagsYet);
while True do
case ExtractFlag(ParamData, ActionFlags) of
-2: System.Break;
-1: AbortParsingFmt(SParsingParamUnknownFlag2, [ParamName]);
0: TMAction.Flags := TMAction.Flags + [afIgnoreErrors];
1: TMAction.Flags := TMAction.Flags + [afWaitUntilTerminated];
2: TMAction.Flags := TMAction.Flags + [afWaitUntilIdle];
end; //while true do case extractflag of
end;
end; //case
end; //for p do with params[p] do
{ Validation }
//Type:
if (not ParamNameFound[0]) then
AbortParsingFmt(SParsingParamExpected, [ParamMenuItemType]);
//Caption:
if (ItemType in [mitSubMenu, mitItem]) and (not ParamNameFound[1]) then
AbortParsingFmt(SParsingParamExpected, [ParamMenuItemCaption]);
//SubMenu:
if (ItemType in [mitSubMenu, mitServiceSubMenu]) and
(not ParamNameFound[3]) then
AbortParsingFmt(SParsingParamExpected, [ParamMenuItemSection]);
//Service:
if ((ItemType = mitServiceSubMenu) or (TMAction is TTMServiceAction))
and (not ParamNameFound[11]) then
AbortParsingFmt(SParsingParamExpected, [ParamServiceService]);
//FileName:
if ((TMAction is TTMRunAction) or (TMAction is TTMShellExecuteAction))
and (not ParamNameFound[5]) then
AbortParsingFmt(SParsingParamExpected, [ParamActionFileName]);
//Action:
if (ItemType = mitItem) and (not ParamNameFound[4]) then
AbortParsingFmt(SParsingParamExpected, [ParamActionAction]);
//Actions:
if (TMAction is TTMMultiAction) and (not ParamNameFound[10]) then
AbortParsingFmt(SParsingParamExpected, [ParamActionMultiSection]);
//ServiceAction:
if (TMAction is TTMServiceAction) and (not ParamNameFound[12]) then
AbortParsingFmt(SParsingParamExpected, [ParamActionServiceAction]);
//Flags:
if Assigned(TMAction) then
begin
if (afWaitUntilTerminated in TMAction.Flags) and
(not ((TMAction is TTMRunAction) or (TMAction is TTMServiceAction))) then
AbortParsingFmt(SParsingInvalidActionFlag, ['waituntilterminated']);
if (afWaitUntilIdle in TMAction.Flags) and
(not ((TMAction is TTMRunAction) or (TMAction is TTMServiceAction))) then
AbortParsingFmt(SParsingInvalidActionFlag, ['waituntilidle']);
end; //if assigned(tmaction)
end; //with newserviceitem
except
on E: Exception do
begin
FreeAndNil(NewMenuItem);
AbortParsing(E.Message);
Exit;
end;
end;
if ItemType = mitItem then
with NewMenuItem do
begin
Tag := Longint(TMAction);
OnClick := OnSelectMenuItem;
end; //if itemtype = mititem with newmenuitem do
ParentMenu.Add(NewMenuItem);
end;
procedure TTMConfigReader.EnumMenuSettings(const Line: PChar; const Ext: Longint);
var
KeyName, Value: String;
I: Integer;
Directive: TMenuSectionDirective;
begin
SeparateDirective(Line, KeyName, Value);
if KeyName = '' then
Exit;
I := GetEnumValue(TypeInfo(TMenuSectionDirective), 'mn' + KeyName);
if I = -1 then
AbortParsingFmt(SParsingUnknownDirective, ['Menu.*.Settings', KeyName]);
Directive := TMenuSectionDirective(I);
if MenuDirectiveLines[Directive] <> 0 then
AbortParsingFmt(SParsingEntryAlreadySpecified, ['Menu.*.Settings', KeyName]);
MenuDirectiveLines[Directive] := LineNumber;
with TBcBarPopupMenu(Ext) do
case Directive of
mnAutoHotkeys: begin
if ISStrToBool(Value) then
AutoHotkeys := maAutomatic
else
AutoHotkeys := maManual;
end;
mnAutoLineReduction: begin
if ISStrToBool(Value) then
AutoLineReduction := maAutomatic
else
AutoLineReduction := maManual;
end;
mnBarBackPictureDrawStyle: begin
Value := UpperCase(Trim(Value));
with Bar.BarBackPicture do
if Value = 'NORMAL' then
DrawStyle := BarMenus.dsNormal
else if Value = 'STRETCH' then
DrawStyle := BarMenus.dsStretch
else if Value = 'TILE' then
DrawStyle := BarMenus.dsTile
else
AbortParsingFmt(SParsingInvalidDirectiveValue, [Value, KeyName]);
end;
mnBarBackPictureHorzAlignment: begin
Value := UpperCase(Trim(Value));
with Bar.BarBackPicture do
if Value = 'LEFT' then
HorzAlignment := haLeft
else if Value = 'CENTER' then
HorzAlignment := haCenter
else if Value = 'RIGHT' then