Do not let user install specific component, if another is already installed - installation

Very new to InnoSetup, but I could not find any documentation on this. I would like to implement a condition where if the user has already installed a specific component, it will not allow them to install another specific component.
For example: If Bob has previously installed ComponentA, and ties to install ComponentB, it will error our with a warning "Cannot install ComponentB while ComponentA currently installed"
This is what I have come up with so far:
procedure CurPageChanged(CurPageID: Integer);
var
Value: string;
UninstallKey: string;
begin
UninstallKey := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\' +
ExpandConstant('{#SetupSetting("AppId")}') + '_is1';
Result := (RegQueryStringValue(HKLM, UninstallKey, 'Inno Setup: Selected Components', Value) or
RegQueryStringValue(HKCU, UninstallKey, 'Inno Setup: Selected Components', Value)) and (Value <> '');
if CurPageID = wpSelectComponents then
if Result = WizardForm.ComponentsList.ItemCaption[1] then
begin
WizardForm.ComponentsList.Checked[1] := False;
WizardForm.ComponentsList.ItemEnabled[1] := True;
WizardForm.ComponentsList.Checked[2] := False;
WizardForm.ComponentsList.ItemEnabled[2] := False;
WizardForm.ComponentsList.Checked[3] := False;
WizardForm.ComponentsList.Enabled[3] := True;
end;
end;
end;
I know I do not quite have the Registry Query exactly right for selected components.. I feel like I'm close though. The problem is, Result may have multiple components in it. like (apple,orange,mango) but I want the statement to still be true if just "mango" exists.

Think you could do this in another way:
Use Flags:
exclusive
example:
[Types]
Name: "full"; Description: "Full"; Flags: iscustom
[Components]
Name: "connect"; Description: "Mainsection"; Types: "full" ;Flags: fixed
Name: "connect\compA"; Description: "ComponentA"; Types: "full"; Flags: exclusive
Name: "connect\compB"; Description: "ComponentB"; Flags: exclusive
[Files]
Source: "srcpath"; DestDir: "dirpath"; Components: connect\compA
Source: "srcpath"; DestDir: "dirpath"; Components: connect\compB
It looks like this
So if "Bob" wants to choose componenB he can not use ComponentA without automatic deselect componentB
So now if "Bob" already installed ComponentA and wants to install ComponentB and u dont want that both components are installed u need to use installdelete
example:
[InstallDelete]
Type: filesandordirs; Name: "dirpath\compA"; Components: connect\compB;
Type: filesandordirs; Name: "dirpath\compB"; Components: connect\compA;
I hope this will help

Related

Inno Setup: turning exclusive Tasks into radio boxes

I'm working on an Inno Setup installer that has 4 radio boxes to let the user select which "flavor" they want to install. The documentation left me confused; should I use Tasks, Types, or Components for that?
It seems Tasks have radio-button behavior built-in: when the exclusive flag is set, only one of the tasks can be selected at a time. That's exactly what I want. So I have this code:
[Tasks]
Name: variant-a; Description: "A"; GroupDescription: "Variant"; Flags: exclusive
Name: variant-b; Description: "B"; GroupDescription: "Variant"; Flags: exclusive unchecked
Name: variant-c; Description: "C"; GroupDescription: "Variant"; Flags: exclusive unchecked
Name: variant-d; Description: "D"; GroupDescription: "Variant"; Flags: exclusive unchecked
How can I make the radio buttons show up? And how do I get the value of the Task that was chosen (e.g. "variant-a")?
The best is to use an existing script and see how it works
The documentation left me confused; should I use Tasks, Types, or
Components for that?
The added code parts have both : Task and Components
So decide what is more useful for your project.
In the examples directory are many useful examples that are well suited to respond to user input.
Copy the ..:...\Inno Setup 5\Examples\CodeExample1.iss to CodeExample1_ex.iss.
Open the copied file and insert the following code fragments.
Search for
OutputDir=userdocs:Inno Setup Examples Output
Insert below
//OutputDir=userdocs:Inno Setup Examples Output
[Tasks]
Name: variant_a; Description: "A"; GroupDescription: "Variant"; Components: main\a; Flags: exclusive
Name: variant_b; Description: "B"; GroupDescription: "Variant"; Components: main\b; Flags: exclusive unchecked
Name: variant_c; Description: "C"; GroupDescription: "Variant"; Components: main\c; Flags: exclusive unchecked
Name: variant_d; Description: "D"; GroupDescription: "Variant"; Components: main\d; Flags: exclusive unchecked
; Disabled we need it later -----------------------------------------------------
;Name: variant_a; Description: "A"; GroupDescription: "Variant"; Flags: exclusive
;Name: variant_b; Description: "B"; GroupDescription: "Variant"; Flags: exclusive unchecked
;Name: variant_c; Description: "C"; GroupDescription: "Variant"; Flags: exclusive unchecked
;Name: variant_d; Description: "D"; GroupDescription: "Variant"; Flags: exclusive
[Types]
Name: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom
[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive
Name: "main"; Description: "variants"; Types: custom
Name: "main\a"; Description: "variant_a"; Types: custom; Flags: exclusive
Name: "main\b"; Description: "variant_b"; Types: custom; Flags: exclusive
Name: "main\c"; Description: "variant_c"; Types: custom full; Flags: exclusive
Name: "main\d"; Description: "variant_d"; Types: custom; Flags: exclusive
Search for the [Code] and add I : integer;
[Code]
var
MyProgChecked: Boolean;
MyProgCheckResult: Boolean;
FinishedInstall: Boolean;
I : integer;
Search for
procedure CurPageChanged(CurPageID: Integer);
Insert below
//procedure CurPageChanged(CurPageID: Integer);
var
Addtxt,WFCaption,WSelCaption : String;
Search for
Log('CurPageChanged(' + IntToStr(CurPageID) + ') called');
Insert below
//Log('CurPageChanged(' + IntToStr(CurPageID) + ') called');
if CurPageID = wpSelectComponents then begin
WFCaption := WizardForm.ComponentsList.ItemCaption[8];
Addtxt := ' <---------- If I where you I would take this';
if Pos(Addtxt,WFCaption) = 0 then WizardForm.ComponentsList.ItemCaption[8] := WFCaption + Addtxt;
end;
if CurPageID = wpSelectTasks then
begin
{ Only now is the TasksList populated }
if WizardForm.TasksList.Items.Count = 2 then begin
WSelCaption := Copy(WizardForm.TasksList.ItemCaption[1],1,2); //else
if Pos('C',WizardForm.TasksList.ItemCaption[1]) > 0 then
WSelCaption := WSelCaption + ' <-------- Your choice, my favorite, thank you :-)'#13#10+
' Not correct? Please go back and change the selection' else
WSelCaption := WSelCaption + ' <-------- Your choice : Not correct? Please go back and change the selection';
WizardForm.TasksList.ItemEnabled[0] := False;
WizardForm.TasksList.ItemCaption[1] := WSelCaption;
end else begin
For I := 1 to WizardForm.TasksList.Items.Count -1 do begin
if WizardForm.TasksList.Checked[I] then begin
WizardForm.TasksList.ItemCaption[I] := Copy(WizardForm.TasksList.ItemCaption[I],1,2) +
' <-------- Your choice : Not correct? Please change the selection';
end;
end; // for
end;
end;
Next are the constants used for the CurPageID
Example:
if CurPageID = wpSelectComponents then begin
wpWelcome, wpLicense, wpPassword, wpInfoBefore wpUserInfo,
wpSelectDir, wpSelectComponents wpSelectProgramGroup, wpSelectTasks,
wpReady wpPreparing, wpInstalling, wpInfoAfter, wpFinished
Change the individual code sections and look at the result.
It is easier and quicker to achieve results that are traceable.
Version A:
and the Task List result.
Why the trick with the .ComponentsList?
You do not need an extra event.
It is selected in the .ComponentsList and Controlled in the .Taskslist.
If you select nothing the .Taskslist is not visible.
All without extra code in the [Code] section.
Now we try Version B
Go to the [Task] section and look for
; Disabled we need it later -----------------------------------------------------
Disable the first four lines and enable the next four lines.
Search for procedure CurPageChanged(CurPageID: Integer);
Add above the Event WizardForm.TasksList.OnClickCheck := #TaskListClickCheck;
and the procedure for the .TasksList.
Here goes what you need to capture the selected value.
How or what you do with the Event WizardForm.TasksList.OnClickCheck and the freely selectable name of the function here : procedure TaskListClickCheck(Sender: TObject); depends on the requirements you want to achieve.
procedure TaskListClickCheck(Sender: TObject);
begin
For I := 1 to WizardForm.TasksList.Items.Count -1 do begin
if WizardForm.TasksList.Checked[I] then
WizardForm.TasksList.ItemCaption[I] := Copy(WizardForm.TasksList.ItemCaption[I],1,2) +
' <-------- Your choice : Not correct? Please change the selection' else
WizardForm.TasksList.ItemCaption[I] := Copy(WizardForm.TasksList.ItemCaption[I],1,2);
end;
end;
procedure InitializeWizard();
begin
WizardForm.TasksList.OnClickCheck := #TaskListClickCheck;
end;
//procedure CurPageChanged(CurPageID: Integer);
Now we need an event to intercept the selection.
Without extra code, the selection is always "A".
At last put before the final list, a little late right?
The user thought he was almost done!
The Name: "main"; Description: "variants"; Types: custom etc. part of the .ComponentsList is useless now. Best to disable it also.
Where can you find all this information?
Look at the Inno Setup help.
Search for WizardForm.TasksList
There we can see the property TasksList: **TNewCheckListBox**; read;
(Used Properties are blue)
So we click on TNewCheckListBox and get.
One or the other we can get a bit easier (direct way: value of a variable).
But here I did not want to make it too complicated and not use directly which only contributes to confusion.
Just using an existing code in an already existing script I do not understand as a code wrighting service.
To understand it only as an initial aid.

Prompt user in Inno Setup for file to be used in Shortcut

In Inno Setup I try to create this shortcut:
"C:\Program Files (x86)\MapInfo\Professional\MapInfow.exe" "{app}\DPImap.MBX"
It works fine with static text, however location of MapInfow.exe can vary so I like to ask the user for it.
This is what I did so far, however the shortcut is not created as intended
; Default value for silent installion
#define MapInfoDefault AddBackslash(GetEnv("ProgramFiles(x86)")) + "MapInfo\Professional\MapInfow.exe"
[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
[Icons]
Name: {group}\DPImap; Filename: {code:MapInfoExecutable} {app}\DPImap.mbx
Name: {userdesktop}\DPImap; Filename: {code:MapInfoExecutable} {app}\DPImap.mbx; Tasks: desktopicon
[Code]
function MapInfoExecutable(Param: String): String;
var
FileName: string;
begin
FileName := '';
if GetOpenFileName('Locate your MapInfo Application', FileName, ExpandConstant('{pf32}'), 'Executable (*.exe)|*.exe', 'exe') then
Result := FileName
else
{ Return default #MapInfoDefault if user does not provide any file }
Result := ExpandConstant('{#MapInfoDefault}');
end;
How can I provide proper user dialog?
It should be:
[Icons]
Name: {group}\DPImap; Filename: "{code:MapInfoExecutable}"; \
Parameters: """{app}\DPImap.mbx"""
You should also cache the selected file name, otherwise you get the prompt at least twice, and probably even more times.
var
FileName: string;
function MapInfoExecutable(Param: String): String;
begin
if FileName = '' then
begin
if not GetOpenFileName(
'Locate your MapInfo Application', FileName, ExpandConstant('{pf32}'),
'Executable (*.exe)|*.exe', 'exe') then
begin
{ Return default #MapInfoDefault if user does not provide any file }
FileName := '{#MapInfoDefault}';
end;
end;
Result := FileName;
end;
Or actually even better, use a custom page, rather than a dialog, which pops up at uncontrollable moment.
See Inno Setup Prompt for external file location.
And even if you like the dialog, pop it on specific page/moment of your choice, cache the selected file name to a global variable and use the variable in the MapInfoExecutable.
Note that I've removed ExpandConstant from '{#MapInfoDefault}' - It's nonsense. See Evaluate preprocessor macro on run time in Inno Setup Pascal Script.

Inno Setup Jumps to Second Page if Program is Installed [duplicate]

This question already has answers here:
Inno Setup generated installer does not show "Select Destination Location" page on some systems
(3 answers)
Closed 4 years ago.
On first install everything runs smooth, but if I run the installer again it just jumps to the second page asking where i want to put the additional files, and then in the ready page only the parameters for the additional files folders is shown. The ignore version flag is set, what else could it be?
[Setup]
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
Compression=lzma
SolidCompression=yes
OutputBaseFilename=aeolian_meditation_setup
WizardSmallImageFile=compiler:greenlogo.bmp
WizardImageFile=compiler:glogo.bmp
DirExistsWarning=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
;Main program that will be installed in {app} folder
Source: "D:\ocean_swift\Flowstone Projects\Aeolian Meditation Advanced\OS Aeolian Meditation Advanced A191.exe"; DestDir: "{app}"; Flags: ignoreversion
;Database file that will installed where user choosed
Source: "D:\ocean_swift\Flowstone Projects\Aeolian Meditation Advanced\onts\OpenSans-Regular.ttf"; DestDir: "{fonts}"; Flags: onlyifdoesntexist; FontInstall: "Open Sans"
Source: "C:\Program Files (x86)\VSTPlugins\OS Aeolian Meditation Advanced A191.dll"; DestDir: "{code:GetDataDir}"
[Code]
var
DataDirPage: TInputDirWizardPage;
procedure InitializeWizard;
begin
// Create the page
DataDirPage := CreateInputDirPage(wpSelectDir,
'Select 32bit VST Plugin Directory', 'Where should the 32bit VSTi plugin be installed??',
'Select the folder in which Setup should install the 32bit VSTi plugin, then click Next.',
False, '');
DataDirPage.Add('');
DataDirPage.Values[0] := 'C:\Program Files (x86)\VSTPlugins\';
end;
procedure RegisterPreviousData(PreviousDataKey: Integer);
begin
// Store the selected folder for further reinstall/upgrade
SetPreviousData(PreviousDataKey, 'DataDir', DataDirPage.Values[0]);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
// Set default folder if empty
if DataDirPage.Values[0] = '' then
DataDirPage.Values[0] := ExpandConstant('{sd}\DataDir');
Result := True;
end;
function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo,
MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
S: String;
begin
// Fill the 'Ready Memo' with the normal settings and the custom settings
S := '';
S := S + MemoDirInfo + NewLine + NewLine;
S := S + '32bit VSTi' + NewLine;
S := S + Space + DataDirPage.Values[0] + NewLine;
Result := S;
end;
function GetDataDir(Param: String): String;
begin
{ Return the selected DataDir }
Result := DataDirPage.Values[0];
end;
If you look here you will see that the default value for DisableProgramGroupPage is auto. As described there:
If this is set to auto, at startup Setup will look in the registry to
see if the same application is already installed, and if so, it will
not show the Select Start Menu Folder wizard page.
If you review the other Disable entries in the help file you will see them behave the same. It is logical to only show these pages during a new install. Change the default behaviour by setting these to no.

How to show several licenses in the installer

I use the Inno Setup to create installer for my program. In my program I use third-party libraries, so I have to show license information for each of them.
also I want the installer to show certain license files to chosen language.
I know how to switch between license files if I have 1 license form.
I've looked in google for whole day but didn't find anything
how can I show several licenses?
You can make each license file match the language file by removing the LicenseFile directive from [Setup] and putting it in the [Languages] like this:
Name: "english"; MessagesFile: "compiler:Default.isl"; LicenseFile: "English License.rtf"
Name: "chinesesimp"; MessagesFile: "compiler:Languages\ChineseSimp.isl"; LicenseFile: "Chinese SIM License.rtf"
Name: "chinesetrad"; MessagesFile: "compiler:Languages\ChineseTrad.isl"; LicenseFile: "Chinese TRA License.rtf"
etc...
Hope that helps
You can use the CreateOutputMsgMemoPage to create a page with the memo box on. You can then adjust the sizing and add the agree/disagree boxes.
; Shows a new license page for the LGPL with the usual accept/don't acccept options
[Code]
var
LGPLPage: TOutputMsgMemoWizardPage;
LGPLAccept: TNewRadioButton;
LGPLRefuse: TNewRadioButton;
procedure LGPLPageActivate(Sender: TWizardPage); forward;
procedure LGPLAcceptClick(Sender: TObject); forward;
procedure LGPL_InitializeWizard();
var
LGPLText: AnsiString;
begin
// Create the page
LGPLPage := CreateOutputMsgMemoPage(wpLicense, SetupMessage(msgWizardLicense), SetupMessage(msgLicenseLabel), CustomMessage('LGPLHeader'), '');
// Adjust the memo and add the confirm/refuse options
LGPLPage.RichEditViewer.Height := ScaleY(148);
LGPLAccept := TNewRadioButton.Create(LGPLPage);
LGPLAccept.Left := LGPLPage.RichEditViewer.Left;
LGPLAccept.Top := LGPLPage.Surface.ClientHeight - ScaleY(41);
LGPLAccept.Width := LGPLPage.RichEditViewer.Width;
LGPLAccept.Parent := LGPLPage.Surface;
LGPLAccept.Caption := SetupMessage(msgLicenseAccepted);
LGPLRefuse := TNewRadioButton.Create(LGPLPage);
LGPLRefuse.Left := LGPLPage.RichEditViewer.Left;
LGPLRefuse.Top := LGPLPage.Surface.ClientHeight - ScaleY(21);
LGPLRefuse.Width := LGPLPage.RichEditViewer.Width;
LGPLRefuse.Parent := LGPLPage.Surface;
LGPLRefuse.Caption := SetupMessage(msgLicenseNotAccepted);
// Set the states and event handlers
LGPLPage.OnActivate := #LGPLPageActivate;
LGPLAccept.OnClick := #LGPLAcceptClick;
LGPLRefuse.OnClick := #LGPLAcceptClick;
LGPLRefuse.Checked := true;
// Load the LGPL text into the new page
ExtractTemporaryFile('lgpl-3.0.txt');
LoadStringFromFile(ExpandConstant('{tmp}/lgpl-3.0.txt'), LGPLText);
LGPLPage.RichEditViewer.RTFText := LGPLText;
end;
procedure LGPLPageActivate(Sender: TWizardPage);
begin
WizardForm.NextButton.Enabled := LGPLAccept.Checked;
end;
procedure LGPLAcceptClick(Sender: TObject);
begin
WizardForm.NextButton.Enabled := LGPLAccept.Checked;
end;
[Files]
Source: {#Common}Setups\lgpl-3.0.txt; DestDir: {app}; Flags: ignoreversion
[CustomMessages]
LGPLHeader=Please read the following License Agreement. Some components are licensed under the GNU Lesser General Public License.

Inno Setup: How to change Messages at runtime?

I need to change Messages at runtime. I have a AfterInstall procedure that checks to see if a bat file was successful. If it is not, I want to change the value of ExitSetupMessage just before calling WizardForm.Close. I was hoping to do something like this english.ExitSetupMessage := 'THIS IS THE PART THAT DOES NOT WORK';. Code examples would be appreciated. Thank you.
[Languages]
Name: english; MessagesFile: compiler:Default.isl
[Files]
Source: {src}\test.bat; DestDir: {tmp}; AfterInstall: ValidateInstall
[Code]
procedure ValidateInstall();
var
ResultCode : Integer;
begin
if not Exec(ExpandConstant('{tmp}\test.bat'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
english.ExitSetupMessage := 'THIS IS THE PART THAT DOES NOT WORK';
WizardForm.Close;
end;
end;
I don't know of a way to change the messages at runtime.
However in the case you posted I know of a workaround. You would set your CustomState before calling WizardForm.Close
var
CustomState : Boolean;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
var
Msg : String;
Res : Integer;
begin
Confirm := False; // Don't show the default dialog.
// Chose which message the custom or default message.
if CustomState then
Msg := 'My Custom Close Message'
else
Msg := SetupMessage(msgExitSetupMessage);
//as the Question
Res := MsgBox(Msg, mbConfirmation,MB_OKCANCEL);
// If they press OK then Cancel the install
Cancel := (Res = IDOK);
end;
The side effect is you lose the Exit Setup? title of the dialog box.
You can use function ExitSetupMsgBox: Boolean; when you don't want to change the message
to keep the title around.
According to http://www.jrsoftware.org/ishelp/index.php?topic=scriptclasses
it should be
WizardForm.FinishedLabel.Caption := 'Desired text goes here';

Resources