forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompWizard.pas
1099 lines (966 loc) · 39.7 KB
/
CompWizard.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 CompWizard;
{
Inno Setup
Copyright (C) 1997-2024 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
Compiler IDE Script Wizard form
}
interface
uses
Windows, Forms, Classes, Graphics, StdCtrls, ExtCtrls, Controls, Dialogs, pngimage,
UIStateForm, NewStaticText, DropListBox, NewCheckListBox, NewNotebook,
CompWizardFilesHelper, CompWizardRegistryHelper;
type
TWizardPage = (wpWelcome, wpAppInfo, wpAppDir, wpAppFiles, wpAppAssoc, wpAppIcons,
wpAppDocs, wpPrivilegesRequired, wpAppRegistry, wpLanguages, wpCompiler,
wpISPP, wpFinished);
TWizardFormResult = (wrNone, wrEmpty, wrComplete);
TWizardForm = class(TUIStateForm)
CancelButton: TButton;
NextButton: TButton;
BackButton: TButton;
OuterNotebook: TNewNotebook;
InnerNotebook: TNewNotebook;
WelcomePage: TNewNotebookPage;
MainPage: TNewNotebookPage;
AppInfoPage: TNewNotebookPage;
AppDirPage: TNewNotebookPage;
AppFilesPage: TNewNotebookPage;
AppIconsPage: TNewNotebookPage;
AppDocsPage: TNewNotebookPage;
PrivilegesRequiredPage: TNewNotebookPage;
AppRegistryPage: TNewNotebookPage;
LanguagesPage: TNewNotebookPage;
CompilerPage: TNewNotebookPage;
ISPPPage: TNewNotebookPage;
FinishedPage: TNewNotebookPage;
Bevel: TBevel;
WelcomeImage: TImage;
WelcomeLabel1: TNewStaticText;
PnlMain: TPanel;
Bevel1: TBevel;
PageNameLabel: TNewStaticText;
PageDescriptionLabel: TNewStaticText;
InnerImage: TImage;
FinishedLabel: TNewStaticText;
FinishedImage: TImage;
WelcomeLabel2: TNewStaticText;
EmptyCheck: TCheckBox;
WelcomeLabel3: TNewStaticText;
AppNameLabel: TNewStaticText;
AppNameEdit: TEdit;
AppVersionLabel: TNewStaticText;
AppVersionEdit: TEdit;
AppDirNameLabel: TNewStaticText;
AppRootDirComboBox: TComboBox;
AppRootDirEdit: TEdit;
AppDirNameEdit: TEdit;
NotDisableDirPageCheck: TCheckBox;
AppRootDirLabel: TNewStaticText;
AppPublisherLabel: TNewStaticText;
AppPublisherEdit: TEdit;
OtherLabel: TNewStaticText;
NotCreateAppDirCheck: TCheckBox;
AppFilesLabel: TNewStaticText;
AppFilesListBox: TDropListBox;
AppFilesAddButton: TButton;
AppFilesEditButton: TButton;
AppFilesRemoveButton: TButton;
AppURLLabel: TNewStaticText;
AppURLEdit: TEdit;
AppExeLabel: TNewStaticText;
AppExeEdit: TEdit;
AppExeRunCheck: TCheckBox;
AppExeButton: TButton;
AppGroupNameLabel: TNewStaticText;
AppGroupNameEdit: TEdit;
NotDisableProgramGroupPageCheck: TCheckBox;
AllowNoIconsCheck: TCheckBox;
AppExeIconsLabel: TNewStaticText;
DesktopIconCheck: TCheckBox;
CreateUninstallIconCheck: TCheckBox;
CreateURLIconCheck: TCheckBox;
AppLicenseFileLabel: TNewStaticText;
AppLicenseFileEdit: TEdit;
AppLicenseFileButton: TButton;
AppInfoBeforeFileLabel: TNewStaticText;
AppInfoBeforeFileEdit: TEdit;
AppInfoBeforeFileButton: TButton;
AppInfoAfterFileLabel: TNewStaticText;
AppInfoAfterFileEdit: TEdit;
AppInfoAfterFileButton: TButton;
RequiredLabel1: TNewStaticText;
RequiredLabel2: TNewStaticText;
AppFilesAddDirButton: TButton;
ISPPCheck: TCheckBox;
ISPPLabel: TLabel;
OutputDirLabel: TNewStaticText;
OutputDirEdit: TEdit;
OutputBaseFileNameLabel: TNewStaticText;
OutputBaseFileNameEdit: TEdit;
SetupIconFileLabel: TNewStaticText;
SetupIconFileEdit: TEdit;
PasswordLabel: TNewStaticText;
PasswordEdit: TEdit;
SetupIconFileButton: TButton;
EncryptionCheck: TCheckBox;
OutputDirButton: TButton;
LanguagesLabel: TNewStaticText;
LanguagesList: TNewCheckListBox;
AllLanguagesButton: TButton;
NoLanguagesButton: TButton;
NoAppExeCheck: TCheckBox;
UseAutoProgramsCheck: TCheckBox;
PrivilegesRequiredLabel: TNewStaticText;
PrivilegesRequiredAdminRadioButton: TRadioButton;
PrivilegesRequiredLowestRadioButton: TRadioButton;
PrivilegesRequiredOverridesAllowedCommandLineCheckbox: TCheckBox;
PrivilegesRequiredOverridesAllowedDialogCheckbox: TCheckBox;
AppAssocPage: TNewNotebookPage;
AppAssocNameEdit: TEdit;
AppAssocNameLabel: TNewStaticText;
CreateAssocCheck: TCheckBox;
AppAssocExtLabel: TNewStaticText;
AppAssocExtEdit: TEdit;
AppRegistryFileLabel: TNewStaticText;
AppRegistryFileEdit: TEdit;
AppRegistryFileButton: TButton;
AppRegistrySettingsLabel: TNewStaticText;
AppRegistryUninsDeleteKeyCheck: TCheckBox;
AppRegistryUninsDeleteKeyIfEmptyCheck: TCheckBox;
AppRegistryUninsDeleteValueCheck: TCheckBox;
AppRegistryMinVerCheck: TCheckBox;
AppRegistryMinVerEdit: TEdit;
AppRegistryMinVerDocImage: TImage;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormDestroy(Sender: TObject);
procedure NextButtonClick(Sender: TObject);
procedure BackButtonClick(Sender: TObject);
procedure FileButtonClick(Sender: TObject);
procedure AppRootDirComboBoxChange(Sender: TObject);
procedure NotCreateAppDirCheckClick(Sender: TObject);
procedure AppExeButtonClick(Sender: TObject);
procedure NotDisableProgramGroupPageCheckClick(Sender: TObject);
procedure PasswordEditChange(Sender: TObject);
procedure OutputDirButtonClick(Sender: TObject);
procedure AllLanguagesButtonClick(Sender: TObject);
procedure NoLanguagesButtonClick(Sender: TObject);
procedure NoAppExeCheckClick(Sender: TObject);
procedure UseAutoProgramsCheckClick(Sender: TObject);
procedure PrivilegesRequiredOverridesAllowedDialogCheckboxClick(Sender: TObject);
procedure CreateAssocCheckClick(Sender: TObject);
private
CurPage: TWizardPage;
FWizardName: String;
FFilesHelper: TWizardFormFilesHelper;
FRegistryHelper: TWizardFormRegistryHelper;
FLanguages: TStringList;
FResult: TWizardFormResult;
FResultScript: String;
function FixLabel(const S: String): String;
procedure SetWizardName(const WizardName: String);
procedure CurPageChanged;
function SkipCurPage: Boolean;
procedure UpdateAppExeControls;
procedure UpdateAppAssocControls;
procedure UpdateAppIconsControls;
procedure GenerateScript;
public
property WizardName: String write SetWizardName;
property Result: TWizardFormResult read FResult;
property ResultScript: String read FResultScript;
end;
implementation
{$R *.DFM}
uses
SysUtils, ShlObj, ActiveX, UITypes, FileClass,
PathFunc, CmnFunc, CmnFunc2, CompFunc, BrowseFunc,
CompMsgs2, CompWizardFile;
type
TConstant = record
Constant, Description: String;
end;
const
NotebookPages: array[TWizardPage, 0..1] of Integer =
((0, -1), (1, 0), (1, 1), (1, 2),
(1, 3), (1, 4), (1, 5), (1, 6),
(1, 7), (1, 8), (1, 9), (1, 10), (2, -1));
PageCaptions: array[TWizardPage] of String =
(SWizardWelcome, SWizardAppInfo, SWizardAppDir, SWizardAppFiles, SWizardAppAssoc,
SWizardAppIcons, SWizardAppDocs, SWizardPrivilegesRequired, SWizardAppRegistry,
SWizardLanguages, SWizardCompiler, SWizardISPP, SWizardFinished);
PageDescriptions: array[TWizardPage] of String =
('', SWizardAppInfo2, SWizardAppDir2, SWizardAppFiles2, SWizardAppAssoc2,
SWizardAppIcons2, SWizardAppDocs2, SWizardPrivilegesRequired2, SWizardAppRegistry2,
SWizardLanguages2, SWizardCompiler2, SWizardISPP2, '');
RequiredLabelVisibles: array[TWizardPage] of Boolean =
(False, True, True, True, True, True, False, True, False, True, False, False, False);
AppRootDirs: array[0..0] of TConstant =
(
( Constant: '{autopf}'; Description: 'Program Files folder')
);
LanguagesDefaultIsl = 'Default.isl';
LanguagesDefaultIslDescription = 'English';
EnabledColors: array[Boolean] of TColor = (clBtnFace, clWindow);
function EscapeAmpersands(const S: String): String;
begin
Result := S;
StringChangeEx(Result, '&', '&&', True);
end;
function TWizardForm.FixLabel(const S: String): String;
begin
Result := S;
{don't localize these}
StringChange(Result, '[name]', FWizardName);
end;
procedure TWizardForm.SetWizardName(const WizardName: String);
begin
FWizardName := WizardName;
end;
{ --- }
type
TNotebookAccess = class(TNotebook);
procedure TWizardForm.FormCreate(Sender: TObject);
procedure AddLanguages(const Extension: String);
var
SearchRec: TSearchRec;
begin
if FindFirst(PathExtractPath(NewParamStr(0)) + 'Languages\*.' + Extension, faAnyFile, SearchRec) = 0 then begin
repeat
FLanguages.Add(SearchRec.Name);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
procedure MakeBold(const Ctl: TNewStaticText);
begin
Ctl.Font.Style := [fsBold];
end;
function SpaceLanguageName(const LanguageName: String): String;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(LanguageName) do begin
if (I <> 1) and CharInSet(LanguageName[I], ['A'..'Z']) then
Result := Result + ' ';
Result := Result + LanguageName[I];
end;
end;
var
I: Integer;
begin
FResult := wrNone;
FWizardName := SWizardDefaultName;
FFilesHelper := TWizardFormFilesHelper.Create(Self,
NotCreateAppDirCheck, AppFilesListBox, AppFilesAddButton, AppFilesAddDirButton,
AppFilesEditButton, AppFilesRemoveButton);
FRegistryHelper := TWizardFormRegistryHelper.Create(Self, AppRegistryFileEdit,
AppRegistryFileButton, AppRegistryUninsDeleteKeyCheck,
AppRegistryUninsDeleteKeyIfEmptyCheck, AppRegistryUninsDeleteValueCheck,
AppRegistryMinVerCheck, AppRegistryMinVerEdit, AppRegistryMinVerDocImage);
FLanguages := TStringList.Create;
FLanguages.Sorted := True;
FLanguages.Duplicates := dupIgnore; { Some systems also return .islu files when searching for *.isl }
AddLanguages('isl');
AddLanguages('islu');
FLanguages.Sorted := False;
FLanguages.Insert(0, LanguagesDefaultIsl);
InitFormFont(Self);
if Font.Name = 'Segoe UI' then begin
{ See Wizard.pas }
for I := 0 to OuterNotebook.PageCount-1 do
OuterNotebook.Pages[I].HandleNeeded;
for I := 0 to InnerNotebook.PageCount-1 do
InnerNotebook.Pages[I].HandleNeeded;
ClientWidth := MulDiv(ClientWidth, 105, 100);
end;
if FontExists('Verdana') then
WelcomeLabel1.Font.Name := 'Verdana';
TNotebookAccess(OuterNotebook).ParentBackground := False;
OuterNotebook.Color := clWindow;
MakeBold(PageNameLabel);
MakeBold(RequiredLabel1);
MakeBold(AppNameLabel);
MakeBold(AppVersionLabel);
MakeBold(AppRootDirLabel);
MakeBold(AppDirNameLabel);
MakeBold(AppExeLabel);
MakeBold(AppAssocNameLabel);
MakeBold(AppAssocExtLabel);
MakeBold(AppGroupNameLabel);
MakeBold(PrivilegesRequiredLabel);
MakeBold(LanguagesLabel);
FinishedImage.Picture := WelcomeImage.Picture;
RequiredLabel2.Left := RequiredLabel1.Left + RequiredLabel1.Width;
{ AppInfo }
AppNameEdit.Text := 'My Program';
AppVersionEdit.Text := '1.5';
AppPublisherEdit.Text := 'My Company, Inc.';
AppURLEdit.Text := 'https://www.example.com/';
{ AppDir }
for I := Low(AppRootDirs) to High(AppRootDirs) do
AppRootDirComboBox.Items.Add(AppRootDirs[I].Description);
AppRootDirComboBox.Items.Add('(Custom)');
AppRootDirComboBox.ItemIndex := 0;
AppRootDirEdit.Enabled := False;
AppRootDirEdit.Color := clBtnFace;
NotDisableDirPageCheck.Checked := True;
{ AppFiles }
AppExeEdit.Text := PathExtractPath(NewParamStr(0)) + 'Examples\MyProg-x64.exe';
AppExeRunCheck.Checked := True;
{ AppAssoc }
CreateAssocCheck.Checked := True;
AppAssocExtEdit.Text := '.myp';
{ AppIcons }
UseAutoProgramsCheck.Checked := True;
NotDisableProgramGroupPageCheck.Checked := True;
DesktopIconCheck.Checked := True;
{ PrivilegesRequired }
PrivilegesRequiredAdminRadioButton.Checked := True;
{ Languages }
for I := 0 to FLanguages.Count-1 do begin
if FLanguages[I] <> LanguagesDefaultIsl then
LanguagesList.AddCheckBox(SpaceLanguageName(PathChangeExt(FLanguages[I], '')), '', 0, False, True, False, True, TObject(I))
else
LanguagesList.AddCheckBox(LanguagesDefaultIslDescription, '', 0, True, True, False, True, TObject(I));
end;
{ Compiler }
OutputBaseFileNameEdit.Text := 'mysetup';
EncryptionCheck.Visible := ISCryptInstalled;
EncryptionCheck.Checked := True;
EncryptionCheck.Enabled := False;
{ ISPP }
ISPPLabel.Caption := FixLabel(SWizardISPPLabel);
ISPPCheck.Caption := SWizardISPPCheck;
ISPPCheck.Checked := ISPPInstalled;
CurPage := Low(TWizardPage);
CurPageChanged;
end;
procedure TWizardForm.FormShow(Sender: TObject);
begin
Caption := FWizardName;
WelcomeLabel1.Caption := FixLabel(WelcomeLabel1.Caption);
FinishedLabel.Caption := FixLabel(FinishedLabel.Caption);
end;
procedure TWizardForm.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if ModalResult = mrCancel then
CanClose := MsgBox(FixLabel(SWizardCancelMessage), FWizardName, mbConfirmation, MB_YESNO) = idYes;
end;
procedure TWizardForm.FormDestroy(Sender: TObject);
begin
FLanguages.Free;
FRegistryHelper.Free;
FFilesHelper.Free;
end;
{ --- }
procedure TWizardForm.CurPageChanged;
{ Call this whenever the current page is changed }
begin
OuterNotebook.ActivePage := OuterNotebook.Pages[NotebookPages[CurPage, 0]];
if NotebookPages[CurPage, 1] <> -1 then
InnerNotebook.ActivePage := InnerNotebook.Pages[NotebookPages[CurPage, 1]];
{ Set button visibility and captions }
BackButton.Visible := not (CurPage = wpWelcome);
if CurPage = wpFinished then
NextButton.Caption := SWizardFinishButton
else
NextButton.Caption := SWizardNextButton;
RequiredLabel1.Visible := RequiredLabelVisibles[CurPage];
RequiredLabel2.Visible := RequiredLabel1.Visible;
{ Set the Caption to match the current page's title }
PageNameLabel.Caption := PageCaptions[CurPage];
PageDescriptionLabel.Caption := PageDescriptions[CurPage];
{ Adjust focus }
case CurPage of
wpAppInfo: ActiveControl := AppNameEdit;
wpAppDir:
begin
if AppRootDirComboBox.Enabled then
ActiveControl := AppRootDirComboBox
else
ActiveControl := NotCreateAppDirCheck;
end;
wpAppFiles:
begin
if AppExeEdit.Enabled then
ActiveControl := AppExeEdit
else
ActiveControl := AppFilesListBox;
end;
wpAppAssoc: ActiveControl := CreateAssocCheck;
wpAppIcons:
begin
if UseAutoProgramsCheck.Enabled then
ActiveControl := UseAutoProgramsCheck
else
ActiveControl := AppGroupNameEdit;
end;
wpAppDocs: ActiveControl := AppLicenseFileEdit;
wpPrivilegesRequired:
begin
if PrivilegesRequiredAdminRadioButton.Checked then
ActiveControl := PrivilegesRequiredAdminRadioButton
else
ActiveControl := PrivilegesRequiredLowestRadioButton;
end;
wpAppRegistry: ActiveControl := AppRegistryFileEdit;
wpLanguages: ActiveControl := LanguagesList;
wpCompiler: ActiveControl := OutputDirEdit;
wpISPP: ActiveControl := ISPPCheck;
end;
end;
function TWizardForm.SkipCurPage: Boolean;
begin
if ((CurPage = wpAppAssoc) and not CreateAssocCheck.Enabled) or
((CurPage = wpAppIcons) and NotCreateAppDirCheck.Checked) or
((CurPage = wpLanguages) and not (FLanguages.Count > 1)) or
((CurPage = wpISPP) and not ISPPInstalled) or
(not (CurPage in [wpWelcome, wpFinished]) and EmptyCheck.Checked) then
Result := True
else
Result := False;
end;
procedure TWizardForm.NextButtonClick(Sender: TObject);
function CheckAppInfoPage: Boolean;
begin
Result := False;
if AppNameEdit.Text = '' then begin
MsgBox(SWizardAppNameError, '', mbError, MB_OK);
ActiveControl := AppNameEdit;
end else if AppVersionEdit.Text = '' then begin
MsgBox(SWizardAppVersionError, '', mbError, MB_OK);
ActiveControl := AppVersionEdit;
end else
Result := True;
end;
function CheckAppDirPage: Boolean;
begin
Result := False;
if not NotCreateAppDirCheck.Checked and
(AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1) and
(AppRootDirEdit.Text = '') then begin
MsgBox(SWizardAppRootDirError, '', mbError, MB_OK);
ActiveControl := AppRootDirEdit;
end else if not NotCreateAppDirCheck.Checked and (AppDirNameEdit.Text = '') then begin
MsgBox(SWizardAppDirNameError, '', mbError, MB_OK);
ActiveControl := AppDirNameEdit;
end else
Result := True;
end;
function CheckAppFilesPage: Boolean;
begin
Result := False;
if AppExeEdit.Enabled and (AppExeEdit.Text = '') then begin
MsgBox(SWizardAppExeError, '', mbError, MB_OK);
ActiveControl := AppExeEdit;
end else
Result := True;
end;
function CheckAppIconsPage: Boolean;
begin
Result := False;
if AppGroupNameEdit.Text = '' then begin
MsgBox(SWizardAppGroupNameError, '', mbError, MB_OK);
ActiveControl := AppGroupNameEdit;
end else
Result := True;
end;
function CheckLanguagesPage: Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to LanguagesList.Items.Count-1 do begin
if LanguagesList.Checked[I] then begin
Result := True;
Exit;
end;
end;
MsgBox(SWizardLanguagesSelError, '', mbError, MB_OK);
ActiveControl := LanguagesList;
end;
begin
case CurPage of
wpAppInfo: if not CheckAppInfoPage then Exit;
wpAppDir: if not CheckAppDirPage then Exit;
wpAppFiles: if not CheckAppFilesPage then Exit;
wpAppIcons: if not CheckAppIconsPage then Exit;
wpLanguages: if not CheckLanguagesPage then Exit;
end;
repeat
if CurPage = wpAppAssoc then begin
if (AppAssocExtEdit.Text <> '') and (AppAssocExtEdit.Text[1] <> '.') then
AppAssocExtEdit.Text := '.' + AppAssocExtEdit.Text;
end else if CurPage = wpPrivilegesRequired then begin
if not PrivilegesRequiredOverridesAllowedCommandLineCheckbox.Checked then begin
if PrivilegesRequiredAdminRadioButton.Checked then
FRegistryHelper.PrivilegesRequired := prAdmin
else
FRegistryHelper.PrivilegesRequired := prLowest
end else
FRegistryHelper.PrivilegesRequired := prDynamic;
end else if CurPage = wpFinished then begin
GenerateScript;
ModalResult := mrOk;
Exit;
end;
Inc(CurPage);
{ Even if we're skipping a page, we should still update it }
case CurPage of
wpAppDir: if AppDirNameEdit.Text = '' then AppDirNameEdit.Text := AppNameEdit.Text;
wpAppAssoc: if AppAssocNameEdit.Text = '' then AppAssocNameEdit.Text := AppNameEdit.Text + ' File';
wpAppIcons: if AppGroupNameEdit.Text = '' then AppGroupNameEdit.Text := AppNameEdit.Text;
end;
until not SkipCurPage;
CurPageChanged;
end;
procedure TWizardForm.BackButtonClick(Sender: TObject);
begin
if CurPage = Low(TWizardPage) then Exit;
{ Go to the previous page }
Dec(CurPage);
while SkipCurPage do
Dec(CurPage);
CurPageChanged;
end;
{---}
procedure TWizardForm.UpdateAppExeControls;
var
Enabled: Boolean;
begin
Enabled := not NotCreateAppDirCheck.Checked;
NoAppExeCheck.Enabled := Enabled;
Enabled := Enabled and not NoAppExeCheck.Checked;
AppExeLabel.Enabled := Enabled;
AppExeEdit.Enabled := Enabled;
AppExeEdit.Color := EnabledColors[Enabled];
AppExeButton.Enabled := Enabled;
AppExeRunCheck.Enabled := Enabled;
AppExeIconsLabel.Enabled := Enabled;
DesktopIconCheck.Enabled := Enabled;
if Enabled then
AppExeLabel.Font.Style := AppExeLabel.Font.Style + [fsBold]
else
AppExeLabel.Font.Style := AppExeLabel.Font.Style - [fsBold];
end;
procedure TWizardForm.UpdateAppAssocControls;
var
Enabled: Boolean;
begin
Enabled := not NoAppExeCheck.Checked;
CreateAssocCheck.Enabled := Enabled;
Enabled := Enabled and CreateAssocCheck.Checked;
AppAssocNameLabel.Enabled := Enabled;
AppAssocNameEdit.Enabled := Enabled;
AppAssocExtLabel.Enabled := Enabled;
AppAssocExtEdit.Enabled := Enabled;
if Enabled then begin
AppAssocNameLabel.Font.Style := AppAssocNameLabel.Font.Style + [fsBold];
AppAssocExtLabel.Font.Style := AppAssocExtLabel.Font.Style + [fsBold];
end else begin
AppAssocNameLabel.Font.Style := AppAssocNameLabel.Font.Style - [fsBold];
AppAssocExtLabel.Font.Style := AppAssocExtLabel.Font.Style - [fsBold];
end;
end;
procedure TWizardForm.UpdateAppIconsControls;
var
Enabled: Boolean;
begin
UseAutoProgramsCheck.Enabled := NoAppExeCheck.Enabled and not NoAppExeCheck.Checked;
Enabled := not (UseAutoProgramsCheck.Enabled and UseAutoProgramsCheck.Checked);
AppGroupNameLabel.Enabled := Enabled;
AppGroupNameEdit.Enabled := Enabled;
AppGroupNameEdit.Color := EnabledColors[Enabled];
NotDisableProgramGroupPageCheck.Enabled := Enabled;
AllowNoIconsCheck.Enabled := Enabled and NotDisableProgramGroupPageCheck.Checked;
CreateURLIconCheck.Enabled := Enabled and (AppURLEdit.Text <> '');
CreateUninstallIconCheck.Enabled := Enabled;
if Enabled then
AppGroupNameLabel.Font.Style := AppGroupNameLabel.Font.Style + [fsBold]
else
AppGroupNameLabel.Font.Style := AppGroupNameLabel.Font.Style - [fsBold];
end;
{---}
procedure TWizardForm.AppRootDirComboBoxChange(Sender: TObject);
begin
if AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1 then begin
AppRootDirEdit.Enabled := True;
AppRootDirEdit.Color := clWindow;
ActiveControl := AppRootDirEdit;
end else begin
AppRootDirEdit.Enabled := False;
AppRootDirEdit.Color := clBtnFace;
end;
end;
procedure TWizardForm.NotCreateAppDirCheckClick(Sender: TObject);
var
Enabled: Boolean;
begin
Enabled := not NotCreateAppDirCheck.Checked;
{ AppDir }
AppRootDirLabel.Enabled := Enabled;
AppRootDirComboBox.Enabled := Enabled;
AppRootDirComboBox.Color := EnabledColors[Enabled];
AppRootDirEdit.Enabled := Enabled and (AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1);
AppRootDirEdit.Color := EnabledColors[AppRootDirEdit.Enabled];
AppDirNameLabel.Enabled := Enabled;
AppDirNameEdit.Enabled := Enabled;
AppDirNameEdit.Color := EnabledColors[Enabled];
NotDisableDirPageCheck.Enabled := Enabled;
if Enabled then begin
AppRootDirLabel.Font.Style := AppRootDirLabel.Font.Style + [fsBold];
AppDirNameLabel.Font.Style := AppRootDirLabel.Font.Style + [fsBold];
end else begin
AppRootDirLabel.Font.Style := AppRootDirLabel.Font.Style - [fsBold];
AppDirNameLabel.Font.Style := AppRootDirLabel.Font.Style - [fsBold];
end;
{ AppFiles }
UpdateAppExeControls;
end;
procedure TWizardForm.AppExeButtonClick(Sender: TObject);
var
FileName: String;
begin
FileName := AppExeEdit.Text;
if NewGetOpenFileName('', FileName, PathExtractPath(FileName), SWizardAppExeFilter, SWizardAppExeDefaultExt, Handle) then
AppExeEdit.Text := FileName;
end;
procedure TWizardForm.NoAppExeCheckClick(Sender: TObject);
begin
UpdateAppExeControls;
UpdateAppAssocControls;
UpdateAppIconsControls;
end;
procedure TWizardForm.CreateAssocCheckClick(Sender: TObject);
begin
UpdateAppAssocControls;
end;
procedure TWizardForm.UseAutoProgramsCheckClick(Sender: TObject);
begin
UpdateAppIconsControls;
end;
procedure TWizardForm.NotDisableProgramGroupPageCheckClick(
Sender: TObject);
begin
UpdateAppIconsControls;
end;
procedure TWizardForm.FileButtonClick(Sender: TObject);
var
Edit: TEdit;
Filter, DefaultExt, FileName: String;
begin
if Sender = AppLicenseFileButton then
Edit := AppLicenseFileEdit
else if Sender = AppInfoBeforeFileButton then
Edit := AppInfoBeforeFileEdit
else if Sender = AppInfoAfterFileButton then
Edit := AppInfoAfterFileEdit
else
Edit := SetupIconFileEdit;
if Sender <> SetupIconFileButton then begin
Filter := SWizardAppDocsFilter;
DefaultExt := SWizardAppDocsDefaultExt;
end else begin
Filter := SWizardCompilerSetupIconFileFilter;
DefaultExt := SWizardCompilerSetupIconFileDefaultExt;
end;
FileName := Edit.Text;
if NewGetOpenFileName('', FileName, PathExtractPath(FileName), Filter, DefaultExt, Handle) then
Edit.Text := FileName;
end;
procedure TWizardForm.OutputDirButtonClick(Sender: TObject);
var
Path: String;
begin
Path := OutputDirEdit.Text;
if PathDrivePartLength(Path) = 0 then
Path := ''; { don't pass in a relative path to BrowseForFolder }
if BrowseForFolder(SWizardCompilerOutputDir, Path, Handle, True) then
OutputDirEdit.Text := Path;
end;
procedure TWizardForm.PasswordEditChange(Sender: TObject);
begin
EncryptionCheck.Enabled := PasswordEdit.Text <> '';
end;
procedure TWizardForm.AllLanguagesButtonClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to LanguagesList.Items.Count-1 do
LanguagesList.Checked[I] := True;
end;
procedure TWizardForm.NoLanguagesButtonClick(Sender: TObject);
var
I: Integer;
begin
for I := 0 to LanguagesList.Items.Count-1 do
LanguagesList.Checked[I] := False;
end;
procedure TWizardForm.PrivilegesRequiredOverridesAllowedDialogCheckboxClick(
Sender: TObject);
begin
PrivilegesRequiredOverridesAllowedCommandLineCheckbox.Enabled := not PrivilegesRequiredOverridesAllowedDialogCheckbox.Checked;
if PrivilegesRequiredOverridesAllowedDialogCheckbox.Checked then
PrivilegesRequiredOverridesAllowedCommandLineCheckbox.Checked := True;
end;
{ --- }
procedure TWizardForm.GenerateScript;
function Is64BitPEImage(const Filename: String): Boolean;
{ Returns True if the specified file is a non-32-bit PE image, False
otherwise. }
var
F: TFile;
DosHeader: packed record
Sig: array[0..1] of AnsiChar;
Other: array[0..57] of Byte;
PEHeaderOffset: LongWord;
end;
PESigAndHeader: packed record
Sig: DWORD;
Header: TImageFileHeader;
OptHeaderMagic: Word;
end;
begin
Result := False;
F := TFile.Create(Filename, fdOpenExisting, faRead, fsRead);
try
if F.Read(DosHeader, SizeOf(DosHeader)) = SizeOf(DosHeader) then begin
if (DosHeader.Sig[0] = 'M') and (DosHeader.Sig[1] = 'Z') and
(DosHeader.PEHeaderOffset <> 0) then begin
F.Seek(DosHeader.PEHeaderOffset);
if F.Read(PESigAndHeader, SizeOf(PESigAndHeader)) = SizeOf(PESigAndHeader) then begin
if (PESigAndHeader.Sig = IMAGE_NT_SIGNATURE) and
(PESigAndHeader.OptHeaderMagic <> IMAGE_NT_OPTIONAL_HDR32_MAGIC) then
Result := True;
end;
end;
end;
finally
F.Free;
end;
end;
var
Script, ISPP, Setup, Languages, Tasks, Files, Registry, INI, Icons, Run, UninstallDelete: String;
I: Integer;
AppExeName, AppName, AppAmpEscapedName, AppAssocKey, LanguageName, LanguageMessagesFile: String;
begin
Script := '';
AppExeName := PathExtractName(AppExeEdit.Text);
AppName := AppNameEdit.Text;
AppAmpEscapedName := EscapeAmpersands(AppName);
if ISPPCheck.Checked then begin
{ Setup ISPP usage. Change the edits to reflect ISPP usage. A bit ugly but for now it works. }
ISPP := '#define MyAppName "' + AppNameEdit.Text + '"' + SNewLine +
'#define MyAppVersion "' + AppVersionEdit.Text + '"' + SNewLine;
if AppDirNameEdit.Text = AppNameEdit.Text then
AppDirNameEdit.Text := '{#MyAppName}';
if AppGroupNameEdit.Text = AppNameEdit.Text then
AppGroupNameEdit.Text := '{#MyAppName}';
AppNameEdit.Text := '{#MyAppName}';
AppAmpEscapedName := '{#StringChange(MyAppName, ''&'', ''&&'')}';
AppVersionEdit.Text := '{#MyAppVersion}';
if AppPublisherEdit.Text <> '' then begin
ISPP := ISPP + '#define MyAppPublisher "' + AppPublisherEdit.Text + '"' + SNewLine;
AppPublisherEdit.Text := '{#MyAppPublisher}';
end;
if AppURLEdit.Text <> '' then begin
ISPP := ISPP + '#define MyAppURL "' + AppURLEdit.Text + '"' + SNewLine;
AppURLEdit.Text := '{#MyAppURL}';
end;
{ Special ones }
if not NoAppExeCheck.Checked then begin
ISPP := ISPP + '#define MyAppExeName "' + AppExeName + '"' + SNewLine;
AppExeName := '{#MyAppExeName}';
end;
if CreateAssocCheck.Enabled and CreateAssocCheck.Checked then begin
if Pos(AppName, AppAssocNameEdit.Text) = 1 then
ISPP := ISPP + '#define MyAppAssocName MyAppName + "' + Copy(AppAssocNameEdit.Text, Length(AppName)+1, MaxInt) + '"' + SNewLine
else
ISPP := ISPP + '#define MyAppAssocName "' + AppAssocNameEdit.Text + '"' + SNewLine;
AppAssocNameEdit.Text := '{#MyAppAssocName}';
ISPP := ISPP + '#define MyAppAssocExt "' + AppAssocExtEdit.Text + '"' + SNewLine;
AppAssocExtEdit.Text := '{#MyAppAssocExt}';
ISPP := ISPP + '#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt' + SNewLine;
AppAssocKey := '{#MyAppAssocKey}';
end;
end else begin
ISPP := '';
AppAssocKey := StringReplace(AppAssocNameEdit.Text, ' ', '', [rfReplaceAll]) + AppAssocExtEdit.Text;
end;
Setup := '[Setup]' + SNewLine;
Languages := '[Languages]' + SNewLine;
Tasks := '[Tasks]' + SNewLine;
Files := '[Files]' + SNewLine;
Registry := '[Registry]' + SNewLine;
INI := '[INI]' + SNewLine;
Icons := '[Icons]' + SNewLine;
Run := '[Run]' + SNewLine;
UninstallDelete := '[UninstallDelete]' + SNewLine;
if not EmptyCheck.Checked then begin
Setup := Setup + (
'; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.' + SNewLine +
'; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)' + SNewLine);
Setup := Setup + 'AppId={' + GenerateGuid + SNewLine;
{ AppInfo }
Setup := Setup + 'AppName=' + AppNameEdit.Text + SNewLine;
Setup := Setup + 'AppVersion=' + AppVersionEdit.Text + SNewLine;
Setup := Setup + ';AppVerName=' + AppNameEdit.Text + ' ' + AppVersionEdit.Text + SNewLine;
if AppPublisherEdit.Text <> '' then
Setup := Setup + 'AppPublisher=' + AppPublisherEdit.Text + SNewLine;
if AppURLEdit.Text <> '' then begin
Setup := Setup + 'AppPublisherURL=' + AppURLEdit.Text + SNewLine;
Setup := Setup + 'AppSupportURL=' + AppURLEdit.Text + SNewLine;
Setup := Setup + 'AppUpdatesURL=' + AppURLEdit.Text + SNewLine;
end;
{ AppDir }
if not NotCreateAppDirCheck.Checked then begin
if AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1 then
Setup := Setup + 'DefaultDirName=' + AddBackslash(AppRootDirEdit.Text) + AppDirNameEdit.Text + SNewLine
else
Setup := Setup + 'DefaultDirName=' + AddBackslash(AppRootDirs[AppRootDirComboBox.ItemIndex].Constant) + AppDirNameEdit.Text + SNewLine;
if not NotDisableDirPageCheck.Checked then
Setup := Setup + 'DisableDirPage=yes' + SNewLine;
end else begin
Setup := Setup + 'CreateAppDir=no' + SNewLine;
end;
{ AppFiles }
if not NotCreateAppDirCheck.Checked and not NoAppExeCheck.Checked then begin
Files := Files + 'Source: "' + PathExtractPath(AppExeEdit.Text) + AppExeName + '"; DestDir: "{app}"; Flags: ignoreversion' + SNewLine;
if AppExeRunCheck.Checked then begin
if SameText(PathExtractExt(AppExeEdit.Text), '.exe') then
Run := Run + 'Filename: "{app}\' + AppExeName + '"; Description: "{cm:LaunchProgram,' + AppAmpEscapedName + '}"; Flags: nowait postinstall skipifsilent' + SNewLine
else
Run := Run + 'Filename: "{app}\' + AppExeName + '"; Description: "{cm:LaunchProgram,' + AppAmpEscapedName + '}"; Flags: shellexec postinstall skipifsilent' + SNewLine;
end;
if Is64BitPEImage(AppExeEdit.Text) then begin
Setup := Setup + '; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run' + SNewLine;
Setup := Setup + '; on anything but x64 and Windows 11 on Arm.' + SNewLine;
Setup := Setup + 'ArchitecturesAllowed=x64compatible' + SNewLine;
Setup := Setup + '; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the' + SNewLine;
Setup := Setup + '; install be done in "64-bit mode" on x64 or Windows 11 on Arm,' + SNewLine;
Setup := Setup + '; meaning it should use the native 64-bit Program Files directory and' + SNewLine;
Setup := Setup + '; the 64-bit view of the registry.' + SNewLine;
Setup := Setup + 'ArchitecturesInstallIn64BitMode=x64compatible' + SNewLine;
end;
end;
{ AppAssocation }
if CreateAssocCheck.Enabled and CreateAssocCheck.Checked then begin
Setup := Setup + 'ChangesAssociations=yes' + SNewLine;
Registry := Registry + 'Root: HKA; Subkey: "Software\Classes\' + AppAssocExtEdit.Text + '\OpenWithProgids"; ValueType: string; ValueName: "' + AppAssocKey + '"; ValueData: ""; Flags: uninsdeletevalue' + SNewLine;
Registry := Registry + 'Root: HKA; Subkey: "Software\Classes\' + AppAssocKey + '"; ValueType: string; ValueName: ""; ValueData: "' + AppAssocNameEdit.Text + '"; Flags: uninsdeletekey' + SNewLine;
Registry := Registry + 'Root: HKA; Subkey: "Software\Classes\' + AppAssocKey + '\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\' + AppExeName + ',0"' + SNewLine;
Registry := Registry + 'Root: HKA; Subkey: "Software\Classes\' + AppAssocKey + '\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\' + AppExeName + '"" ""%1"""' + SNewLine;
Registry := Registry + 'Root: HKA; Subkey: "Software\Classes\Applications\' + AppExeName + '\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""' + SNewLine;
end;
FFilesHelper.AddScript(Files);
{ AppGroup }
if not NotCreateAppDirCheck.Checked then begin
if UseAutoProgramsCheck.Enabled and UseAutoProgramsCheck.Checked then begin
Setup := Setup + 'DisableProgramGroupPage=yes' + SNewLine;
Icons := Icons + 'Name: "{autoprograms}\' + AppNameEdit.Text + '"; Filename: "{app}\' + AppExeName + '"' + SNewLine;
end else begin
Setup := Setup + 'DefaultGroupName=' + AppGroupNameEdit.Text + SNewLine;
if not NoAppExeCheck.Checked then
Icons := Icons + 'Name: "{group}\' + AppNameEdit.Text + '"; Filename: "{app}\' + AppExeName + '"' + SNewLine;
if not NotDisableProgramGroupPageCheck.Checked then
Setup := Setup + 'DisableProgramGroupPage=yes' + SNewLine;
if AllowNoIconsCheck.Checked and NotDisableProgramGroupPageCheck.Checked then
Setup := Setup + 'AllowNoIcons=yes' + SNewLine;
if CreateURLIconCheck.Enabled and CreateURLIconCheck.Checked then
Icons := Icons + 'Name: "{group}\{cm:ProgramOnTheWeb,' + AppNameEdit.Text + '}"; Filename: "' + AppURLEdit.Text + '"' + SNewLine;
if CreateUninstallIconCheck.Checked then
Icons := Icons + 'Name: "{group}\{cm:UninstallProgram,' + AppNameEdit.Text + '}"; Filename: "{uninstallexe}"' + SNewLine;