In my Inno Setup script there's a task that may be used under certain conditions which are determined by code. In no other conditions this task should be executed. In fact that entire Tasks page is skipped then. Unfortunately the task selection is remembered by Inno Setup and restored on every following update setup, even if the page isn't visible at all.
I now need to uncheck that task generally at every setup initialisation in order to forget the last selected state. But I can't get this to work. Here's my latest try:
[Tasks]
Name: DeleteConfig; Description: "{cm:Task_DeleteConfig}"; Flags: unchecked
#define Task_DeleteConfig_Index 0
[InstallDelete]
; Delete user configuration files if the task is selected
Type: files; Name: "{userappdata}\...\App.conf"; Tasks: DeleteConfig
[Code]
var
IsDowngradeSetup: Boolean;
function InitializeSetup: Boolean;
begin
// More code not shown here, but the following may be set under certain conditions
IsDowngradeSetup := true;
end;
procedure InitializeWizard;
begin
// Clear possibly remembered value from previous downgrade install
WizardForm.TasksList.Checked[{#Task_DeleteConfig_Index}] := false;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
// Make upgrade install quicker
Result := ((PageID = wpSelectTasks) or ((PageID = wpReady) and (GetArrayLength(products) = 0))) and PrevInstallExists;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpWelcome then
begin
if PrevInstallExists then
begin
// Change "Next" button to "Upgrade" on the first page, because it won't ask any more
WizardForm.NextButton.Caption := ExpandConstant('{cm:Upgrade}');
WizardForm.FinishedHeadingLabel.Caption := ExpandConstant('{cm:UpdatedHeadingLabel}');
end;
end;
if CurPageID = wpSelectTasks then
begin
if IsDowngradeSetup then
begin
// Pre-select task to delete existing configuration on downgrading (user can deselect it again)
// (Use the zero-based index of all rows in the tasks list GUI)
// Source: http://stackoverflow.com/a/10490352/143684
WizardForm.TasksList.Checked[{#Task_DeleteConfig_Index}] := true;
end;
end;
end;
This gives me a
Runtime error (at 85:77): List index out of bounds (0).
I don't know where "85:77" is supposed to be but from the only recent changes it can only be the quoted code above.
I first had that in the InitializeSetup function but that didn't work either.
Where should I put this code so that it works and finds a fully initialised tasks list? The tasks page may not be shown so I think it's too late to wait for the page to become visible. In fact the code used to be there and wasn't called when the page was skipped.
I do not understand, why you need to reset the task. I have an impression that you have that conditional skip of the task implemented incorrectly.
It's just a guess, but I assume that you skip the task page using the ShouldSkipPage. So the task stays checked, if it was enabled in a previous installation.
Do not use the ShouldSkipPage for this, use the Check parameter instead. If there's a single task only that is conditionally disabled using the Check parameter, whole task page gets skipped.
[Tasks]
Name: DeleteConfig; Description: "{cm:Task_DeleteConfig}"; Flags: unchecked; \
Check: UseDeleteConfig
[Code]
function UseDeleteConfig: Boolean;
begin
Result := IsDowngradeSetup;
end;
To answer your actual question, you can do this:
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageId = wpReady then
begin
if PrevInstallExists then
begin
{ In Inno Setup 6, you can use WizardSelectTasks }
WizardForm.TasksList.Checked[0] := False;
end;
end;
end;
function UpdateReadyMemo(
Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo,
MemoGroupInfo, MemoTasksInfo: String): String;
begin
if PrevInstallExists then
begin
MemoTasksInfo := '';
end;
end;
Though again, I do not think, that this is a good solution.
Or even easier, use the UsePreviousTasks:
[Setup]
UsePreviousTasks=no
Or similarly using the checkedonce flag:
[Tasks]
Name: DeleteConfig; Description: "{cm:Task_DeleteConfig}"; Flags: unchecked checkedonce
Related
I have an installation file for my app and it contains the .exe file and a .zip file as well.
What I want is:
Recently I added a code in the [Code] section that is extracting files from zip, But actually, it happened after the installation is done, and the progress bar is 100%, So what I want is to make that code's (unzipping) process work with the progress bar and show the user what is extracting at the moment.
For example: let's say extracting files will take 50% of the progress bar and the rest will take it the code section while it is unzipping, with the state about what is extracting at the moment.
Here is the code:
[Code]
procedure InitializeWizard;
begin
ForceDirectories(ExpandConstant('{localappdata}\folder-A\app\folder-B'))
end;
const
SHCONTCH_NOPROGRESSBOX = 4;
SHCONTCH_RESPONDYESTOALL = 16;
procedure unzip(ZipFile, TargetFldr: variant);
var
shellobj: variant;
SrcFldr, DestFldr: variant;
shellfldritems: variant;
begin
if FileExists(ZipFile) then begin
if not DirExists(TargetFldr) then
if not ForceDirectories(TargetFldr) then begin
MsgBox('Can not create folder '+TargetFldr+' !!', mbError, MB_OK);
Exit;
end;
shellobj := CreateOleObject('Shell.Application');
SrcFldr := shellobj.NameSpace(ZipFile);
DestFldr := shellobj.NameSpace(TargetFldr);
shellfldritems := SrcFldr.Items;
DestFldr.CopyHere(
shellfldritems, SHCONTCH_NOPROGRESSBOX or SHCONTCH_RESPONDYESTOALL);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
unzip(ExpandConstant('{app}\example.zip'),ExpandConstant('{app}\'));
end;
end;
The easiest solution is to use the WizardForm.StatusLabel:
WizardForm.StatusLabel.Caption := 'Extracting...';
For more fancy solution you can use TOutputProgressWizardPage. For an example that even displays a progress bar (though by using a DLL for the extraction), see:
Inno Setup - How to add cancel button to decompressing page?
This post lists more related examples:
Inno Setup: How to modify long running script so it will not freeze GUI?
I'm stuck on simple situation with OnClickCheck property. The problem is that I see a Msgbox every time I turn on backup task, but also (while it's switched on) OnClickCheckappeared on pressing uninst task too! Seems that OnClickCheck checks all clicks, but I need to check click only on the first task.
It is logical to add to "WizardForm.TasksList.OnClickCheck" exact number of task (WizardForm.TasksList.OnClickCheck[0]), but compiler doesn't agree with it.
[Tasks]
Name: backup; Description: do backup
Name: uninst; Description: do not create uninstaller
[Code]
procedure TaskOnClick(Sender: TObject);
begin
if IsTaskSelected('backup') then
begin
MsgBox('backup task has been checked.', mbInformation, MB_OK)
end;
end;
procedure InitializeWizard();
begin
WizardForm.TasksList.OnClickCheck := #TaskOnClick;
end;
There's no way tell exactly what task (list item) was changed in the OnClickCheck event.
To tell which item was checked by the user, you can use the ItemIndex property. The user can check only the selected item.
Though if you have a task hierarchy, even unselected task can be toggled automatically by the installer due to a change in child/parent items. So to tell all changes, all you can do is to remember the previous state and compare it against the current state, when the OnClickCheck is called.
var
TasksState: array of TCheckBoxState;
procedure TasksClickCheck(Sender: TObject);
var
I: Integer;
begin
for I := 0 to WizardForm.TasksList.Items.Count - 1 do
begin
if TasksState[I] <> WizardForm.TasksList.State[I] then
begin
Log(Format('Task %d state changed from %d to %d',
[I, TasksState[I], WizardForm.TasksList.State[I]]));
TasksState[I] := WizardForm.TasksList.State[I];
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
var
I: Integer;
begin
if CurPageID = wpSelectTasks then
begin
{ Only now is the task list initialized (e.g. based on selected setup }
{ type and components). Remember what is the current/initial state. }
SetArrayLength(TasksState, WizardForm.TasksList.Items.Count);
for I := 0 to WizardForm.TasksList.Items.Count - 1 do
TasksState[I] := WizardForm.TasksList.State[I];
end;
end;
procedure InitializeWizard();
begin
WizardForm.TasksList.OnClickCheck := #TasksClickCheck;
end;
Instead of using indexes, you can also use task names with use of WizardSelectedTasks or WizardIsTaskSelected. For an example, see Inno Setup: how to auto select a component if another component is selected?
Also see:
Inno Setup ComponentsList OnClick event
Inno Setup Uncheck a task when another task is checked
Inno Setup - Show children component as sibling and show check instead of square in checkbox
Is it possible to disable the the Preparing To Install wpPreparing and the Installing wpInstalling Wizard Pages (i.e. the ones with the progress bar) so that they do not show during installation? There does not appear to be a built-in directive or method (e.g. for the Ready Wizard Page you can use DisableReadyPage=yes to do so). Am I missing something, or is it, as I suspect, simply not possible?
I have already tried using:
function ShouldSkipPage(CurPageID: Integer): Boolean;
begin
if CurPageID = wpPreparing then
Result := True;
if CurPageID = wpInstalling then
Result := True;
end;
Have you tried this - DisableReadyPage=yes in the [Setup] section.
Seems the only other option is to use the "install silently" command line switch. I'd be careful though this essentially installs a potentially destructive program without the users knowledge.
It is not possible to skip the wpPreparing or wpInstalling Wizard Pages. However, if the installer is not actually installing anything and is being used to return something, say an unlock code, as is the use case here, the following could be done instead:
//Disable the Exit confirmation prompt
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
Cancel := True;
Confirm := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
//Get the unlock code
if CurPageID = UnlockCodePage.ID then
begin
if UnlockCodePage.Values[0] = '' then
begin
MsgBox('You must enter an installation ID to generate an unlock code.',
mbError, MB_OK);
end
else
begin
UnlockCodePage.Values[1] := GetUnlockCode;
end;
Result := False;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
//Define button visibility, whether the Back button is enabled and change the Next and Cancel button labels
WizardForm.CancelButton.Caption := '&Close';
if CurPageID = UnlockCodePage.ID then
begin
WizardForm.BackButton.Enabled := False;
WizardForm.NextButton.Caption := '&Generate';
end;
end;
Hopefully this may help someone looking to do something similar.
I try to making setup file to patch previous program. The setup must be able to check if previous program is installed or not.
This is my unusable code
[Code]
function GetHKLM() : Integer;
begin
if IsWin64 then
begin
Result := HKLM64;
end
else
begin
Result := HKEY_LOCAL_MACHINE;
end;
end;
function InitializeSetup(): Boolean;
var
V: string;
begin
if RegKeyExists(GetHKLM(), 'SOFTWARE\ABC\Option\Settings')
then
MsgBox('please install ABC first!!',mbError,MB_OK);
end;
My condition is
must check windows 32- or 64-bits in for RegKeyExists
if previous program is not installed, show error message and exit setup program, else continue process.
How to modify the code?
Thank you in advance.
**Update for fix Wow6432Node problem. I try to modify my code
[Code]
function InitializeSetup: Boolean;
begin
// allow the setup to continue initially
Result := True;
// if the registry key based on current OS bitness doesn't exist, then...
if IsWin64 then
begin
if not RegKeyExists(HKLM, 'SOFTWARE\Wow6432Node\ABC\Option\Settings') then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end
else
if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings' then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end
end;
end;
The updated code in the question is incorrect -- you should never ever use Wow6432Node anywhere other than when looking at paths in RegEdit.
From the behaviour you have described, you are actually looking for a 32-bit application. In this case you can use the same code regardless of whether Windows is 32-bit or 64-bit; you were overthinking your original question.
Here is the corrected code from your updated question:
[Code]
function InitializeSetup: Boolean;
begin
// allow the setup to continue initially
Result := True;
if not RegKeyExists(HKLM, 'SOFTWARE\ABC\Option\Settings') then
begin
// return False to prevent installation to continue
Result := False;
// and display a message box
MsgBox('please install ABC first!!', mbError, MB_OK);
end;
end;
I have an optional wizard page of TInputDirWizardPage type.
How to add button which will not validate data and skip if data were not entered?
Did you check the inno help, here you see the available functions on the TInputDirWizardPage
TInputDirWizardPage = class(TWizardPage)
function Add(const APrompt: String): Integer;
property Buttons[Index: Integer]: TNewButton; read;
property Edits[Index: Integer]: TEdit; read;
property PromptLabels[Index: Integer]: TNewStaticText; read;
property SubCaptionLabel: TNewStaticText; read;
property Values[Index: Integer]: String; read write;
end;
I used this way only if i needed a text input on the page. I recommend you to create a complete custom WizardPage, with that you are more flexible. For the creation of the page you can use a designer, I created all my custom pages with the InnoSetup Form Designer. Here you can see it in action http://www.cenadep.org/2012/02/09/innosetup-form-designer/
I've found simple and working solution. Instead of adding additional button to avoid validation of empty path. I've just added default dir creation. in [Dirs] section.
[Dirs]
Name: {code:WrkGetWorkingDir}; Flags: uninsneveruninstall
My application could accept working dir cmdline arg or create default one if it is not specified. So. I just always specifying that cmdline arg and creating that default dir (if user did not changed that path) in installation script.
Hope this will help
procedure OnClickMyButton(Sender: TObject);
begin
MsgBox('OnClickMyButton', mbInformation, MB_OK);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = YourPageID.ID then
begin
MyButton := TButton.Create(YourPageID);
MyButton.Parent := YourPageID.Buttons[0].Parent;
MyButton.Top := YourPageID.Edits[0].Top + YourPageID.Edits[0].Height + 10;
MyButton.Left := YourPageID.Edits[0].Left;
MyButton.Width := 100;
MyButton.Caption := 'My Custom Button';
MyButton.OnClick := #OnClickMyButton;
end;
end;