How to disable Disk Space Warning message in Inno Setup? - inno-setup

I am creating installer using Inno Setup. I have calculated available disk space using function GetSpaceOnDisk. I am displaying error message if available disk space is not enough, and then installer will not continue.
But before my error message displays, Inno Setup Disk space warning is shown with Yes/No option. How can I disable this warning?

You cannot disable the check, nor change the buttons.
What you can do, is to revert a meaning of a question in the message by overriding the default text using [Messages] section, to say something like:
Do you want to cancel installation?
If the user presses No, the installer stays on the Select Destination Location page. If the user presses Yes, the NextButtonClick(wpSelectDir) gets called. There you repeat the check for the disk space (to distinguish the call from a basic scenario, with no warning), and if there's not enough space, you abort the installer forcefully.
[Messages]
DiskSpaceWarning=Setup requires at least %1 KB of free space to install, but the selected drive only has %2 KB available.%n%nDo you want to cancel installation?
[Code]
function NotEnoughSpace: Boolean;
begin
Result := { Check disk space };
end;
procedure ExitProcess(exitCode:integer);
external 'ExitProcess#kernel32.dll stdcall';
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = wpSelectDir then
begin
if NotEnoughSpace then
begin
ExitProcess(0);
end;
end;
Result := True;
end;
The ultimate solution is to re-implement the Select Destination Location page. It's not that difficult. It's just one edit box and one button.

Related

Inno Download Plugin - how detect modal buttons?

For our purposes, we decided to use Inno Download Plugin and Inno Setup version 6.2.0
We switched the installer to silent mode to get rid of unnecessary windows and buttons. It turned out somehow like this (I don’t attach idp.iss, it’s unchanged)
[code]https://pastebin.com/g7xb6iWj
Everything works fine, but there are a couple of but:
1 There is a Downloading window called by IDP, click on the cross to close the window and in the modal window that appears, confirm with Yes
Instead of aborting the download, it tries to proceed with the installation and creates shortcuts
2 There is a Downloading window called by IDP, turn off wifi, in the modal window that appears where they say "Internet is gone" and ask "Retry or Cancel?" click Cancel
Instead of aborting the download, it tries to proceed with the installation and creates shortcuts
I found an explanation here
Exit from Inno Setup installation from [Code]
But I can't figure out exactly how to catch buttons in specific modal windows.
And if I'm not mistaken, the second interrupt case is not native and only applies to IDP
Any ideas to right cancelation of installation of those 2 cases would be great.
My friend did a solution
procedure CurPageChanged(CurPageID: Integer);
begin
WizardForm.Bevel1.Visible := false;
WizardForm.MainPanel.Visible := false;
WizardForm.InnerNotebook.Top := 50;
WizardForm.OuterNotebook.height := 400;
if CurPageID = wpInstalling then begin
Downloaded := idpFilesDownloaded();
if not(Downloaded) then begin
ExitProcess(553);
end;
end;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
if Cancel = True then begin
ExitProcess(554);
end;
end;

Handling and customizing errors and messages in Inno Setup

Inno Setup will show different message boxes to the user.
For example,
When it tries to install a file that is in use, it will show a message to abort/ignore/cancel.
When the setup is installing the files and the target path will have low space while installing, the setup will give an error.
I need to customize these message boxes on my own. (I do not want these native messages to be shown to the user) for example, I need to show another message box, or even totally do not show a specific message from Inno Setup, or changing a label when that message is going to fire.
All Inno Setup messages can be customized using the [Messages] section.
Some examples:
How to modify error message in Inno Setup?
Show a custom message for unsupported architectures
How can I show my own message and then exit setup if the current version of Windows is not supported?
As for the change of the message box layout/design. You cannot really change it. With some fancy implementation of Check and BeforeInstall parameters, you might be able to catch some problems before Inno Setup detects them and handle them your custom way. But that's lot of work with unreliable results.
If you tell us what are you trying to achieve more specifically, you may get more specific answer.
If you need a solution that allows everything that Inno Setup allows on error, including clean abort of the installation, Check or BeforeInstall won't help as they do not have a way to cleanly abort it.
You would have to do all the checks before the installation, e.g. in CurStepChanged(ssInstall).
[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: ShouldInstallFile
[Code]
var
DontInstallFile: Boolean;
function ShouldInstallFile: Boolean;
begin
Result := not DontInstallFile;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
FileName: string;
Msg: string;
Response: Integer;
begin
if CurStep = ssInstall then
begin
FileName := ExpandConstant('{app}\MyProg.exe');
repeat
if FileExists(FileName) and (not DeleteFile(FileName)) then
begin
Msg := Format('File %s cannot be replaced', [FileName]);
Response := MsgBox(Msg, mbError, MB_ABORTRETRYIGNORE)
case Response of
IDABORT: Abort;
IDIGNORE: DontInstallFile := True;
end;
end;
until (Response <> IDRETRY);
end;
end;

Component Exist Message Box too Big - InnoSetup

I have a component list of more than 80 options,where user can select and then install.
The setup remembers the previous install components and automatically checks the Components, Now if user deselects all, the "Component Exist" Warning Message Box is shown.
Because user deselected all 80 options the list becomes to long and the Message box goes out of screen space and user is now stuck.
I know there is NoUninstallWarning in Messages which has the text for the warning message and takes one argument as %1
Is there a way I can change the argument value , rather than having all options listed in indiviual line , I would like to have them as comma separated?
Or if I can have a Scrollbar in the Message box?
Please help
No, this message is internal and you can't customise it like that without modifying Inno's own source code.
In that situation the user shouldn't be completely stuck -- they should be able to press ESC to return to the component selection window and then select everything again.
A simple way to avoid this problem is to not allow the user to deselect components, once installed. You can do this with a bit of code like this:
var
InstalledComponentsDisabled: Boolean;
procedure CurPageChanged(CurPageId: Integer);
var
i: Integer;
begin
if (CurPageId = wpSelectComponents) and
(WizardForm.PrevAppDir <> '') and
not InstalledComponentsDisabled then begin
InstalledComponentsDisabled := True;
for i := 0 to WizardForm.ComponentsList.Items.Count - 1 do begin
if WizardForm.ComponentsList.Checked[i] then begin
WizardForm.ComponentsList.ItemEnabled[i] := False;
end;
end;
end;
end;
This has a similar effect to making anything already installed on upgrades fixed.
An alternate option is to put disablenouninstallwarning on all of your components and then either implement the messagebox completely yourself, add a bit of static text warning about removing components permanently on the page, or even do something to actually support removing components (eg. [InstallDelete] entries or UninsHs).

How to show ok button only in message box when there is not enough space to install application [duplicate]

I have built an installer to install application using Inno Setup. But I want to display an error message showing that there is not enough space in the drive or path, where I am going to install application, if there is no space available.
By default I am getting Inno built in ability to show message when there is no space available in the hard disk or selected path. But it shows YES and NO button to continue or cancel. Here I want to show error message with a OK button and when the user clicks ok button it should stop installation. Please help me on this issue. I could not find any ways to do so.
To determine a free space on a drive of a specific folder (in your case the selected directory), you can call the GetSpaceOnDisk or GetSpaceOnDisk64 function. The difference between them is that the first one is able to return space info in bytes as well as in megabytes. The latter returns this info just in bytes. For the following example I chose the first mentioned function, so you can decide in which units you want to operate by modifying a single boolean parameter:
[Code]
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess#kernel32.dll stdcall';
function IsEnoughFreeSpace(const Path: string; MinSpace: Cardinal): Boolean;
var
FreeSpace, TotalSpace: Cardinal;
begin
// the second parameter set to True means that the function operates with
// megabyte units; if you set it to False, it will operate with bytes; by
// the chosen units you must reflect the value of the MinSpace paremeter
if GetSpaceOnDisk(Path, True, FreeSpace, TotalSpace) then
Result := FreeSpace >= MinSpace
else
RaiseException('Failed to check free space.');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID = wpSelectDir then
begin
// the second parameter in this function call is the expected min. space in
// units specified by the commented parameter above; in this example we are
// checking if there's at least 1 MB of free space on drive of the selected
// directory; we need to extract a drive portion of the selected directory,
// because it's probable that the directory won't exist yet when we check
if not IsEnoughFreeSpace(ExtractFileDrive(WizardDirValue), 1) then
begin
MsgBox('There is not enough space on drive of the selected directory. ' +
'Setup will now exit.', mbCriticalError, MB_OK);
// in this input parameter you can pass your own exit code which can have
// some meaningful value indicating that the setup process exited because
// of the not enough space reason
ExitProcess(666);
end;
end;
end;
Maybe my answer looks like off-topic.
I had more or less the same problem.
If you have in the files section a check function made by yourself, setup can only count the number of (Mega)bytes of those files which have "normal" check flags.
A way to avoid this is count-up the bytes by yourself and put the result in the ExtraDiskSpaceRequired directive in the [setup] section

How to check whether required space is available in the hard disk to install application using Inno Setup installer

I have built an installer to install application using Inno Setup. But I want to display an error message showing that there is not enough space in the drive or path, where I am going to install application, if there is no space available.
By default I am getting Inno built in ability to show message when there is no space available in the hard disk or selected path. But it shows YES and NO button to continue or cancel. Here I want to show error message with a OK button and when the user clicks ok button it should stop installation. Please help me on this issue. I could not find any ways to do so.
To determine a free space on a drive of a specific folder (in your case the selected directory), you can call the GetSpaceOnDisk or GetSpaceOnDisk64 function. The difference between them is that the first one is able to return space info in bytes as well as in megabytes. The latter returns this info just in bytes. For the following example I chose the first mentioned function, so you can decide in which units you want to operate by modifying a single boolean parameter:
[Code]
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess#kernel32.dll stdcall';
function IsEnoughFreeSpace(const Path: string; MinSpace: Cardinal): Boolean;
var
FreeSpace, TotalSpace: Cardinal;
begin
// the second parameter set to True means that the function operates with
// megabyte units; if you set it to False, it will operate with bytes; by
// the chosen units you must reflect the value of the MinSpace paremeter
if GetSpaceOnDisk(Path, True, FreeSpace, TotalSpace) then
Result := FreeSpace >= MinSpace
else
RaiseException('Failed to check free space.');
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if CurPageID = wpSelectDir then
begin
// the second parameter in this function call is the expected min. space in
// units specified by the commented parameter above; in this example we are
// checking if there's at least 1 MB of free space on drive of the selected
// directory; we need to extract a drive portion of the selected directory,
// because it's probable that the directory won't exist yet when we check
if not IsEnoughFreeSpace(ExtractFileDrive(WizardDirValue), 1) then
begin
MsgBox('There is not enough space on drive of the selected directory. ' +
'Setup will now exit.', mbCriticalError, MB_OK);
// in this input parameter you can pass your own exit code which can have
// some meaningful value indicating that the setup process exited because
// of the not enough space reason
ExitProcess(666);
end;
end;
end;
Maybe my answer looks like off-topic.
I had more or less the same problem.
If you have in the files section a check function made by yourself, setup can only count the number of (Mega)bytes of those files which have "normal" check flags.
A way to avoid this is count-up the bytes by yourself and put the result in the ExtraDiskSpaceRequired directive in the [setup] section

Resources