📄 wizard.pas
字号:
P := PrevGroup;
end;
GroupEdit.Text := P;
if shAllowNoIcons in SetupHeader.Options then begin
if InitNoIcons then
NoIconsCheck.Checked := True;
NoIconsCheck.Visible := True;
end
else
NoIconsCheck.Visible := False;
//tasks page will be updated later based on the selected components
NeedSelectTasksPageUpdate := True;
end;
destructor TWizardForm.Destroy;
begin
FreeAndNil(PrevDeselectedComponents);
FreeAndNil(PrevSelectedTasks);
FreeAndNil(PrevDeselectedTasks);
FreeAndNil(PrevSelectedComponents);
FreeAndNil(InitialSelectedComponents);
FreeAndNil(FPageList);
inherited;
end;
procedure TWizardForm.CreateParams(var Params: TCreateParams);
begin
inherited;
{ Ensure the form is *always* on top of MainForm by making MainForm
the "parent" of the form. }
Params.WndParent := MainForm.Handle;
end;
function TWizardForm.PageIndexFromID(const ID: Integer): Integer;
{ Given a page ID, returns the index of the page in FPageList. An exception is
raised if a page with the specified ID is not found. }
var
I: Integer;
begin
for I := 0 to FPageList.Count-1 do begin
if TWizardPage(FPageList[I]).ID = ID then begin
Result := I;
Exit;
end;
end;
InternalError(Format('Could not find page with ID %d', [ID]));
Result := -1; { avoid compiler warning }
end;
function TWizardForm.PageFromID(const ID: Integer): TWizardPage;
begin
Result := FPageList[PageIndexFromID(ID)];
end;
procedure TWizardForm.RegisterExistingPage(const ID: Integer;
const AOuterNotebookPage, AInnerNotebookPage: TNewNotebookPage;
const ACaption, ADescription: String);
var
P: TWizardPage;
begin
FPageList.Expand;
P := TWizardPage.Create(Self);
P.FID := ID;
P.FOuterNotebookPage := AOuterNotebookPage;
P.FInnerNotebookPage := AInnerNotebookPage;
P.Caption := ACaption;
P.Description := ADescription;
FPageList.Add(P);
end;
procedure TWizardForm.AddPage(const APage: TWizardPage; const AfterID: Integer);
{ Adds a new wizard page entry in FPageList, and an associated page in
InnerNotebook. AfterID specifies where the page should be inserted, or -1
which inserts the page at the end. }
var
InsertIndex: Integer;
NotebookPage: TNewNotebookPage;
begin
if AfterID <> -1 then
InsertIndex := PageIndexFromID(AfterID) + 1
else
InsertIndex := FPageList.Count;
FPageList.Expand;
Inc(FNextPageID);
if FNextPageID = 1 then
FNextPageID := 100;
NotebookPage := TNewNotebookPage.Create(APage);
NotebookPage.Notebook := InnerNotebook;
APage.FID := FNextPageID;
APage.FOuterNotebookPage := InnerPage;
APage.FInnerNotebookPage := NotebookPage;
FPageList.Insert(InsertIndex, APage);
end;
{ Also see GetPreviousData in ScriptFunc.pas }
procedure TWizardForm.FindPreviousData;
const
RootKeys: array[0..1] of HKEY = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE);
var
I: Integer;
H: HKEY;
S, ExpandedAppId, UninstallRegKeyBaseName: String;
begin
ExpandedAppId := ExpandConst(SetupHeader.AppId);
if ExpandedAppId <> '' then begin
{ First look in HKEY_CURRENT_USER. That's where Inno Setup creates
the uninstall key for non-administrators. If the key doesn't exist
under HKEY_CURRENT_USER, check HKEY_LOCAL_MACHINE. }
UninstallRegKeyBaseName := GetUninstallRegKeyBaseName(ExpandedAppId);
for I := 0 to 1 do
if RegOpenKeyEx(RootKeys[I],
PChar(Format('%s\%s_is1', [NEWREGSTR_PATH_UNINSTALL, UninstallRegKeyBaseName])),
0, KEY_QUERY_VALUE, H) = ERROR_SUCCESS then begin
try
{ do not localize or change the following strings }
if shUsePreviousAppDir in SetupHeader.Options then
RegQueryStringValue(H, 'Inno Setup: App Path', PrevAppDir);
if shUsePreviousGroup in SetupHeader.Options then
RegQueryStringValue(H, 'Inno Setup: Icon Group', PrevGroup);
if shUsePreviousSetupType in SetupHeader.Options then begin
RegQueryStringValue(H, 'Inno Setup: Setup Type', PrevSetupType);
if RegQueryStringValue(H, 'Inno Setup: Selected Components', S) then
PrevSelectedComponents.CommaText := S;
if RegQueryStringValue(H, 'Inno Setup: Deselected Components', S) then
PrevDeselectedComponents.CommaText := S;
end;
if shUsePreviousTasks in SetupHeader.Options then begin
if RegQueryStringValue(H, 'Inno Setup: Selected Tasks', S) then
PrevSelectedTasks.CommaText := S;
if RegQueryStringValue(H, 'Inno Setup: Deselected Tasks', S) then
PrevDeselectedTasks.CommaText := S;
end;
if shUsePreviousUserInfo in SetupHeader.Options then begin
RegQueryStringValue(H, 'Inno Setup: User Info: Name', PrevUserInfoName);
RegQueryStringValue(H, 'Inno Setup: User Info: Organization', PrevUserInfoOrg);
RegQueryStringValue(H, 'Inno Setup: User Info: Serial', PrevUserInfoSerial);
end;
finally
RegCloseKey(H);
end;
Break;
end;
end;
end;
procedure TWizardForm.ChangeReadyLabel(const S: String);
var
Width, OldHeight, dY: Integer;
begin
Width := ReadyLabel.Width;
OldHeight := ReadyLabel.Height;
ReadyLabel.Caption := S;
ReadyLabel.AutoSize := True;
ReadyLabel.Width := Width;
dY := ReadyLabel.Height-OldHeight;
IncTopDecHeight(ReadyMemo, dY);
end;
procedure TWizardForm.ChangeFinishedLabel(const S: String);
var
Y: Integer;
begin
FinishedLabel.Caption := S + SNewLine;
AdjustLabelHeight(FinishedLabel);
Y := FinishedLabel.Top + FinishedLabel.Height;
IncTopDecHeight(RunList, Y-YesRadio.Top);
YesRadio.Top := Y;
NoRadio.Top := Y + ScalePixelsY(22);
end;
procedure TWizardForm.UpdateRunList(const SelectedComponents, SelectedTasks: TStringList);
var
RunEntry: PSetupRunEntry;
Caption: String;
I: Integer;
begin
RunList.Items.Clear();
for I := 0 to Entries[seRun].Count-1 do begin
RunEntry := PSetupRunEntry(Entries[seRun][I]);
if (roPostInstall in RunEntry.Options) and ShouldProcessRunEntry(SelectedComponents, SelectedTasks, RunEntry) then begin
if RunEntry.Description <> '' then
try
Caption := ExpandConst(RunEntry.Description)
except
{ An exception here killing the entire Setup is not too desirable,
as post-install [Run] entries are normally unimportant. Just
display the message and move on. }
Application.HandleException(Self);
Caption := '[Error]';
end
else if not(roShellExec in RunEntry.Options) then
Caption := FmtSetupMessage1(msgRunEntryExec, PathExtractName(RunEntry.Name))
else
Caption := FmtSetupMessage1(msgRunEntryShellExec, PathExtractName(RunEntry.Name));
RunList.AddCheckBox(Caption, '', 0, not(roUnchecked in RunEntry.Options), True, True, True, TObject(I));
end;
end;
end;
procedure TWizardForm.CreateTaskButtons(const SelectedComponents: TStringList);
function MultipleRadioButtonsInGroup(const SelectedComponents: TStringList; const GroupDescription: String): Boolean;
var
TaskEntry: PSetupTaskEntry;
N, I: Integer;
begin
N := 0;
for I := 0 to Entries[seTask].Count-1 do begin
TaskEntry := PSetupTaskEntry(Entries[seTask][I]);
if ShouldProcessEntry(SelectedComponents, nil, TaskEntry.Components, '', TaskEntry.Languages, '') and (ExpandConst(TaskEntry.GroupDescription) = GroupDescription) and (toExclusive in TaskEntry.Options) then begin
Inc(N);
if N > 1 then begin
Result := True;
Exit;
end;
end;
end;
Result := False;
end;
var
TaskEntry: PSetupTaskEntry;
I: Integer;
Description, GroupDescription: String;
LastGroupDescription: String;
UseRadioButtons: Boolean;
begin
TasksList.Items.Clear();
UseRadioButtons := MultipleRadioButtonsInGroup(SelectedComponents, '');
LastGroupDescription := '';
//Create the task buttons with their default checked states
for I := 0 to Entries[seTask].Count-1 do begin
TaskEntry := PSetupTaskEntry(Entries[seTask][I]);
if ShouldProcessEntry(SelectedComponents, nil, TaskEntry.Components, '', TaskEntry.Languages, '') then begin
Description := ExpandConst(TaskEntry.Description);
GroupDescription := ExpandConst(TaskEntry.GroupDescription);
//see if we should add a group label
if GroupDescription <> LastGroupDescription then begin
TasksList.AddGroup(GroupDescription, '', 0, nil);
UseRadioButtons := MultipleRadioButtonsInGroup(SelectedComponents, GroupDescription);
LastGroupDescription := GroupDescription;
end;
//create a checkbox or radiobutton. only create a radiobutton if the group
//has multiple radiobuttons based on the selected components
if UseRadioButtons and (toExclusive in TaskEntry.Options) then
TasksList.AddRadioButton(Description, '', TaskEntry.Level,
not(toUnchecked in TaskEntry.Options), True, TObject(TaskEntry))
else
TasksList.AddCheckBox(Description, '', TaskEntry.Level,
not(toUnchecked in TaskEntry.Options), True, TaskEntry.Used,
not(toDontInheritCheck in TaskEntry.Options), TObject(TaskEntry));
end;
end;
//Now restore the previous checked state of the buttons we just created
for I := 0 to TasksList.Items.Count-1 do begin
TaskEntry := PSetupTaskEntry(TasksList.ItemObject[I]);
if TaskEntry <> nil then begin
if ListContains(PrevSelectedTasks, TaskEntry.Name) then begin
TasksList.Checked[I] := not(toCheckedOnce in TaskEntry.Options);
Continue;
end;
if ListContains(PrevDeselectedTasks, TaskEntry.Name) then
TasksList.Checked[I] := False;
end;
end;
end;
function TWizardForm.GetSetupType(): PSetupTypeEntry;
var
Index: Integer;
begin
Index := TypesCombo.ItemIndex;
if Index <> -1 then
Result := PSetupTypeEntry(TypesCombo.Items.Objects[TypesCombo.ItemIndex])
else
Result := nil;
end;
procedure TWizardForm.SetSelectedComponents(const SelectedComponents, DeselectedComponents: TStringList);
var
I: Integer;
ComponentEntry: PSetupComponentEntry;
begin
for I := 0 to Entries[seComponent].Count-1 do begin
ComponentEntry := PSetupComponentEntry(Entries[seComponent][I]);
if SelectedComponents <> nil then begin
if ListContains(SelectedComponents, ComponentEntry.Name) then begin
ComponentsList.Checked[I] := True;
Continue;
end;
end;
if DeselectedComponents <> nil then begin
if ListContains(DeselectedComponents, ComponentEntry.Name) then
ComponentsList.Checked[I] := False;
end;
end;
end;
procedure TWizardForm.SetSelectedComponentsFromType(const TypeName: String; OnlySelectFixedComponents: Boolean);
var
ComponentTypes: TStringList;
ComponentEntry: PSetupComponentEntry;
I: Integer;
begin
ComponentTypes := TStringList.Create();
for I := 0 to Entries[seComponent].Count-1 do begin
ComponentEntry := PSetupComponentEntry(Entries[seComponent][I]);
if not OnlySelectFixedComponents or (coFixed in ComponentEntry.Options) then begin
ComponentTypes.CommaText := ComponentEntry.Types;
ComponentsList.Checked[I] := ListContains(ComponentTypes, TypeName);
end;
end;
ComponentTypes.Free();
end;
procedure TWizardForm.UpdateSelectTasksPage;
var
SelectedComponents: TStringList;
begin
SelectedComponents := TStringList.Create();
GetSelectedComponents(SelectedComponents, False, False);
CreateTaskButtons(SelectedComponents);
SelectedComponents.Free();
end;
procedure TWizardForm.GetSelectedComponents(Components: TStringList; const Descriptions, IndentDescriptions: Boolean);
function GetString(ComponentEntry: PSetupComponentEntry; Descriptions: Boolean): String;
begin
if Descriptions then begin
Result := ExpandConst(ComponentEntry.Description);
if IndentDescriptions then
Result := Format('%*s', [3*ComponentEntry.Level, '']) + Result;
end else
Result := ComponentEntry.Name;
end;
var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -