How to show progress during "PrepareToInstall"? - inno-setup

An installer I'm working on does most of its work in the PrepareToInstall function, as everything I need to do might fail, and therefore this is the appropriate place to handle these things in case they do fail. Any failure can be automatically reported by passing the error message in the function's result. There are only 3 small files which the installer actually copies over.
The problem is that the wizard seems to freeze (or not respond rather) during this function, just showing a blank page titled "Preparing to install..." while in reality, it's going through my install process.
I would like to show the progress to the user with a simple procedure ShowProgress(const S: String); which shows the user what it's actually doing. How can I do this?
This is how I'm doing my install, where I'd like to wrap each call to Log()...
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
R: Integer;
begin
Result:= '';
try
Log('Doing this...');
R:= DoThis;
case R of
0: begin
Result:= '';
end;
1: begin
Result:= 'Error message 1 was raised while doing this.';
end;
else begin
Result:= 'Unexpected error doing this: ' + IntToStr(R);
end;
end;
if Result = '' then begin
Log ('Doing that...');
R:= DoThat;
case R of
0: begin
Result:= '';
end;
1: begin
Result:= 'Error message 1 was raised while doing that.';
end;
else begin
Result:= 'Unexpected error doing that: ' + IntToStr(R);
end;
end;
end;
if Result = '' then begin
Log ('Doing something else...');
R:= DoSomethingElse;
case R of
0: begin
Result:= '';
end;
1: begin
Result:= 'Error message 1 was raised while doing something else.';
end;
else begin
Result:= 'Unexpected error doing something else: ' + IntToStr(R);
end;
end;
end;
//A few more blocks like above
//Error logging
if Result <> '' then begin
Log('FAILURE: '+Result);
end;
except
Result:= 'EXCEPTION';
Log('EXCEPTION');
end;
end;

I mixed all your answers guys and I found another possible solution to this question.
I know this is not a so called 'elegant solution'.
Anyway it is a quick solution that can avoid you to develop a separated DLL with custom controls managing the communication between the installer and the DLL.
The following approach describe how to create a custom Page that is a copy of the Page Inno Setup shows during PrepareToInstall setup phase.
This copy must have the same look and feel of the original one plus a progress bar and a label that developer can use to indicate the current step of the PrepareToInstall setup phase.
Let's see some code.
First of all, prepare the custom Page:
[Code]
var
PrepareToInstallWithProgressPage : TOutputProgressWizardPage;
Now define PrepareToInstall function to add our custom stuff:
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: Integer;
begin
PrepareToInstallWithProgressPage.SetProgress(0, 0);
PrepareToInstallWithProgressPage.Show;
try
// First preinstallation step: suppose to kill currently app you are going to update
PrepareToInstallWithProgressPage.SetText('Exiting MyApp Running Instances'), '');
ExecuteCmd('taskkill', '/F /IM MyApp');
// Set progress bar to 10%
PrepareToInstallWithProgressPage.SetProgress(1, 10);
// Second preinstallation step
// DoSomething usefull...
// Set progress bar to 20% after done
PrepareToInstallWithProgressPage.SetProgress(2, 10);
// ...do other preinstallation steps till the end
PrepareToInstallWithProgressPage.SetProgress(10, 10);
finally
PrepareToInstallWithProgressPage.Hide;
end;
end;
At this installation phase we completed the steps for prepare to install phase so the default PrepareToInstall Page of Inno Setup is shown for a while.
Now, the user probably cannot understand that the page changes because our PrepareToInstallWithProgressPage has the same look and feel of the original one.
In order to let our page has the same look and feel we can use SetupMessage function to get the 2 strings of the original Inno Setup PrepareToInstall page.
Using SetupMessage we can avoid to duplicate and localize strings for our custom page to copy the originals.
Just like this:
procedure InitializeWizard;
var
A: AnsiString;
S: String;
begin
// The string msgWizardPreparing has the macro '[name]' inside that I have to replace with the name of my app, stored in a define constant of my script.
S := SetupMessage(msgPreparingDesc);
StringChange(S, '[name]', '{#MY_APPNAME}');
A := S;
PrepareToInstallWithProgressPage := CreateOutputProgressPage(SetupMessage(msgWizardPreparing), A);
end;
I hope this help.

Have a look at the CodeDlg.iss example script included with Inno, in particular at the code that uses CreateOutputProgressPage.
This page type allows you to show a status message and/or a progress bar while you are performing other actions. And it automatically pumps messages whenever you change the progress label/value to ensure that the user sees the correct status.
It is intended for precisely this kind of code.

The code written in the PrepareToInstall function blocks the Windows message pump from processing, rendering the wizard form non-responsive. If many controls are needed to be visible in this screen, showing perhaps a progress bar and list of steps to take, this can be done with a form inside of a DLL. Make sure there is a thread in this DLL which does the actual install process, and only update the GUI to display the status to the user. This DLL form may overlay the wizard, or may even be embedded inside of the wizard in a custom wizard page, for example. The idea is to move your install code from the PrepareToInstall function to within this thread, and only then will you be able to achieve a fully responsive GUI during this process. From the PrepareToInstall function, there should be just one DLL call to initiate the install process, which in turn shows the form from the DLL.
The result may look something like this (in the works):

Related

Remove image from the last Finished page of Inno Setup

How to customize last page (wpFinished) to only have a message, but keep the bottom buttons, like this:
I don't want the image on the left that is there by default.
I was trying to create new page, but don't know how to hide the default finished page or add bottom buttons (Back, Finished, Cancel) on new page.
Hide the WizardBitmapImage2 control and extend remaining controls accordingly.
Something like this:
[Code]
procedure ExtendFinishedPageControl(Control: TControl);
begin
Control.Left := Control.Left - WizardForm.WizardBitmapImage2.Width;
Control.Width := Control.Width + WizardForm.WizardBitmapImage2.Width;
end;
procedure InitializeWizard();
begin
WizardForm.WizardBitmapImage2.Visible := False;
ExtendFinishedPageControl(WizardForm.RunList);
ExtendFinishedPageControl(WizardForm.NoRadio);
ExtendFinishedPageControl(WizardForm.YesRadio);
ExtendFinishedPageControl(WizardForm.FinishedLabel);
ExtendFinishedPageControl(WizardForm.FinishedHeadingLabel);
end;

How to fix, images loaded in multi thread sometimes don't show up on the form

In my manga viewer i try to load a large number of images (around 200), i try loading these images inside an anonymous thread and when the loading finishes i call a Thread.synchronize, this works fine, but in some cases i keep seeing some images not drawn on the form (I think they are loaded because i can see the information about the image), how can i solve this?
This issue only happens in multi thread so i decided to set the image visible to false and then at the end of the loading inside a Thread.synchronize turn the visible to true, i had hoped this would force some kind of refresh or redraw, but the problem i mentioned consists
TThread.CreateAnonymousThread(procedure
begin
for imageIndex := 0 to fileList.count - 1 do
begin
filePath := fileList[imageIndex]
//Please note that mImageList is an array of FMX.Objects.TImage
//which was filled when the Form is created (I create 300 TImage
//at Form create and later i load the images to the bitmap when
//the user clicks on a new directory(Chapter)
mImageList[imageIndex].beginUpdate();
try
mImageList[imageIndex].loadFromFile(filePath);
mImageList[imageIndex].tagString := filePath;
mImageList[imageIndex].Scale := mImageScale;
mImageList[imageIndex].Visible := false;
except
mImageList[imageIndex].EmptyBitmaps;
end;
mImageList[imageIndex].endUpdate();
end;
TThread.Synchronize(nil, procedure
var
I: Integer;
begin
for I := Low(mImageList) to High(mImageList) do
begin
mImageList[I].Visible := true;
end;
end);
end).Start;
I expect that when i scroll down through the images loaded on the form, i can see them all and they all get drawn on the form properly.

Loop Commands or Functions Until a Condition becomes True in Inno Setup

I want to show a Nice Welcome Animated GIF to my users when running my Program Installer created using Inno Setup.
I want to display some PNG Images to an order (As Inno Setup doesn't support displaying Animated GIFs yet) using Isgsg.dll until Setup finishes initializing my tons of codes.
I wrote a code to show those PNG Images in order, but it stops after last one is shown.
I need to continue showing from first PNG Image after last one shown before.
If Setup was initialized,(I mean if WizardForm is visible) the Looping Procedure should stop.
The Codes I wrote to display those PNG Images:
function InitializeSetup(): Boolean;
var
DlgWait: TForm;
if Result = True then begin
ExtractTemporaryFile('Welcome1.png');
ExtractTemporaryFile('Welcome2.png');
ExtractTemporaryFile('Welcome3.png');
ExtractTemporaryFile('Welcome4.png');
ExtractTemporaryFile('Welcome5.png');
ExtractTemporaryFile('Welcome6.png');
ExtractTemporaryFile('Welcome7.png');
<<< LOOPING SHOULD BEGIN FROM HERE >>>
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome1.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome2.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome3.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome4.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome5.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome6.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome7.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
<<< LOOPING SHOULD CONTINUE FROM HERE IF NOT WizardForm VISIBLE, OTHERWISE LOOPING SHOULD BE STOPPED >>>
...
end;
How can I do this as I expect?
UPDATED QUESTION
I can't think why this Code is not working.
This DLL requires PNG File's Filename as an AnsiString.
But I've provided a String.
Is this gone wrong or any other Synatx Error Here for this to not working?
Not Working means those PNG Images Showing Loop Procedure not working.
The Code I tried to add to do this Conditional Loop using Repeat Until:
function InitializeSetup(): Boolean;
var
DlgWait: TForm;
IMessageHandler: TForm;
X: Integer;
ErrorCode: Integer;
LblWait: TLabel;
if Result := True then begin
DlgWait := TForm.Create(nil);
DlgWait.Hide;
begin
Order:=1;
Repeat
ShowSplashScreen(DlgWait.Handle,ExpandConstant('{tmp}\Welcome+IntToStr(Order)+.png'),0250,1000,0250,0,255,True,$FFFFFF,10);
Order:=Order+1;
Until FileExists(ExpandConstant('{tmp}\Welcome+IntToStr(Order)+.png')) = False;
end;
end;
Are there any syntax Errors?
But Compiler doesn't give any Compiler Warning or Error.
Thanks in Advance.
You need to reset your counter when you've reached the end. Something like this should get you started. (NOTE: Untested - I don't have InnoSetup on this machine. Replace the test in the until with whatever is appropriate to detect the WizardForm being visible.)
function InitializeSetup(): Boolean;
var
DlgWait: TForm;
IMessageHandler: TForm;
X: Integer;
ErrorCode: Integer;
LblWait: TLabel;
const
NumImages = 7;
begin
if Result then
begin
DlgWait := TForm.Create(nil);
DlgWait.Hide;
Order := 1;
repeat
ShowSplashScreen(DlgWait.Handle, ExpandConstant('{tmp}\Welcome' + IntToStr(Order) + '.png'), 0250, 1000, 0250, 0,255, True, $FFFFFF, 10);
Order := Order + 1;
if Order > NumImages then
Order := 1;
until WizardForm.Visible;
end;
end;

Inno Setup Place controls on wpPreparing Page

I am trying to place a label on the wpPreparing page to indicate uninstallation of an existing version, prior to running the new installation. Here is my code:
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
UninstallingLabel: TNewStaticText;
intResultCode: Integer;
begin
with UninstallingLabel do
begin
Caption := 'Uninstalling existing version...';
Left := WizardForm.StatusLabel.Left;
Top := WizardForm.StatusLabel.Top;
Parent := wpPreparing.Surface;
end;
if strExistingInstallPath <> '' then
begin
Exec(GetUninstallString, '/verysilent /suppressmsgboxes', '', SW_HIDE,
ewWaitUntilTerminated, intResultCode);
end;
end;
The trouble is it does not seem to like Parent := wpPreparing.Surface and compiling fails with a
Semicolon (;) expected
error. This syntax works when adding a label to a custom created page. Why does this fail when trying to add it to wpPreparing?
The wpPreparing is not an object, it's just a numerical constant.
The WizardForm.PreparingPage holds a reference to the "Preparing to Install" page. Note that it is of type TNewNotebookPage already, not TWizardPage. So you use it directly as a parent.
Also note that the StatusLabel is on the "Installing" page. You probably want to relate your new label to the PreparingLabel instead.
And you have to create the UninstallingLabel.
UninstallingLabel := TNewStaticText.Create(WizardForm);
with UninstallingLabel do
begin
Caption := 'Uninstalling existing version...';
Left := WizardForm.PreparingLabel.Left;
Top := WizardForm.PreparingLabel.Top;
Parent := WizardForm.PreparingPage;
end;
Though do you really want to shadow the PreparingLabel (as you use its coordinates).
What about reusing it instead?
WizardForm.PreparingLabel.Caption := 'Uninstalling existing version...';
I've replayed your code. It works if you use just WizardForm as the parent. But it's in the top left corner of the form...
wpPreparing is the name of a constant that holds the ID of the correspnding page.
And you have to create an instance of UninstallingLabel

How can I show a "please wait" window while checking for prerequisites in my installer?

I do a number of checks in the InitializeSetup function in my script. These take about 10 seconds to complete, during which time nothing is displayed except for the window button on the taskbar (clicking it yields nothing). I would like to show a simple "Please wait" window instead. How can I do this?
Here is sample script that shows how you can create a custom dialog.
Basically create a custom form and place the custom control on it. You can use this as starting point to get the dialog appear as you wish.
[Setup]
AppName='Test Date Script'
AppVerName='Test Date Script'
DefaultDirName={pf}\test
[Code]
function InitializeSetup() : boolean;
var
DlgWait : TSetupForm;
lblWait : TLabel;
I : Integer;
begin
dlgWait := CreateCustomForm;
dlgWait.FormStyle := bsDialog;
dlgWait.Position := poMainFormCenter;
lblWait := TLabel.Create(dlgWait);
lblWait.Parent := dlgWait;
lblWait.Caption := 'Please Wait';
lblWait.Visible := True;
dlgWait.Show;
dlgWait.Refresh; // Process the paint message
for I := 0 to 10 do
begin
Sleep(1000); // Simulate Functions taking 10 sec
dlgWait.Refresh;
end;
DlgWait.Free;
end;

Resources