With Inno Setup, I have a task which I want to be conditional based on the results of a Pascal Script function. If the function returns true, the task will be displayed and the user can either check or un-check it. Otherwise, the task will not be shown.
You are looking for the Check parameter:
[Tasks]
Name: mytask; Description: "My Task"; Check: IsTaskValid
[Code]
function IsTaskValid: Boolean;
begin
Result := { Your decision logic };
end;
Related
My component section:
[Components]
Name: "client"; Description: "Client"; Types: full default monitor;
Name: "server"; Description: "Server"; Types: full default server;
Name: "server/feature"; Description: "Optional feature";
Name: "server/Db"; Description: "Always supported server feature"; Types: full default server; Flags: fixed
Name: "server/Db/latest"; Description: "Latest"; Types: full default server; Flags: exclusive
Name: "server/Db/2_10"; Description: "2.10"; Flags: exclusive
I would like to have component server/Db that is always selected when its parent server is selected. I was able to acomplish it with fixed flag, but then I'm not able to select server/Db/2_10. If I tried to select second exclusive component, server/Db is unsellected altogether.
I can only select server/Db/2_10 if server/Db isn't flaged as fixed, but then I'm able to unselect it.
Edit:
I added procedures like in Inno Setup: how to auto select a component if another component is selected?. Just changed ComponentsListCheckChanges procedure like this, (because I don't want to allow user to uncheck it):
procedure ComponentsListCheckChanges;
begin
// No metter what you chceck/uncheck force component if needed.
if WizardIsComponentSelected('server') then
begin
WizardSelectComponents('server/Db');
end
else
begin
WizardSelectComponents('!server/Db');
end
end;
I just found out, that If I try to uncheck server/Db, its checked back, that's good, but Type change to Custom even if it match other predefined type. Did I made some mistakes?
Old:
I also tried to mark it as Disabled in code. I was able to select both exclusive components, but not able to Uncheck component server anymore.
[code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectComponents then
WizardForm.ComponentsList.ItemEnabled[3] := False;
end;
I'm able to create same behavior in component section as with code above by adding custom to Types list. I'm able to select both exclusive components, but can't uncheck server
[Components]
Name: "client"; Description: "Client"; Types: full default monitor;
Name: "server"; Description: "Server"; Types: full default server;
Name: "server/feature"; Description: "Optional feature";
Name: "server/Db"; Description: "Always supported server feature"; Types: full default server custom; Flags: fixed
Name: "server/Db/latest"; Description: "Latest"; Types: full default server; Flags: exclusive
Name: "server/Db/2_10"; Description: "2.10"; Types: custom; Flags: exclusive
Last thing that I tried was setting it to True in code if server is checked. I Tried using code from: https://stackoverflow.com/a/36989894/2416941 , it forced server/Db to behave like I wanted but, in dropdown menu above components, Selected Type stopped changing, It always showed as Default instalation and not Custom or any other type, so I don't think that's a valid solution.
How can I force server/Db to be always checked with server and able to choose one of server/Db's children, and still possible to uncheck server?
Or is there other way to group exclusive components?
I made it works corectly by editing answers for Inno Setup: how to auto select a component if another component is selected? but had to add ComponentsListClickCheckPrev(nil); to Update Type selection corectly after calling WizardSelectComponents.
[Code]
var
TypesComboOnChangePrev: TNotifyEvent;
ComponentsListClickCheckPrev: TNotifyEvent;
procedure ComponentsListCheckChanges;
begin
{ If Check status of components is different }
{ Update child's status with parent's status. }
if WizardIsComponentSelected('server') <> WizardIsComponentSelected('server/Db') then
begin
if WizardIsComponentSelected('server') then { If checked parent }
begin
WizardSelectComponents('server/Db'); { Check component }
end
else
begin
WizardSelectComponents('!server/Db'); { Uncheck component }
end;
ComponentsListClickCheckPrev(nil); { Update Type selection after my edits }
end;
end;
procedure ComponentsListClickCheck(Sender: TObject);
begin
{ First let Inno Setup update the components selection }
ComponentsListClickCheckPrev(Sender);
{ And then check for changes }
ComponentsListCheckChanges;
end;
procedure TypesComboOnChange(Sender: TObject);
begin
{ First let Inno Setup update the components selection }
TypesComboOnChangePrev(Sender);
{ And then check for changes }
ComponentsListCheckChanges;
end;
procedure InitializeWizard();
begin
{ The Inno Setup itself relies on the TypesCombo.OnChange and OnClickCheck. }
{ so we have to preserve their handlers. }
ComponentsListClickCheckPrev := WizardForm.ComponentsList.OnClickCheck;
WizardForm.ComponentsList.OnClickCheck := #ComponentsListClickCheck;
TypesComboOnChangePrev := WizardForm.TypesCombo.OnChange;
WizardForm.TypesCombo.OnChange := #TypesComboOnChange;
end;
This code actually download me the files and it does not matter whether the selected component is "test" or not. I want those two files download, if you select a component, can do that? I use Inno Inno Setup 5 + Tools Downloader)
[Components]
Name: Dictionaries; Description: "test"; Types: Full; ExtraDiskSpaceRequired: 50;
[Languages]
Name: english; MessagesFile: compiler:Default.isl
#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');
[Code]
procedure InitializeWizard();
begin
itd_init;
itd_addfile('http://www.sherlocksoftware.org/petz/files/dogz5.zip',expandconstant('{tmp}\dogz5.zip'));
itd_addfile('http://www.sherlocksoftware.org/petz/files/petz4.zip',expandconstant('{tmp}\petz4.zip'));
itd_downloadafter(wpReady);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep=ssInstall then begin
filecopy(expandconstant('{tmp}\dogz5.zip'),expandconstant('{app}\dogz5.zip'),false);
filecopy(expandconstant('{tmp}\petz4.zip'),expandconstant('{app}\petz4.zip'),false);
end;
end;
Yes, that's possible. Your are looking for a little helper function called
IsComponentSelected().
It's basically a boolean tester accepting a component name from the [components] and returning the checkbox value (selected=true).
// for a single component
if IsComponentSelected('NameOfTheComponent') then idpAddFile(URL, ...);`
// multiple components with one selection
if IsComponentSelected('dictionaries') then
begin
idpAddFile(URL1, ...);
idpAddFile(URL2, ...);
end;
Comment by TLama:
In which event and where to enqueue the download files?
I would suggest to use the NextButtonClick event with a condition, that the current (CurPage) has to be the component selection screen (wpSelectComponents).
In other words: when you are on the component selection screen and press next, only the selected components are added to the downloader.
The code could look like this:
function NextButtonClick(CurPage: Integer): Boolean;
(*
Called when the user clicks the Next button.
If you return True, the wizard will move to the next page.
If you return False, it will remain on the current page (specified by CurPageID).
*)
begin
if CurPage = wpSelectComponents then
begin
if IsComponentSelected('NameOfTheComponent') then idpAddFile(URL, ...);
end; // of wpSelectComponents
Result := True;
end;
Sidenote: you might switch your download lib to https://code.google.com/p/inno-download-plugin/ This has better features, including decent https support and is actively maintained. InnoTools Download by SherlockSoftware is outdated (2008).
How can I delete a folder using a task function which must be executed when hitting Next button in Additional Task panel?
Thanks so much in advanced.
To check whether certain task is selected you can use the IsTaskSelected function. So, to meet your requirement you can write something like this:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Tasks]
Name: deletefolder; Description: "Delete a folder"; GroupDescription: "Group Description:"
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
// allow the setup turning to the next page
Result := True;
// if we are on the Additional Tasks page and the task is selected, then...
if (CurPageID = wpSelectTasks) and IsTaskSelected('deletefolder') then
// here call the RemoveDir or DelTree function depending on your needs
end;
In a prior question I asked how to have three optional components, where the user could also specify the locations for each component separately (e.g. a code part and two HTML web applications). #Miral gave me a great answer which I have now implemented:
three components in three user defined locations
I have a small esthetic issue remaining. I am always creating and asking the user for a CreateInputDirPage, in the wizard. The question comes after the wpSelectComponents.
Question: How do I skip the page if the component was not selected. That is, how do I skip my custom page?
I have a feeling it has to do with ShouldSkipPage(). But I have no idea what the PageID for my custom page is, and how to test to see what components were selected.
function ShouldSkipPage(PageID: Integer): Boolean;
The wizard calls this event function to determine whether or not a particular page (specified by PageID) should be shown at all. If you return True, the page will be skipped; if you return False, the page may be shown.
My script is enclosed below:
[Components]
Name: "Watson"; Description: "Watson Component"; Types: onlywatson full
Name: "Toby"; Description: "Toby Component"; Types: onlytoby full
Name: "Sherlock"; Description: "Sherlock Component"; Types: onlysherlock full
[Code]
var
TobyDirPage: TInputDirWizardPage;
SherlockDirPage: TInputDirWizardPage;
procedure InitializeWizard;
begin
TobyDirPage := CreateInputDirPage(wpSelectComponents,
'Select Location for Toby Web Pages', 'Where should we store the sample Toby application files?',
'The sample Toby stand-alone map application will be saved in the following folder.'#13#10#13#10 +
'To continue, click Next. If you would like to select a different folder, click Browse.',
False, 'New Folder');
{ Add item (with an empty caption) }
TobyDirPage.Add('');
{ Set initial value (optional) }
TobyDirPage.Values[0] := ExpandConstant('c:\wwwroot\Toby');
SherlockDirPage := CreateInputDirPage(wpSelectComponents,
'Select Location for Sherlock Web Pages', 'Where should we store the Sherlock Catalog Search Tool?',
'Sherlock.html and it'#39 + 's associated files will be saved in the following folder.'#13#10#13#10 +
'To continue, click Next. If you would like to select a different folder, click Browse.',
False, 'New Folder');
{ Add item (with an empty caption) }
SherlockDirPage.Add('');
{ Set initial value (optional) }
SherlockDirPage.Values[0] := ExpandConstant('c:\wwwroot\Sherlock');
end;
function GetTobyDir(Param: String): String;
begin
{ Return the selected TobyDir }
Result := TobyDirPage.Values[0];
end;
function GetSherlockDir(Param: String): String;
begin
{ Return the selected TobyDir }
Result := SherlockDirPage.Values[0];
end;
As you correctly forefelt, you need to use the ShouldSkipPage event handler to conditionally skip the page. To check if a certain component is selected use the IsComponentSelected function and finally, to get ID of your custom page you need to store its ID. Putting all together might give you the following example script:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output
[Components]
Name: "help"; Description: "Help File";
[Code]
var
CustomPageID: Integer;
procedure InitializeWizard;
var
CustomPage: TInputDirWizardPage;
begin
CustomPage := CreateInputDirPage(wpSelectComponents, 'Caption',
'Description', 'SubCaption', False, 'NewFolderName');
CustomPage.Add('Input');
{ store your custom page ID to further use in the ShouldSkipPage event }
CustomPageID := CustomPage.ID;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
{ initialize result to not skip any page (not necessary, but safer) }
Result := False;
{ if the page that is asked to be skipped is your custom page, then... }
if PageID = CustomPageID then
{ if the component is not selected, skip the page }
Result := not IsComponentSelected('help');
end;
My take on this is to use the TWizardPageShouldSkipEvent, I've made only a case-and-point script:
[Code]
var
TobyDirPage: TInputDirWizardPage;
function SkipEvent (Sender: TWizardPage): Boolean;
begin
Result := not IsComponentSelected('Toby');
end;
procedure InitializeWizard;
begin
TobyDirPage := CreateInputDirPage(wpSelectComponents, yadda yadda yadda
TobyDirPage.OnShouldSkipPage := #SkipEvent;
end;
Now, OnShouldSkipPage fires right after pressing Next on wpSelectComponents and before TobyDirPage gets painted and since you can attach that event to the page itself you don't need to fiddle with PageID's.
After couple of hours googling and struggling, and got no where, I decide to ask for help here.
What I am trying to accomplish, I am trying to get the IP from the user and use it as a command line parameter in my [Run] Section.
So I have this:
[Task]
Name: "License"; Description: "Usb Key License Driver"; GroupDescription: "UsbLicense"; Flags: checkedonce
Name: "License/Desktop"; Description: "Desktop License"; GroupDescription: "UsbLicense"; Flags: exclusive
Name: "License/NetworkClient"; Description: "Network Client License Key"; GroupDescription: "UsbLicense"; Flags: exclusive unchecked
Now if the user chooses Network client, I want to be able to show a custom page, and get the IP and use it like this:
[Run]
Filename: "{app}\Drivers\Program.exe"; Parameters: "/ip:{code:GetIPhere}"; StatusMsg: "Installing drivers..."; Tasks: License/NetworkClient
I managed to create my own page and ran this:
[Code]
procedure InitializeWizard();
begin
CustomForm_CreatePage(wpSelectDir);
end;
Now for my main question:
1) How do i control WHEN the custom form shows, it shows up before it activates before my Task page.
2) If i can get it to show AFTER task page? How do I write code to make it show under the "Client Network" condition only from task. (If i do this in NextButtonClick method, how do i know what is the page id of my custom page?)
Thanks for all you help, i am just geting so close to finishing my installer, but this is driving me nuts.
----EDITED----
I sovled my problem 1, there is a pageAfter parameter when creating the custom page, and we can use the selectedTask constant to determine it to appear AFTER the Task page:
procedure InitializeWizard();
begin
Form_CreatePage(wpSelectTasks);
end;
Thanks and Regards,
Kev84
You can use the Pascal Script WizardSelectedTasks, which will return you the string of tasks you have created, just do a "Pos" on the returned string and you'll be able to determine if your specific task was chosen.
[code]
function Form_ShouldSkipPage(Page: TWizardPage): Boolean;
var
selectedTask : string;
skipPage : bool;
begin
skipPage := true;
selectedTask := WizardSelectedTasks(false);
if (Pos('client', selectedTask) > 0) then
begin
skipPage := false;
end;
Result := skipPage;
end;