Inno Setup: ensure that the user have read the Information page - inno-setup

I have an Information page, the page that that is activated with infobefore file:
[Setup]
InfoBeforeFile=infobefore.txt
I want to:
Add a checkbox (or a couple of checkboxes), that the user has to check to show that he has paid attention to the information.
The user should only be allowed to proceed when he checks the checkboxes right. I think of disabling the Next button or showing a messagebox, whatever is easier.
Is there an easy way to do this?

Just add a new checkbox on the InfoBeforePage page. And update the NextButton state based on the check box state.
[Setup]
InfoBeforeFile=infobefore.txt
[Code]
var
InfoBeforeCheck: TNewCheckBox;
procedure CheckInfoBeforeRead;
begin
{ Enable the NextButton only if InfoBeforeCheck is checked or }
{ installer is running in the silent mode }
WizardForm.NextButton.Enabled := InfoBeforeCheck.Checked or WizardSilent;
end;
procedure InfoBeforeCheckClick(Sender: TObject);
begin
{ Update state of the Next button, whenever the InfoBeforeCheck is toggled }
CheckInfoBeforeRead;
end;
procedure InitializeWizard();
begin
InfoBeforeCheck := TNewCheckBox.Create(WizardForm);
InfoBeforeCheck.Parent := WizardForm.InfoBeforePage;
{ Follow the License page layout }
InfoBeforeCheck.Top := WizardForm.LicenseNotAcceptedRadio.Top;
InfoBeforeCheck.Left := WizardForm.LicenseNotAcceptedRadio.Left;
InfoBeforeCheck.Width := WizardForm.LicenseNotAcceptedRadio.Width;
InfoBeforeCheck.Height := WizardForm.LicenseNotAcceptedRadio.Height;
InfoBeforeCheck.Caption := 'I swear I read this';
InfoBeforeCheck.OnClick := #InfoBeforeCheckClick;
{ Make the gap between the InfoBeforeMemo and the InfoBeforeCheck the same }
{ as the gap between LicenseMemo and LicenseAcceptedRadio }
WizardForm.InfoBeforeMemo.Height :=
((WizardForm.LicenseMemo.Top + WizardForm.LicenseMemo.Height) -
WizardForm.InfoBeforeMemo.Top) +
(InfoBeforeCheck.Top - WizardForm.LicenseAcceptedRadio.Top);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpInfoBefore then
begin
{ Initial state of the Next button }
CheckInfoBeforeRead;
end;
end;

Related

TNewCheckListBox Checked not being updated

I'm trying to write an installer in Inno Setup that includes a page where a TNewCheckListBox is created and then used to populate a selection of choices on the next page:
var
ListBox: TNewCheckListBox;
SelectedConfigs: array of Integer;
function ConfigurationPage(): Integer;
var
Page: TWizardPage;
I: Integer;
begin
Page := CreateCustomPage(wpSelectComponents, 'Select Configuration',
'Please select the configuration you would like to install to.');
ListBox := TNewCheckListBox.Create(Page);
ListBox.Parent := Page.Surface;
ListBox.Left := ScaleX(0);
ListBox.Top := ScaleY(0);
ListBox.Width := Page.SurfaceWidth;
ListBox.Height := Page.SurfaceHeight;
ListBox.BorderStyle := bsNone;
for I := 0 to GetArrayLength(ConfigurationNames) - 1 do
begin
ListBox.AddCheckBox(ConfigurationNames[I], '', 0, False, True, False, False, nil);
end;
ListBox.ItemIndex := 0;
Result := Page.ID;
end;
procedure PortSelectionPage(PageID: Integer);
var
Page: TWizardPage;
ArrayLength: Integer;
I: Integer;
begin
Page := CreateCustomPage(PageID, 'Select Port',
'Please select the port you want the configurations to receive on.');
for I := 0 to ListBox.Items.Count - 1 do
begin
Log(Format('ListBox[%d], %s is checked? %d', [I, ListBox.Items[I], ListBox.Checked[I]]));
if ListBox.Checked[I] then
begin
ArrayLength := GetArrayLength(SelectedConfigs);
SetArrayLength(SelectedConfigs, ArrayLength + 1);
SelectedConfigs[ArrayLength] := I;
Log(Format('Config %d was selected...', [I]));
end;
end;
end;
procedure InitializeWizard;
var
PageID: Integer;
begin
PageID := ConfigurationPage;
PortSelectionPage(PageID);
end;
The problem I'm having is that, regardless of the selections I make in the ConfigurationPage procedure, the SelectedConfigs array is not being updated and my debugging messages are showing that none of the options are selected. Before creating the PortSelectionPage procedure, the code lived on the CurStepChanged event handler so I'm not sure if the issue is with my having moved the code to a different page or if there's something else going on here. Do I need to force an update to the component or should I be using event handlers instead? If so, how would I implement one for this usecase?
Your whole code is executed from InitializeWizard event function. Hence even before the installer wizard is shown.
You have to query the checkbox states only after the user changes them. For example, from some of these events:
NextButtonClick
CurStepChanged
CurPageChanged

Adding post-install radio option to do nothing when installer has finished

Some time back I had this question. Some of that code is repeated here:
procedure RebuildRunList;
var
RunEntries: array of TRunEntry;
I: Integer;
begin
{ Save run list ... }
SetArrayLength(RunEntries, WizardForm.RunList.Items.Count);
for I := 0 to WizardForm.RunList.Items.Count - 1 do
begin
RunEntries[I].Caption := WizardForm.RunList.ItemCaption[I];
RunEntries[I].Checked := WizardForm.RunList.Checked[I];
RunEntries[I].Object := WizardForm.RunList.ItemObject[I];
end;
{ ... clear it ... }
WizardForm.RunList.Items.Clear;
{ ... and re-create }
for I := 0 to GetArrayLength(RunEntries) - 1 do
begin
{ the first two entries are radio buttons }
if (I = 0) or (I = 1) then
begin
WizardForm.RunList.AddRadioButton(
RunEntries[I].Caption, '', 0, RunEntries[I].Checked, True, RunEntries[I].Object);
end
else
begin
WizardForm.RunList.AddCheckBox(
RunEntries[I].Caption, '', 0, RunEntries[I].Checked, True, True, True,
RunEntries[I].Object);
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then
begin
{ Only now is the RunList populated. }
{ Two entries are on 64-bit systems only. }
if IsWin64 then RebuildRunList;
end;
end;
I would like to know how I can make a enhancement to the radio choices. The drawback at the moment is that the user is forced to start one or the other application. I would like to add another radio option for simply closing down the installer. Ideally it would use a Inno Setup supplied message so that I do not have to ask for translations. (See this question).
Can this be done?
The easiest solution is to add a no-op entry to the RunList:
[Run]
...
Filename: "{cmd}"; Parameters: "/C exit"; Description: "Exit setup"; \
Flags: nowait postinstall runasoriginaluser unchecked skipifsilent runhidden; \
Check: IsWin64
And turn it to a radio button:
{ the first three entries are radio buttons }
if (I = 0) or (I = 1) or (I = 2) then

Inno Setup: CreateInputQueryPage isn't returning any value

Here is the script I'm using on Inno Setup. It is my first script, please understand if I'm asking something obvious.
It seems that the variable ServerAddress never has a value, even if I fill the input field. It looks like Page.Values[0] always returns an empty result. What is wrong with my code?
As you can see, I have made a test with a testvar variable to exclude it was a matter of variable scope, but it's not the case.
[Code]
var
Page: TInputQueryWizardPage;
ServerAddress: String;
testvar: String;
procedure InitializeWizard();
begin
Page := CreateInputQueryPage(wpWelcome,
'Server Informations', '',
'Please specify the IP address, then click Next.');
{ Add items (False means it's not a password edit) }
Page.Add('IP Address:', False);
ServerAddress := Page.Values[0];
testvar := 'testvalue';
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then begin
MsgBox(ExpandConstant('{app} '+testvar+' : '+ServerAddress),mbInformation,MB_OK);
SaveStringToFile(ExpandConstant('{app}')+'\config.txt', 'test'+ServerAddress, True);
end;
end;
The InitializeWizard event function is called (and finishes) before the wizard window is even shown.
So a value (that the user will enter in the future) can hardly be known at that point. You have to read the value only after the custom page is shown. Like in your CurStepChanged(ssPostInstall):
procedure CurStepChanged(CurStep: TSetupStep);
var
ServerAddress: string;
begin
if CurStep = ssPostInstall then
begin
{ This is the right time to read the value }
ServerAddress := Page.Values[0];
SaveStringToFile(ExpandConstant('{app}') + '\config.txt', ServerAddress, True);
end;
end;

Inno Setup - Conditionally hide/show static text based on task selection

[Components]
Name: "Slasher"; Description: "Dagon Slasher"; Types: Slasher Full
Name: "Frankenstein"; Description: "Dagon Frankenstein"; Types: Frankenstein Full
[Types]
Name: "Full"; Description: "Dagon Video Tools"
Name: "Slasher"; Description: "Dagon Slasher"
Name: "Frankenstein"; Description: "Dagon FrankenStein"
[Tasks]
Name: "Debug"; Description: "Nothing"; Components: not Slasher
Name: "Vid"; Description: "Install Extra Codecs for Frankenstein"; Flags: unchecked; Components: not Slasher
[Code]
var
Warning: TNewStaticText;
procedure InitializeWizard;
begin
Warning := TNewStaticText.Create(WizardForm);
Warning.Parent := WizardForm.SelectTasksPage;
Warning.Visible := False;
Warning.AutoSize := False;
Warning.SetBounds(
WizardForm.TasksList.Left,
WizardForm.TasksList.Top + WizardForm.TasksList.Height,
WizardForm.TasksList.Width,
50
);
Warning.Font.Color := clRed;
Warning.Caption := 'Warning: This will result in a non-functional "Join in FrankenStein" button in the Tools Menu.';
end;
I used yet another amazing piece of code by TLama. The problem is I need the note to be visible when the user selects the task, and be hidden otherwise (while on the same page).
You have to handle WizardForm.TasksList.OnClickCheck event and update the Warning label visibility accordingly.
var
Warning: TNewStaticText;
procedure TasksListClickCheck(Sender: TObject);
begin
Warning.Visible :=
{ This (and the task index below) has to be kept in sync with the expression }
{ in "Components" parameter of the respective task. }
{ Though note that in your specific case the test }
{ is redundant as when "Slasher" is selected, you have no tasks, }
{ and the "Tasks" page is completely skipped, so you do not even get here. }
(not IsComponentSelected('Slasher')) and
WizardForm.TasksList.Checked[0]; { You can also use WizardIsTaskSelected }
end;
procedure InitializeWizard;
begin
Warning := TNewStaticText.Create(WizardForm);
...
{ Update Warning label visibility on task selection change }
WizardForm.TasksList.OnClickCheck := #TasksListClickCheck
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectTasks then
begin
{ Update initial visibility }
TasksListClickCheck(WizardForm.TasksList);
end;
end;
Side notes:
Do not hard code the height to fixed 50. Scale it with DPI instead: ScaleY(50).
You should set Warning.WordWrap := True as the caption does not fit page width.
You should shrink TasksList's height as the label does not fit below the list. You are missing the WizardForm.TasksList.Height := WizardForm.TasksList.Height - NoteHeight; from #TLama's code. Again note that he is missing the scaling of the NoteHeight.
const
NoteHeight = 50;
procedure InitializeWizard;
begin
WizardForm.TasksList.Height := WizardForm.TasksList.Height - ScaleY(NoteHeight);
Warning := TNewStaticText.Create(WizardForm);
Warning.Parent := WizardForm.SelectTasksPage;
Warning.AutoSize := False;
Warning.WordWrap := True;
Warning.SetBounds(
WizardForm.TasksList.Left,
WizardForm.TasksList.Top + WizardForm.TasksList.Height,
WizardForm.TasksList.Width,
ScaleY(NoteHeight)
);
Warning.Font.Color := clRed;
{ Update Warning label visibility on task selection change }
WizardForm.TasksList.OnClickCheck := #TasksListClickCheck
Warning.Caption :=
'Warning: This will result in a non-functional "Join in FrankenStein" button ' +
'in the Tools Menu.';
end;

InnoSetup: need to add validate URL by adding test button on CreateInputQueryPage

I have on CreateInputQueryPage, in that box user will type URL...Now i want to have Test button next to that text box so i can ping and validate that URL...is that possible ?
Using the Standard Support Functions, you are unable to do this.
You can call an external dll, which would allow you to do this.
You can also call COM interfaces, which would also allow you do to this.
Specifically you could use WinHTTPRequest COM object to perform this check.
You have a couple of options to deal with the validation. Both are demonstrated in the following script. The first is to create a button just for validation, the 2nd is to hook the Next Button and have it occur automatically before moving to the next page.
[Setup]
AppName='Test Script'
AppVerName='Test Script'
DefaultDirName={pf}\test
[Code]
const
InputQueryPageID = 100; //Determined by watching in Debugger.
var
Page : TInputQueryWizardPage;
procedure ClickEvent(Sender : TObject);
begin
MsgBox('Could Validate Here',mbInformation,MB_OK);
end;
procedure InitializeWizard();
var
Button : TButton;
begin
Page := CreateInputQueryPage(wpWelcome,
'Add URL', 'Test2','Test3');
Page.Add('URL:', False);
Button := TButton.Create(Page);
Button.Parent := Page.Surface;
Button.Caption := 'Button Text';
Button.Top := 100;
Button.Left := 10;
Button.OnClick := #ClickEvent;
end;
function NextButtonClick(CurrPageID: Integer) : Boolean;
begin
case CurrPageID of
InputQueryPageID : begin
MsgBox('Could Validate Here',mbInformation,MB_OK);
result := true; // Results of EXE Validation
end;
else result := true;
end;
end;

Resources