forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWizard.pas
3078 lines (2799 loc) · 117 KB
/
Wizard.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 Wizard;
{
Inno Setup
Copyright (C) 1997-2019 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
Wizard form
}
interface
{$I VERSION.INC}
uses
Windows, SysUtils, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls,
SetupForm, Struct, Int64Em, NewCheckListBox, RichEditViewer, NewStaticText,
SetupTypes, NewProgressBar, MsgIDs, PasswordEdit, FolderTreeView, BitmapImage,
NewNotebook, BidiCtrls;
type
TWizardForm = class;
TWizardPage = class;
TWizardPageClass = class of TWizardPage;
TWizardPageStyle = set of (psAlwaysSkip, psNoButtons);
TWizardPageNotifyEvent = procedure(Sender: TWizardPage) of object;
TWizardPageButtonEvent = function(Sender: TWizardPage): Boolean of object;
TWizardPageCancelEvent = procedure(Sender: TWizardPage; var ACancel, AConfirm: Boolean) of object;
TWizardPageShouldSkipEvent = function(Sender: TWizardPage): Boolean of object;
TWizardPage = class(TComponent)
private
FID: Integer;
FOuterNotebookPage: TNewNotebookPage;
FInnerNotebookPage: TNewNotebookPage;
FCaption: String;
FDescription: String;
FOnActivate: TWizardPageNotifyEvent;
FOnBackButtonClick: TWizardPageButtonEvent;
FOnCancelButtonClick: TWizardPageCancelEvent;
FOnNextButtonClick: TWizardPageButtonEvent;
FOnShouldSkipPage: TWizardPageShouldSkipEvent;
FStyle: TWizardPageStyle;
FWizardForm: TWizardForm;
function GetSurface: TNewNotebookPage;
function GetSurfaceColor: TColor;
function GetSurfaceHeight: Integer;
function GetSurfaceWidth: Integer;
procedure SetCaption(const Value: String);
procedure SetDescription(const Value: String);
procedure SyncCaptionAndDescription;
protected
procedure Activate; virtual;
procedure BackButtonClick(var AContinue: Boolean); virtual;
procedure CancelButtonClick(var ACancel, AConfirm: Boolean); virtual;
procedure NextButtonClick(var AContinue: Boolean); virtual;
procedure ShouldSkipPage(var AShouldSkip: Boolean); virtual;
property InnerNotebookPage: TNewNotebookPage read FInnerNotebookPage;
property OuterNotebookPage: TNewNotebookPage read FOuterNotebookPage;
property Style: TWizardPageStyle read FStyle write FStyle;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Caption: String read FCaption write SetCaption;
property Description: String read FDescription write SetDescription;
property ID: Integer read FID;
property Surface: TNewNotebookPage read GetSurface;
property SurfaceColor: TColor read GetSurfaceColor;
property SurfaceHeight: Integer read GetSurfaceHeight;
property SurfaceWidth: Integer read GetSurfaceWidth;
property OnActivate: TWizardPageNotifyEvent read FOnActivate write FOnActivate;
property OnBackButtonClick: TWizardPageButtonEvent read FOnBackButtonClick write FOnBackButtonClick;
property OnCancelButtonClick: TWizardPageCancelEvent read FOnCancelButtonClick write FOnCancelButtonClick;
property OnNextButtonClick: TWizardPageButtonEvent read FOnNextButtonClick write FOnNextButtonClick;
property OnShouldSkipPage: TWizardPageShouldSkipEvent read FOnShouldSkipPage write FOnShouldSkipPage;
end;
TWizardForm = class(TSetupForm)
FCancelButton: TNewButton;
FNextButton: TNewButton;
FBackButton: TNewButton;
FOuterNotebook: TNewNotebook;
FInnerNotebook: TNewNotebook;
FWelcomePage: TNewNotebookPage;
FInnerPage: TNewNotebookPage;
FFinishedPage: TNewNotebookPage;
FLicensePage: TNewNotebookPage;
FPasswordPage: TNewNotebookPage;
FInfoBeforePage: TNewNotebookPage;
FUserInfoPage: TNewNotebookPage;
FSelectDirPage: TNewNotebookPage;
FSelectComponentsPage: TNewNotebookPage;
FSelectProgramGroupPage: TNewNotebookPage;
FSelectTasksPage: TNewNotebookPage;
FReadyPage: TNewNotebookPage;
FPreparingPage: TNewNotebookPage;
FInstallingPage: TNewNotebookPage;
FInfoAfterPage: TNewNotebookPage;
FDiskSpaceLabel: TNewStaticText;
FDirEdit: TEdit;
FGroupEdit: TNewEdit;
FNoIconsCheck: TNewCheckBox;
FPasswordLabel: TNewStaticText;
FPasswordEdit: TPasswordEdit;
FPasswordEditLabel: TNewStaticText;
FReadyMemo: TNewMemo;
FTypesCombo: TNewComboBox;
FBevel: TBevel;
FWizardBitmapImage: TBitmapImage;
FWelcomeLabel1: TNewStaticText;
FInfoBeforeMemo: TRichEditViewer;
FInfoBeforeClickLabel: TNewStaticText;
FMainPanel: TPanel;
FBevel1: TBevel;
FPageNameLabel: TNewStaticText;
FPageDescriptionLabel: TNewStaticText;
FWizardSmallBitmapImage: TBitmapImage;
FReadyLabel: TNewStaticText;
FFinishedLabel: TNewStaticText;
FYesRadio: TNewRadioButton;
FNoRadio: TNewRadioButton;
FWizardBitmapImage2: TBitmapImage;
FWelcomeLabel2: TNewStaticText;
FLicenseLabel1: TNewStaticText;
FLicenseMemo: TRichEditViewer;
FInfoAfterMemo: TRichEditViewer;
FInfoAfterClickLabel: TNewStaticText;
FComponentsList: TNewCheckListBox;
FComponentsDiskSpaceLabel: TNewStaticText;
FBeveledLabel: TNewStaticText;
FStatusLabel: TNewStaticText;
FFilenameLabel: TNewStaticText;
FProgressGauge: TNewProgressBar;
FSelectDirLabel: TNewStaticText;
FSelectStartMenuFolderLabel: TNewStaticText;
FSelectComponentsLabel: TNewStaticText;
FSelectTasksLabel: TNewStaticText;
FLicenseAcceptedRadio: TNewRadioButton;
FLicenseNotAcceptedRadio: TNewRadioButton;
FUserInfoNameLabel: TNewStaticText;
FUserInfoNameEdit: TNewEdit;
FUserInfoOrgLabel: TNewStaticText;
FUserInfoOrgEdit: TNewEdit;
FPreparingErrorBitmapImage: TBitmapImage;
FPreparingLabel: TNewStaticText;
FFinishedHeadingLabel: TNewStaticText;
FUserInfoSerialLabel: TNewStaticText;
FUserInfoSerialEdit: TNewEdit;
FTasksList: TNewCheckListBox;
FRunList: TNewCheckListBox;
FDirBrowseButton: TNewButton;
FGroupBrowseButton: TNewButton;
FSelectDirBitmapImage: TBitmapImage;
FSelectGroupBitmapImage: TBitmapImage;
FSelectDirBrowseLabel: TNewStaticText;
FSelectStartMenuFolderBrowseLabel: TNewStaticText;
FPreparingYesRadio: TNewRadioButton;
FPreparingNoRadio: TNewRadioButton;
FPreparingMemo: TNewMemo;
procedure NextButtonClick(Sender: TObject);
procedure BackButtonClick(Sender: TObject);
procedure CancelButtonClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure NoIconsCheckClick(Sender: TObject);
procedure TypesComboChange(Sender: TObject);
procedure ComponentsListClickCheck(Sender: TObject);
procedure LicenseAcceptedRadioClick(Sender: TObject);
procedure LicenseNotAcceptedRadioClick(Sender: TObject);
procedure UserInfoEditChange(Sender: TObject);
procedure DirBrowseButtonClick(Sender: TObject);
procedure GroupBrowseButtonClick(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
FPageList: TList;
FCurPageID, FNextPageID: Integer;
ExpandedDefaultDirName, ExpandedDefaultGroupName: String;
FPrevAppDir, PrevGroup, PrevSetupType, PrevUserInfoName, PrevUserInfoOrg, PrevUserInfoSerial: String;
PrevNoIcons: Boolean;
PrevSelectedComponents, PrevDeselectedComponents: TStringList;
PrevSelectedTasks, PrevDeselectedTasks: TStringList;
DisableDirPage, DisableProgramGroupPage: Boolean;
InitialSelectedComponents: TStringList;
InitialSetupTypeIndex: Integer;
HasLargeComponents: Boolean;
DoneWithWizard: Boolean;
PrepareToInstallNeedsRestart: Boolean;
EnableAnchorOuterPagesOnResize: Boolean;
EnableAdjustReadyLabelHeightOnResize: Boolean;
procedure AdjustFocus;
procedure CalcCurrentComponentsSpace;
procedure ChangeReadyLabel(const S: String);
function CheckSerialOk: Boolean;
procedure CreateTaskButtons(const SelectedComponents: TStringList);
procedure FindPreviousData;
function GetPreviousPageID: Integer;
function PrepareToInstall(const WizardComponents, WizardTasks: TStringList): String;
function QueryRestartManager(const WizardComponents, WizardTasks: TStringList): String;
procedure RegisterExistingPage(const ID: Integer;
const AOuterNotebookPage, AInnerNotebookPage: TNewNotebookPage;
const ACaption, ADescription: String);
procedure SelectComponents(const SelectComponents, DeselectComponents: TStringList; const KeepFixedComponents: Boolean); overload;
procedure SelectComponentsFromType(const TypeName: String; const OnlySelectFixedComponents: Boolean);
procedure SelectTasks(const SelectTasks, DeselectTasks: TStringList); overload;
function ShouldSkipPage(const PageID: Integer): Boolean;
procedure UpdateComponentSizes;
procedure UpdateComponentSizesEnum(Index: Integer; HasChildren: Boolean; Ext: LongInt);
procedure UpdateCurPageButtonState;
procedure UpdatePage(const PageID: Integer);
procedure UpdateSelectTasksPage;
procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
{ Public declarations }
PrepareToInstallFailureMessage: String;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AddPage(const APage: TWizardPage; const AfterID: Integer);
function AdjustLabelHeight(const ALabel: TNewStaticText): Integer;
procedure CallCancelButtonClick(var ACancel, AConfirm: Boolean);
procedure ChangeFinishedLabel(const S: String);
procedure ClickToStartPage;
procedure ClickThroughPages;
procedure DirTreeRename(Sender: TCustomFolderTreeView; var NewName: string; var Accept: Boolean);
procedure GetComponents(SelectedComponents, DeselectedComponents: TStringList);
procedure GetSelectedComponents(Components: TStringList; const Descriptions, IndentDescriptions: Boolean);
procedure GetSelectedTasks(Tasks: TStringList; const Descriptions, IndentDescriptions, GroupDescriptions: Boolean);
function GetSetupType: PSetupTypeEntry;
procedure GetTasks(SelectedTasks, DeselectedTasks: TStringList);
procedure GroupTreeRename(Sender: TCustomFolderTreeView; var NewName: string; var Accept: Boolean);
procedure IncTopDecHeight(const AControl: TControl; const Amount: Integer);
function PageFromID(const ID: Integer): TWizardPage;
function PageIndexFromID(const ID: Integer): Integer;
procedure SetCurPage(const NewPageID: Integer);
procedure SelectComponents(const ASelectComponents: TStringList); overload;
procedure SelectTasks(const ASelectTasks: TStringList); overload;
procedure FlipSizeAndCenterIfNeeded(const ACenterInsideControl: Boolean;
const CenterInsideControlCtl: TWinControl; const CenterInsideControlInsideClientArea: Boolean); override;
procedure UpdateRunList(const SelectedComponents, SelectedTasks: TStringList);
function ValidateDirEdit: Boolean;
function ValidateGroupEdit: Boolean;
published
property CurPageID: Integer read FCurPageID;
property PrevAppDir: String read FPrevAppDir;
property CancelButton: TNewButton read FCancelButton;
property NextButton: TNewButton read FNextButton;
property BackButton: TNewButton read FBackButton;
property OuterNotebook: TNewNotebook read FOuterNotebook;
property InnerNotebook: TNewNotebook read FInnerNotebook;
property WelcomePage: TNewNotebookPage read FWelcomePage;
property InnerPage: TNewNotebookPage read FInnerPage;
property FinishedPage: TNewNotebookPage read FFinishedPage;
property LicensePage: TNewNotebookPage read FLicensePage;
property PasswordPage: TNewNotebookPage read FPasswordPage;
property InfoBeforePage: TNewNotebookPage read FInfoBeforePage;
property UserInfoPage: TNewNotebookPage read FUserInfoPage;
property SelectDirPage: TNewNotebookPage read FSelectDirPage;
property SelectComponentsPage: TNewNotebookPage read FSelectComponentsPage;
property SelectProgramGroupPage: TNewNotebookPage read FSelectProgramGroupPage;
property SelectTasksPage: TNewNotebookPage read FSelectTasksPage;
property ReadyPage: TNewNotebookPage read FReadyPage;
property PreparingPage: TNewNotebookPage read FPreparingPage;
property InstallingPage: TNewNotebookPage read FInstallingPage;
property InfoAfterPage: TNewNotebookPage read FInfoAfterPage;
property DiskSpaceLabel: TNewStaticText read FDiskSpaceLabel;
property DirEdit: TEdit read FDirEdit;
property GroupEdit: TNewEdit read FGroupEdit;
property NoIconsCheck: TNewCheckBox read FNoIconsCheck;
property PasswordLabel: TNewStaticText read FPasswordLabel;
property PasswordEdit: TPasswordEdit read FPasswordEdit;
property PasswordEditLabel: TNewStaticText read FPasswordEditLabel;
property ReadyMemo: TNewMemo read FReadyMemo;
property TypesCombo: TNewComboBox read FTypesCombo;
property Bevel: TBevel read FBevel;
property WizardBitmapImage: TBitmapImage read FWizardBitmapImage;
property WelcomeLabel1: TNewStaticText read FWelcomeLabel1;
property InfoBeforeMemo: TRichEditViewer read FInfoBeforeMemo;
property InfoBeforeClickLabel: TNewStaticText read FInfoBeforeClickLabel;
property MainPanel: TPanel read FMainPanel;
property Bevel1: TBevel read FBevel1;
property PageNameLabel: TNewStaticText read FPageNameLabel;
property PageDescriptionLabel: TNewStaticText read FPageDescriptionLabel;
property WizardSmallBitmapImage: TBitmapImage read FWizardSmallBitmapImage;
property ReadyLabel: TNewStaticText read FReadyLabel;
property FinishedLabel: TNewStaticText read FFinishedLabel;
property YesRadio: TNewRadioButton read FYesRadio;
property NoRadio: TNewRadioButton read FNoRadio;
property WizardBitmapImage2: TBitmapImage read FWizardBitmapImage2;
property WelcomeLabel2: TNewStaticText read FWelcomeLabel2;
property LicenseLabel1: TNewStaticText read FLicenseLabel1;
property LicenseMemo: TRichEditViewer read FLicenseMemo;
property InfoAfterMemo: TRichEditViewer read FInfoAfterMemo;
property InfoAfterClickLabel: TNewStaticText read FInfoAfterClickLabel;
property ComponentsList: TNewCheckListBox read FComponentsList;
property ComponentsDiskSpaceLabel: TNewStaticText read FComponentsDiskSpaceLabel;
property BeveledLabel: TNewStaticText read FBeveledLabel;
property StatusLabel: TNewStaticText read FStatusLabel;
property FilenameLabel: TNewStaticText read FFileNameLabel;
property ProgressGauge: TNewProgressBar read FProgressGauge;
property SelectDirLabel: TNewStaticText read FSelectDirLabel;
property SelectStartMenuFolderLabel: TNewStaticText read FSelectStartMenuFolderLabel;
property SelectComponentsLabel: TNewStaticText read FSelectComponentsLabel;
property SelectTasksLabel: TNewStaticText read FSelectTasksLabel;
property LicenseAcceptedRadio: TNewRadioButton read FLicenseAcceptedRadio;
property LicenseNotAcceptedRadio: TNewRadioButton read FLicenseNotAcceptedRadio;
property UserInfoNameLabel: TNewStaticText read FUserInfoNameLabel;
property UserInfoNameEdit: TNewEdit read FUserInfoNameEdit;
property UserInfoOrgLabel: TNewStaticText read FUserInfoOrgLabel;
property UserInfoOrgEdit: TNewEdit read FUserInfoOrgEdit;
property PreparingErrorBitmapImage: TBitmapImage read FPreparingErrorBitmapImage;
property PreparingLabel: TNewStaticText read FPreparingLabel;
property FinishedHeadingLabel: TNewStaticText read FFinishedHeadingLabel;
property UserInfoSerialLabel: TNewStaticText read FUserInfoSerialLabel;
property UserInfoSerialEdit: TNewEdit read FUserInfoSerialEdit;
property TasksList: TNewCheckListBox read FTasksList;
property RunList: TNewCheckListBox read FRunList;
property DirBrowseButton: TNewButton read FDirBrowseButton;
property GroupBrowseButton: TNewButton read FGroupBrowseButton;
property SelectDirBitmapImage: TBitmapImage read FSelectDirBitmapImage;
property SelectGroupBitmapImage: TBitmapImage read FSelectGroupBitmapImage;
property SelectDirBrowseLabel: TNewStaticText read FSelectDirBrowseLabel;
property SelectStartMenuFolderBrowseLabel: TNewStaticText read FSelectStartMenuFolderBrowseLabel;
property PreparingYesRadio: TNewRadioButton read FPreparingYesRadio;
property PreparingNoRadio: TNewRadioButton read FPreparingNoRadio;
property PreparingMemo: TNewMemo read FPreparingMemo;
end;
var
WizardForm: TWizardForm;
function ExpandSetupMessage(const Msg: String): String; overload;
function ExpandSetupMessage(const ID: TSetupMessageID): String; overload;
function ListContains(const List: TStringList; const S: String): Boolean;
procedure TidyUpDirName(var Path: String);
procedure TidyUpGroupName(var Path: String);
function ValidateCustomDirEdit(const AEdit: TEdit;
const AllowUNCPath, AllowRootDirectory, AllowNetworkDrive: Boolean): Boolean;
implementation
uses
ShellApi, ShlObj, Types, Msgs, Main, PathFunc, CmnFunc, CmnFunc2,
MD5, InstFunc, SelFolderForm, Extract, Logging, RestartManager, ScriptRunner;
{$R *.DFM}
const
BadDirChars = '/:*?"<>|';
var
CurrentComponentsSpace: Integer64;
function IntToKBStr(const I: Integer64): String;
var
X: Extended;
begin
X := Comp(I) / 1024;
if Frac(X) > 0 then
X := Int(X) + 1; { always round up }
Result := Format('%.0n', [X]);
end;
function IntToMBStr(const I: Integer64): String;
var
X: Extended;
begin
X := (Comp(I) / 1048576) * 10; { * 10 to include a decimal }
if Frac(X) > 0 then
X := Int(X) + 1; { always round up }
X := X / 10;
Result := Format('%.1n', [X]);
end;
function IntToGBStr(const I: Integer64): String;
var
X: Extended;
begin
X := (Comp(I) / 1073741824) * 100; { * 100 to include 2 decimals }
if Frac(X) > 0 then
X := Int(X) + 1; { always round up }
X := X / 100;
Result := Format('%.2n', [X]);
end;
function ExpandSetupMessageEx(const Msg: String; const Space: Integer64): String; overload;
begin
Result := Msg;
{don't localize these}
StringChange(Result, '[name]', ExpandedAppName);
StringChange(Result, '[name/ver]', ExpandedAppVerName);
StringChange(Result, '[kb]', IntToKBStr(Space));
StringChange(Result, '[mb]', IntToMBStr(Space));
StringChange(Result, '[gb]', IntToGBStr(Space));
end;
function ExpandSetupMessageEx(const ID: TSetupMessageID; const Space: Integer64): String; overload;
begin
Result := ExpandSetupMessageEx(SetupMessages[ID], Space);
end;
function ExpandMBOrGBSetupMessage(const MBID, GBID: TSetupMessageID;
const Space: Integer64): String;
begin
if Comp(Space) > 1048471142 then begin
{ Don't allow it to display 1000.0 MB or more. Takes the 'always round up' into account:
1048471142 bytes = 999.8999996185303 MB = '999.9 MB',
1048471143 bytes = 999.9000005722046 MB = '1,000.0 MB'. }
Result := ExpandSetupMessageEx(GBID, Space)
end else
Result := ExpandSetupMessageEx(MBID, Space);
end;
function ExpandSetupMessage(const Msg: String): String; overload;
begin
Result := ExpandSetupMessageEx(Msg, MinimumSpace);
end;
function ExpandSetupMessage(const ID: TSetupMessageID): String; overload;
begin
Result := ExpandSetupMessageEx(ID, MinimumSpace);
end;
function ListContains(const List: TStringList; const S: String): Boolean;
{ Similar to "List.IndexOf(S) <> -1", except it uses CompareText instead of
AnsiCompareText (which is locale-sensitive and thus unsuitable for our
purposes). }
var
I: Integer;
begin
for I := 0 to List.Count-1 do
if CompareText(List[I], S) = 0 then begin
Result := True;
Exit;
end;
Result := False;
end;
procedure TidyUpDirName(var Path: String);
{ Tidies up a directory name }
begin
{ Trim spaces, normalize slashes, remove any trailing backslash, then repeat
the process if necessary (e.g. in the 'C:\Program Files\My Program\ \'
case) }
repeat
Path := RemoveBackslashUnlessRoot(PathNormalizeSlashes(Trim(Path)));
until Length(Path) = Length(Trim(Path));
end;
procedure TidyUpGroupName(var Path: String);
{ Tidies up a program group name }
begin
{ Trim spaces, remove leading/extra/trailing backslash(es), then repeat the
process if necessary (e.g. in the '\ \My Program\ \' case) }
repeat
Path := Trim(Path);
while (Path <> '') and PathCharIsSlash(Path[1]) do
Delete(Path, 1, 1);
Path := RemoveBackslash(PathNormalizeSlashes(Path));
until Length(Path) = Length(Trim(Path));
end;
function ContainsControlCharacters(const S: String): Boolean;
{ Returns True if S contains any control characters (#0..#31) }
var
I: Integer;
begin
for I := 1 to Length(S) do
if S[I] <= #31 then begin
Result := True;
Exit;
end;
Result := False;
end;
function PathComponentsContainTrailingSpaces(const S: String): Boolean;
{ Returns True if one or more components of the path contain trailing spaces,
which are invalid in Win32. }
var
P: PChar;
begin
P := PChar(S);
while P^ <> #0 do begin
if (P^ = ' ') and ((P[1] = '\') or (P[1] = #0)) then begin
Result := True;
Exit;
end;
P := PathStrNextChar(P);
end;
Result := False;
end;
function PathComponentsContainInvalidDots(const S: String): Boolean;
{ Returns True if one or more components of the path contain only dots,
i.e. '.', '..', '...', etc. One or two dots represent relative paths; three
or more dots are invalid. }
var
P: PChar;
HasDots: Boolean;
begin
P := PChar(S);
while P^ <> #0 do begin
{ Skip over leading spaces; we want ' .' to return True also }
while P^ = ' ' do
Inc(P);
HasDots := False;
while P^ = '.' do begin
HasDots := True;
Inc(P);
end;
{ Skip over trailing spaces; we want '. ' to return True also }
while P^ = ' ' do
Inc(P);
if HasDots and ((P^ = '\') or (P^ = #0)) then begin
Result := True;
Exit;
end;
{ Skip to next component }
while (P^ <> #0) and (P^ <> '\') do
P := PathStrNextChar(P);
if P^ = '\' then
Inc(P);
end;
Result := False;
end;
function SpaceString(const S: String): String;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(S) do begin
if S[I] = ' ' then Continue;
if Result <> '' then Result := Result + ' ';
Result := Result + S[I];
end;
end;
function TWizardForm.AdjustLabelHeight(const ALabel: TNewStaticText): Integer;
{ Increases or decreases a label's height so that all text fits.
Returns the difference in height. }
begin
Result := ALabel.AdjustHeight;
end;
procedure TWizardForm.IncTopDecHeight(const AControl: TControl; const Amount: Integer);
begin
AControl.SetBounds(AControl.Left, AControl.Top + Amount,
AControl.Width, AControl.Height - Amount);
end;
function TWizardForm.CheckSerialOk(): Boolean;
begin
if NeedSerial and (CodeRunner <> nil) then begin
WizardUserInfoName := UserInfoNameEdit.Text;
WizardUserInfoOrg := UserInfoOrgEdit.Text;
WizardUserInfoSerial := UserInfoSerialEdit.Text;
Result := CodeRunner.RunBooleanFunctions('CheckSerial', [UserInfoSerialEdit.Text], bcTrue, True, False)
end else
Result := True;
end;
procedure TWizardForm.CalcCurrentComponentsSpace();
var
SelectedComponents: TStringList;
I: Integer;
CurFile: PSetupFileEntry;
begin
CurrentComponentsSpace := SetupHeader.ExtraDiskSpaceRequired;
SelectedComponents := TStringList.Create();
GetSelectedComponents(SelectedComponents, False, False);
//we can't simply sum component sizes because of shared files -> add file sizes
for I := 0 to Entries[seFile].Count-1 do begin
CurFile := PSetupFileEntry(Entries[seFile][I]);
if (CurFile.Tasks = '') and (CurFile.Check = '') and {don't count tasks or scripted entries}
ShouldProcessFileEntry(SelectedComponents, nil, CurFile, True) then begin
with CurFile^ do begin
if LocationEntry <> -1 then
Inc6464(CurrentComponentsSpace, PSetupFileLocationEntry(Entries[seFileLocation][LocationEntry])^.OriginalSize)
else
Inc6464(CurrentComponentsSpace, ExternalSize)
end;
end;
end;
//don't forget to add extradiskspacerequired values
for I := 0 to Entries[seComponent].Count-1 do
with PSetupComponentEntry(Entries[seComponent][I])^ do
if ListContains(SelectedComponents, Name) then
Inc6464(CurrentComponentsSpace, ExtraDiskSpaceRequired);
SelectedComponents.Free();
ComponentsDiskSpaceLabel.Caption := ExpandMBOrGBSetupMessage(
msgComponentsDiskSpaceMBLabel, msgComponentsDiskSpaceGBLabel, CurrentComponentsSpace);
end;
procedure TWizardForm.UpdateComponentSizesEnum(Index: Integer; HasChildren: Boolean; Ext: LongInt);
var
ComponentEntry: PSetupComponentEntry;
ComponentSize, ChildrenSize: Integer64;
begin
ComponentEntry := PSetupComponentEntry(ComponentsList.ItemObject[Index]);
ChildrenSize.Hi := 0;
ChildrenSize.Lo := 0;
if HasChildren then
ComponentsList.EnumChildrenOf(Index, UpdateComponentSizesEnum, LongInt(@ChildrenSize));
ComponentSize := ComponentEntry.Size;
Inc6464(ComponentSize, ChildrenSize);
if ComponentsList.Checked[Index] then
Inc6464(Integer64(Pointer(Ext)^), ComponentSize);
if (ComponentSize.Lo <> 0) or (ComponentSize.Hi <> 0) then begin
if not HasLargeComponents then
ComponentsList.ItemSubItem[Index] := FmtSetupMessage1(msgComponentSize1, IntToKBStr(ComponentSize))
else
ComponentsList.ItemSubItem[Index] := FmtSetupMessage1(msgComponentSize2, IntToMBStr(ComponentSize));
end else
ComponentsList.ItemSubItem[Index] := '';
end;
procedure TWizardForm.UpdateComponentSizes();
var
Size: Integer64;
begin
if shShowComponentSizes in SetupHeader.Options then begin
Size.Hi := 0;
Size.Lo := 0;
ComponentsList.EnumChildrenOf(-1, UpdateComponentSizesEnum, LongInt(@Size));
end;
end;
{ TWizardPage }
constructor TWizardPage.Create(AOwner: TComponent);
begin
inherited;
FWizardForm := AOwner as TWizardForm;
end;
destructor TWizardPage.Destroy;
begin
if Assigned(FWizardForm) and Assigned(FWizardForm.FPageList) then
FWizardForm.FPageList.Remove(Self);
inherited;
end;
procedure TWizardPage.Activate;
begin
if Assigned(FOnActivate) then
FOnActivate(Self);
end;
procedure TWizardPage.BackButtonClick(var AContinue: Boolean);
begin
if Assigned(FOnBackButtonClick) then
AContinue := FOnBackButtonClick(Self);
end;
procedure TWizardPage.CancelButtonClick(var ACancel, AConfirm: Boolean);
begin
if Assigned(FOnCancelButtonClick) then
FOnCancelButtonClick(Self, ACancel, AConfirm);
end;
procedure TWizardPage.NextButtonClick(var AContinue: Boolean);
begin
if Assigned(FOnNextButtonClick) then
AContinue := FOnNextButtonClick(Self);
end;
procedure TWizardPage.ShouldSkipPage(var AShouldSkip: Boolean);
begin
if Assigned(FOnShouldSkipPage) then
AShouldSkip := FOnShouldSkipPage(Self);
end;
function TWizardPage.GetSurface: TNewNotebookPage;
begin
if FOuterNotebookPage = FWizardForm.InnerPage then
Result := FInnerNotebookPage
else
Result := FOuterNotebookPage;
end;
function TWizardPage.GetSurfaceColor: TColor;
begin
Result := TNewNotebook(Surface.Parent).Color;
end;
function TWizardPage.GetSurfaceHeight: Integer;
begin
Result := Surface.Parent.Height;
end;
function TWizardPage.GetSurfaceWidth: Integer;
begin
Result := Surface.Parent.Width;
end;
procedure TWizardPage.SetCaption(const Value: String);
begin
FCaption := ExpandSetupMessage(Value);
SyncCaptionAndDescription;
end;
procedure TWizardPage.SetDescription(const Value: String);
begin
FDescription := ExpandSetupMessage(Value);
SyncCaptionAndDescription;
end;
procedure TWizardPage.SyncCaptionAndDescription;
begin
if FWizardForm.CurPageID = FID then begin
FWizardForm.PageNameLabel.Caption := FCaption;
FWizardForm.PageDescriptionLabel.Caption := FDescription;
end;
end;
{ TWizardForm }
constructor TWizardForm.Create(AOwner: TComponent);
{ Do all initialization of the wizard form. We're overriding Create instead of
using the FormCreate event, because if an exception is raised in FormCreate
it's not propagated out. }
procedure LoadSelectDirAndGroupImages;
procedure IconToBitmapImage(const AIcon: HICON; const Ctl: TBitmapImage; const BkColor: TColor);
begin
if AIcon <> 0 then begin
try
with Ctl.Bitmap do begin
Width := 32;
Height := 32;
Canvas.Brush.Color := BkColor;
Canvas.FillRect(Rect(0, 0, 32, 32));
DrawIconEx(Canvas.Handle, 0, 0, AIcon, 32, 32, 0, 0, DI_NORMAL);
end;
finally
DestroyIcon(AIcon);
end;
end;
end;
var
FileInfo: TSHFileInfo;
Path: String;
begin
{ Set sizes (overrides any scaling) }
SelectDirBitmapImage.Width := 32;
SelectDirBitmapImage.Height := 32;
SelectGroupBitmapImage.Width := 32;
SelectGroupBitmapImage.Height := 32;
try
{ We have to extract the icons ourself using ExtractIcon because the
icons SHGetFileInfo returns differ in size depending on whether
"Use large icons" is turned on, and we don't want that.
Note: We *could* avoid SHGetFileInfo altogether and pass 'shell32.dll'
and a hard-coded index directly to ExtractIcon, but I'm worried that
might not work in a future Windows version. }
if (SHGetFileInfo('c:\directory', FILE_ATTRIBUTE_DIRECTORY, FileInfo,
SizeOf(FileInfo), SHGFI_USEFILEATTRIBUTES or SHGFI_ICONLOCATION) <> 0) and
(FileInfo.szDisplayName[0] <> #0) then
IconToBitmapImage(ExtractIcon(HInstance, FileInfo.szDisplayName,
FileInfo.iIcon), SelectDirBitmapImage, SelectDirPage.Color);
if WindowsVersionAtLeast(6, 0) then begin
{ On Windows Vista and 7, use the "Taskbar and Start Menu Properties"
icon as there is no longer a separate icon for Start Menu folders }
IconToBitmapImage(ExtractIcon(HInstance,
PChar(AddBackslash(WinSystemDir) + 'shell32.dll'), 39),
SelectGroupBitmapImage, SelectProgramGroupPage.Color);
end
else begin
Path := GetShellFolder(False, sfPrograms, False);
if Path = '' then
Path := GetShellFolder(True, sfPrograms, False);
if Path <> '' then begin
if (SHGetFileInfo(PChar(Path), 0, FileInfo, SizeOf(FileInfo),
SHGFI_ICONLOCATION) <> 0) and (FileInfo.szDisplayName[0] <> #0) then
IconToBitmapImage(ExtractIcon(HInstance, FileInfo.szDisplayName,
FileInfo.iIcon), SelectGroupBitmapImage, SelectProgramGroupPage.Color);
end;
end;
except
{ ignore any exceptions }
end;
end;
function SelectBestImage(WizardImages: TList; TargetWidth, TargetHeight: Integer): TBitmap;
var
TargetArea, Difference, SmallestDifference, I: Integer;
begin
{ Find the image with the smallest area difference compared to the target area. }
TargetArea := TargetWidth*TargetHeight;
SmallestDifference := -1;
Result := nil;
for I := 0 to WizardImages.Count-1 do begin
Difference := Abs(TargetArea-TBitmap(WizardImages[I]).Width*TBitmap(WizardImages[I]).Height);
if (SmallestDifference = -1) or (Difference < SmallestDifference) then begin
Result := WizardImages[I];
SmallestDifference := Difference;
end;
end;
end;
var
X, W1, W2: Integer;
SystemMenu: HMENU;
P: String;
I, DefaultSetupTypeIndex: Integer;
DfmDefault, IgnoreInitComponents: Boolean;
TypeEntry: PSetupTypeEntry;
ComponentEntry: PSetupComponentEntry;
SaveClientWidth, SaveClientHeight: Integer;
begin
inherited;
FPageList := TList.Create;
InitialSelectedComponents := TStringList.Create();
PrevSelectedComponents := TStringList.Create();
PrevDeselectedComponents := TStringList.Create();
PrevSelectedTasks := TStringList.Create();
PrevDeselectedTasks := TStringList.Create();
{$IFDEF IS_D7}
MainPanel.ParentBackground := False;
{$ENDIF}
{ Prior to scaling the form, shrink WizardSmallBitmapImage if it's currently
larger than WizardSmallImage. This way, stretching will not occur if the
user specifies a smaller-than-default image and WizardImageStretch=yes,
except if the form has to be scaled (e.g. due to Large Fonts). }
if WizardSmallImages.Count = 1 then begin
I := WizardSmallBitmapImage.Height - TBitmap(WizardSmallImages[0]).Height;
if I > 0 then begin
WizardSmallBitmapImage.Height := WizardSmallBitmapImage.Height - I;
WizardSmallBitmapImage.Top := WizardSmallBitmapImage.Top + (I div 2);
end;
I := WizardSmallBitmapImage.Width - TBitmap(WizardSmallImages[0]).Width;
if I > 0 then begin
WizardSmallBitmapImage.Width := WizardSmallBitmapImage.Width - I;
WizardSmallBitmapImage.Left := WizardSmallBitmapImage.Left + (I div 2);
end;
end;
{ Not sure why the following is needed but various things related to
positioning and anchoring don't work without this (you get positions of
page controls back as if there was no anchoring until the page handle
is automatically created. Cause might be related to the comment in
TNewNotebook.AlignControls. }
for I := 0 to OuterNotebook.PageCount-1 do
OuterNotebook.Pages[I].HandleNeeded;
for I := 0 to InnerNotebook.PageCount-1 do
InnerNotebook.Pages[I].HandleNeeded;
InitializeFont;
SetFontNameSize(WelcomeLabel1.Font, LangOptions.WelcomeFontName,
LangOptions.WelcomeFontSize, '', 12);
WelcomeLabel1.Font.Style := [fsBold];
PageNameLabel.Font.Style := [fsBold];
if shWindowVisible in SetupHeader.Options then
Caption := SetupMessages[msgSetupAppTitle]
else if shDisableWelcomePage in SetupHeader.Options then
Caption := FmtSetupMessage1(msgSetupWindowTitle, ExpandedAppVerName)
else
Caption := FmtSetupMessage1(msgSetupWindowTitle, ExpandedAppName);
{ Set BorderStyle and BorderIcons:
-WindowVisible + WizardResizable = sizeable
-not WindowVisible + WizardResizable = sizeable + minimize
-WindowVisible + not WizardResizable = dialog = .dfm default = do nothing
-not WindowVisible + not WizardResizable = single + minimize }
DfmDefault := (shWindowVisible in SetupHeader.Options) and not (shWizardResizable in SetupHeader.Options);
if not DfmDefault then begin
{ Save ClientWidth/ClientHeight and restore them after changing BorderStyle. }
SaveClientWidth := ClientWidth;
SaveClientHeight := ClientHeight;
if not(shWindowVisible in SetupHeader.Options) then
BorderIcons := BorderIcons + [biMinimize];
if not(shWizardResizable in SetupHeader.Options) then
BorderStyle := bsSingle
else
BorderStyle := bsSizeable;
ClientWidth := SaveClientWidth;
ClientHeight := SaveClientHeight;
end;
if shWizardResizable in SetupHeader.Options then begin
EnableAnchorOuterPagesOnResize := True;
{ Do not allow user to resize it smaller than 100% nor larger than 150%. }
Constraints.MinHeight := Height;
Constraints.MinWidth := Width;
Constraints.MaxHeight := MulDiv(Height, 150, 100);
Constraints.MaxWidth := MulDiv(Width, 150, 100);
end;
{ Position the buttons, and scale their size }
W1 := CalculateButtonWidth([SetupMessages[msgButtonBack], SetupMessages[msgButtonCancel],
SetupMessages[msgButtonFinish], SetupMessages[msgButtonInstall],
SetupMessages[msgButtonNext]]); { width of each button }
W2 := ScalePixelsX(10); { margin, and space between Next & Cancel }
BackButton.Width := W1;
NextButton.Width := W1;
CancelButton.Width := W1;
X := ClientWidth - W2 - W1;
CancelButton.Left := X;
Dec(X, W2);
Dec(X, W1);
NextButton.Left := X;
Dec(X, W1);
BackButton.Left := X;
{ Initialize wizard style }
if SetupHeader.WizardStyle = wsModern then begin
OuterNotebook.Color := clWindow;
Bevel1.Visible := False;
end;
{ Initialize images }
WizardBitmapImage.Bitmap := SelectBestImage(WizardImages, WizardBitmapImage.Width, WizardBitmapImage.Height);
WizardBitmapImage.Center := True;
WizardBitmapImage.Stretch := (shWizardImageStretch in SetupHeader.Options);
WizardBitmapImage2.Bitmap := WizardBitmapImage.Bitmap;
WizardBitmapImage2.Center := True;
WizardBitmapImage2.Stretch := (shWizardImageStretch in SetupHeader.Options);
WizardSmallBitmapImage.Bitmap := SelectBestImage(WizardSmallImages, WizardSmallBitmapImage.Width, WizardSmallBitmapImage.Height);
WizardSmallBitmapImage.Stretch := (shWizardImageStretch in SetupHeader.Options);
PreparingErrorBitmapImage.Bitmap.Handle := LoadBitmap(HInstance, 'STOPIMAGE');
PreparingErrorBitmapImage.ReplaceColor := RGB(255, 0, 255);
PreparingErrorBitmapImage.ReplaceWithColor := PreparingPage.Color;
LoadSelectDirAndGroupImages;
{ Initialize wpWelcome page }
RegisterExistingPage(wpWelcome, WelcomePage, nil, '', '');
WelcomeLabel1.Caption := ExpandSetupMessage(msgWelcomeLabel1) + SNewLine;
AdjustLabelHeight(WelcomeLabel1);
IncTopDecHeight(WelcomeLabel2, (WelcomeLabel1.Top + WelcomeLabel1.Height) -
WelcomeLabel2.Top);
WelcomeLabel2.Caption := ExpandSetupMessage(msgWelcomeLabel2) + SNewLine2 +
SetupMessages[msgClickNext];
{ Initialize wpLicense page }
RegisterExistingPage(wpLicense, InnerPage, LicensePage,
SetupMessages[msgWizardLicense], SetupMessages[msgLicenseLabel]);
LicenseLabel1.Caption := ExpandSetupMessage(msgLicenseLabel3);
I := AdjustLabelHeight(LicenseLabel1);
IncTopDecHeight(LicenseMemo, I);
LicenseAcceptedRadio.Caption := SetupMessages[msgLicenseAccepted];
LicenseNotAcceptedRadio.Caption := SetupMessages[msgLicenseNotAccepted];
{ Initialize wpPassword page }
RegisterExistingPage(wpPassword, InnerPage, PasswordPage,
SetupMessages[msgWizardPassword], SetupMessages[msgPasswordLabel1]);
PasswordLabel.Caption := SetupMessages[msgPasswordLabel3];
PasswordEditLabel.Caption := SetupMessages[msgPasswordEditLabel];
I := AdjustLabelHeight(PasswordLabel);
PasswordEditLabel.Top := PasswordEditLabel.Top + I;
Inc(I, AdjustLabelHeight(PasswordEditLabel));
PasswordEdit.Top := PasswordEdit.Top + I;
{ Initialize wpInfoBefore page }
RegisterExistingPage(wpInfoBefore, InnerPage, InfoBeforePage,
SetupMessages[msgWizardInfoBefore], SetupMessages[msgInfoBeforeLabel]);
InfoBeforeClickLabel.Caption := SetupMessages[msgInfoBeforeClickLabel];
I := AdjustLabelHeight(InfoBeforeClickLabel);
IncTopDecHeight(InfoBeforeMemo, I);
{ Initialize wpUserInfo page }
RegisterExistingPage(wpUserInfo, InnerPage, UserInfoPage,
SetupMessages[msgWizardUserInfo], SetupMessages[msgUserInfoDesc]);
UserInfoNameLabel.Caption := SetupMessages[msgUserInfoName];
I := AdjustLabelHeight(UserInfoNameLabel);
UserInfoNameEdit.Top := UserInfoNameEdit.Top + I;
UserInfoOrgLabel.Top := UserInfoOrgLabel.Top + I;
UserInfoOrgLabel.Caption := SetupMessages[msgUserInfoOrg];
Inc(I, AdjustLabelHeight(UserInfoOrgLabel));
UserInfoOrgEdit.Top := UserInfoOrgEdit.Top + I;
if NeedSerial then begin
UserInfoSerialLabel.Top := UserInfoSerialLabel.Top + I;
UserInfoSerialLabel.Caption := SetupMessages[msgUserInfoSerial];
Inc(I, AdjustLabelHeight(UserInfoSerialLabel));
UserInfoSerialEdit.Top := UserInfoSerialEdit.Top + I;
end else begin
UserInfoSerialLabel.Visible := False;
UserInfoSerialEdit.Visible := False;
end;