Choosing components to be installed with Inno Setup using a configuration file - installation

I want to program an installer that will install certain programs by selecting a user. Every user has defined assignments which program should be installed.
For now, you have to use the components section to configure the programs. But my goal is to configure it with a text file.
Example for text file could be like:
User1 User2 User3 User4
Program 1 x x x x
Program 2 x x
Program 3 x x
Here is my code:
[Types]
Name: "User1"; Description: "User 1"
Name: "User2"; Description: "User 2"
Name: "User3"; Description: "User 3"
Name: "User4"; Description: "User 4"
Name: "Custom"; Description: "Custom"
Name: "Random"; Description:"Random"; Flags: iscustom
[Components]
Name: "Select"; Description: "Alle auswählen:"; Types: User1 User2 User3 User4
Name: "Select\Program_1"; Description: "Program_1"; Types: User1 User2 User3 User4
Name: "Select\Program_2"; Description: "Program_2"; Types: User2 User4
Name: "Select\Program_3"; Description: "Program_3"; Types: User1 User3
[Files]
Source: "TEST \Software\x64\Program_1"; DestDir: "{app}\Program_1"; \
Flags: ignoreversion recursesubdirs; Components: Select\Program_1;
Source: "TEST \Software\x64\Program_2"; DestDir: "{app}\Program_2"; \
Flags: ignoreversion recursesubdirs; Components: Select\Program_2;
Source: "TEST \Software\x64\Program_3"; DestDir: "{app}\Program_3"; \
Flags: ignoreversion recursesubdirs; Components: Select\Program_3;
[Code]
var
TypesPage: TWizardPage;
User1_Button: TNewRadioButton;
User2_Button: TNewRadioButton;
User4_Button: TNewRadioButton;
User3_Button: TNewRadioButton;
Custom_Button: TNewRadioButton;
procedure InitializeWizard();
begin
{ Create custom "types" page }
TypesPage := CreateInputOptionPage(wpSelectDir,
'Select User', '' ,
'Please select the right User',true,false);
User1_Button := TNewRadioButton.Create(TypesPage);
User1_Button.Parent := TypesPage.Surface;
User1_Button.Caption := 'User 1';
User1_Button.Top := 50;
User1_Button.Height := ScaleY(User1_Button.Height);
User1_Button.Checked := (WizardForm.TypesCombo.ItemIndex = 0);
User2_Button := TNewRadioButton.Create(TypesPage);
User2_Button.Parent := TypesPage.Surface;
User2_Button.Caption := 'User 2';
User2_Button.Height := ScaleY(User2_Button.Height);
User2_Button.Top := User1_Button.Top + User1_Button.Height + ScaleY(16);
User2_Button.Checked := (WizardForm.TypesCombo.ItemIndex = 1);
User3_Button := TNewRadioButton.Create(TypesPage);
User3_Button.Parent := TypesPage.Surface;
User3_Button.Caption := 'User 3';
User3_Button.Height := ScaleY(User3_Button.Height);
User3_Button.Top := User2_Button.Top + User2_Button.Height + ScaleY(16);
User3_Button.Checked := (WizardForm.TypesCombo.ItemIndex = 2);
User 4_Button := TNewRadioButton.Create(TypesPage);
User 4_Button.Parent := TypesPage.Surface;
User 4_Button.Caption := 'User 4';
User 4_Button.Height := ScaleY(User4_Button.Height);
User 4_Button.Top := User3_Button.Top + User3_Button.Height + ScaleY(16);
User 4_Button.Checked := (WizardForm.TypesCombo.ItemIndex = 3);
Custom_Button := TNewRadioButton.Create(TypesPage);
Custom_Button.Parent := TypesPage.Surface;
Custom_Button.Caption := 'Custom';
Custom_Button.width := 200;
Custom_Button.Height := ScaleY(Custom_Button.Height);
Custom_Button.Top := User4_Button.Top + User4_Button.Height + ScaleY(16);
Custom_Button.Checked := (WizardForm.TypesCombo.ItemIndex = 4);
WizardForm.TypesCombo.Visible := False; { Dropdown List removed }
WizardForm.IncTopDecHeight(WizardForm.ComponentsList,
-(WizardForm.ComponentsList.Top-WizardForm.TypesCombo.Top));
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = TypesPage.ID then
begin
if User1_Button.Checked then WizardForm.TypesCombo.ItemIndex :=0
else
if User2_Button.Checked then WizardForm.TypesCombo.ItemIndex := 1
else
if User3_Button.Checked then WizardForm.TypesCombo.ItemIndex := 2
else
if User4_Button.Checked then WizardForm.TypesCombo.ItemIndex := 3
else
if Custom_Button.Checked then WizardForm.TypesCombo.ItemIndex := 4;
WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo);
end;
Result:= true;
end;

As you do not seem to care about the configuration file format, let's pick INI file, as Inno Setup has functions to parse it:
[Users]
user1=Program1,Program3
user2=Program1,Program2
user3=Program1,Program3
user4=Program1,Program2
Then the following script will do:
[Types]
Name: "user1"; Description: "User 1"
Name: "user2"; Description: "User 2"
Name: "user3"; Description: "User 3"
Name: "user4"; Description: "User 4"
[Files]
Source: "TEST \Software\x64\Program_1"; DestDir: "{app}\Program_1"; \
Flags: ignoreversion recursesubdirs; Check: ShouldInstallProgram('Program1')
Source: "TEST \Software\x64\Program_2"; DestDir: "{app}\Program_2"; \
Flags: ignoreversion recursesubdirs; Check: ShouldInstallProgram('Program2')
Source: "TEST \Software\x64\Program_3"; DestDir: "{app}\Program_3"; \
Flags: ignoreversion recursesubdirs; Check: ShouldInstallProgram('Program3')
[Code]
function ShouldInstallProgram(ProgramName: string): Boolean;
var
UserName: string;
ProgramsStr: string;
Programs: TStringList;
begin
UserName := WizardSetupType(False);
ProgramsStr :=
GetIniString('Users', UserName, '', ExpandConstant('{src}\UserPrograms.ini'));
Programs := TStringList.Create;
Programs.CommaText := ProgramsStr;
Result := (Programs.IndexOf(ProgramName) >= 0);
Programs.Free;
end;
Type names must be lowercase for this to work. And casing of program names matter.
As the code now actually does not use the [Types] at all, you can replace the WizardSetupType with direct check to your custom page selection. And you can remove the redundant [Types] section and your NextButtonClick event function.

Related

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

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

I have duplicated InitializeSetup in INNO SETUP how can i solve it?

Hello i am trying to make an installer using INNO SETUP, when i started to use ISSkin Code Inno setup send me an error mesage DUPLICATE IDENTIFIER 'INITIALIZESETUP' I would like to know what i have to change to my code to make it work.
I was reading at internet and i found a program called IS Script Joiner, i used it but it doesnt work.
Here is my Inno Code:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Myprogram"
#define MyAppVersion "2.8"
#define MyAppPublisher "Myprogram"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "program.exe"
#define ISSI_WizardSmallBitmapImage "wpBanner.bmp"
#define ISSI_WizardSmallBitmapImage_x 495
#define ISSI_WizardSmallBitmapImage_Align
#define ISSI_IncludePath "C:\ISSI"
#include ISSI_IncludePath+"\_issi.isi"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{2A8CE1DB-2FDB-4CAA-8A2C-0FE3DB8A500D}
AppName=Myprogram
AppVersion=2.8
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher=Myprogram
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\Myprogram
DefaultGroupName={#MyAppName}
LicenseFile=C:\Libraries\EULA.rtf
OutputDir=C:\Users\Hans Lopez\INNO SETUPS
OutputBaseFilename=programoutput
SetupIconFile=C:\Libraries\Icon.ico
Compression=lzma/Max
SolidCompression=true
WizardImageFile=C:\InstallMlockPackage\Setupbanner.bmp
AppVerName=2.8
DirExistsWarning=yes
VersionInfoProductName=Myprogram
VersionInfoProductVersion=2.8
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
[Dirs]
Name: "{app}" ; Permissions: everyone-full
Name: {sd}\myprogramfolder; Permissions: everyone-full;
[Code]
//===================================================================Verify if Installed===============================================================================
function GetUninstallString: string;
var
sUnInstPath: string;
sUnInstallString: String;
begin
Result := '';
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
function IsUpgrade: Boolean;
begin
Result := (GetUninstallString() <> '');
end;
function InitializeSetup: Boolean;
var
V: Integer;
iResultCode: Integer;
sUnInstallString: string;
begin
Result := True; // in case when no previous version is found
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\ {2A8CE1DB-2FDB-4CAA-8A2C-0FE2DB8A500D}_is1', 'UninstallString') then //Your App GUID/ID
begin
V := MsgBox(ExpandConstant('Myprogram is Already installed, Do you want to continue?'), mbInformation, MB_YESNO); //Custom Message if App installed
if V = IDYES then
begin
sUnInstallString := GetUninstallString();
sUnInstallString := RemoveQuotes(sUnInstallString);
Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else
Result := False; //when older version present and not uninstalled
end;
end;
//====================================================================Unistall and Delete Everything==================================================================
procedure DeleteBitmaps(ADirName: string);
var
FindRec: TFindRec;
begin
if FindFirst(ADirName + '\*.*', FindRec) then begin
try
repeat
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then begin
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
DeleteBitmaps(ADirName + '\' + FindRec.Name);
RemoveDir(ADirName + '\' + FindRec.Name);
end;
end else if Pos('.bmp', AnsiLowerCase(FindRec.Name)) > 0 then
DeleteFile(ADirName + '\' + FindRec.Name);
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usUninstall then begin
if MsgBox('Do you want to delete all data files?', mbConfirmation,
MB_YESNO) = IDYES
then begin
DeleteBitmaps(ExpandConstant('{app}'));
end;
end;
end;
//===========================================================ISSKinCODE=============================================================================
// Importing LoadSkin API from ISSkin.DLL
procedure LoadSkin(lpszPath: String; lpszIniFileName: String);
external 'LoadSkin#files:isskin.dll stdcall';
// Importing UnloadSkin API from ISSkin.DLL
procedure UnloadSkin();
external 'UnloadSkin#files:isskin.dll stdcall';
// Importing ShowWindow Windows API from User32.DLL
function ShowWindow(hWnd: Integer; uType: Integer): Integer;
external 'ShowWindow#user32.dll stdcall';
function InitializeSetup(): Boolean;
begin
ExtractTemporaryFile('iTunesB.msstyles');
LoadSkin(ExpandConstant('{tmp}\iTunesB.msstyles'), '');
Result := True;
end;
procedure DeinitializeSetup();
begin
// Hide Window before unloading skin so user does not get
// a glimpse of an unskinned window before it is closed.
ShowWindow(StrToInt(ExpandConstant('{wizardhwnd}')), 0);
UnloadSkin();
end;
/////////////////////////////////////////////////////////////ENDCODE/////////////////////////////////////////////////////////////////////////////////////////////////
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: " {cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: " {cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
[Files]
Source: "C:\My program\program.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Program Files\C:\My program\*"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\programfolder\*"; DestDir: "{sd}\Myprogramfolder"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: ISSkin.dll; DestDir: {app}; Flags: dontcopy
Source: "C:\InstallMlockPackage\ISSkin\iTunesB\iTunesB\iTunesB.msstyles"; DestDir: " {tmp}"; Flags: dontcopy
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: " {app}\icon.ico" ;
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"; IconFilename: "{app}\icon.ico" ;
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"; IconFilename: "{app}\icon.ico" ;
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon; IconFilename: "{app}\icon.ico" ;
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon; IconFilename: "{app}\icon.ico" ;
Name: {group}\Uninstall =ISSkin; Filename: {app}\unins000.exe
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram, {#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
Thank You very Much for Your Help
Relocate the two calls to the ISSkin DLL from where they are now (above the second InitializeSetup) to just above the first InitializeSetup declaration.
// Importing LoadSkin API from ISSkin.DLL
procedure LoadSkin(lpszPath: String; lpszIniFileName: String);
external 'LoadSkin#files:isskin.dll stdcall';
// Importing UnloadSkin API from ISSkin.DLL
procedure UnloadSkin();
external 'UnloadSkin#files:isskin.dll stdcall';
Change the first InitializeSetup code to include the calls to extract and load the skin (from the second InitializeSetup).
function InitializeSetup: Boolean;
var
V: Integer;
iResultCode: Integer;
sUnInstallString: string;
begin
// These two lines moved from second InitializeSetup declaration before it
// was removed.
ExtractTemporaryFile('iTunesB.msstyles');
LoadSkin(ExpandConstant('{tmp}\iTunesB.msstyles'), '');
Result := True; // in case when no previous version is found
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\ {2A8CE1DB-2FDB-4CAA-8A2C-0FE2DB8A500D}_is1', 'UninstallString') then //Your App GUID/ID
begin
V := MsgBox(ExpandConstant('Myprogram is Already installed, Do you want to continue?'), mbInformation, MB_YESNO); //Custom Message if App installed
if V = IDYES then
begin
sUnInstallString := GetUninstallString();
sUnInstallString := RemoveQuotes(sUnInstallString);
Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else
Result := False; //when older version present and not uninstalled
end;
end;
Remove the second InitializeSetup code entirely.

How to get installation path during uninstall?

My idea is to offer the user the choice of installing the application either in {localappdata} or {commonappdata}, and that part works fine. However, I'm using custom Inno Setup skinning support, which requires a couple functions to get loaded during installation/uninstallation.
I have a DefaultAppDataFolder(): String function which returns the folder that the user chose (either common or local appdata one), and it works fine during installation. However, when I try to uninstall the app, it throws following error right upon execution:
Script error: Could not call proc
You can see that in the DefaultAppDataFolder() function I'm getting the uninstall directory in a bit shady way, extracting the file directory twice from the {UninstallExe} constant, maybe there is a better way to retrieve this?
Here is my script:
#define ApplicationName "MyApp"
#define ApplicationExe "app.exe"
#define ApplicationInstanceMutex "APPMUTEX"
#define InstallerFilename "install_app"
#define SkinName "Carbon.vsf"
[Setup]
AppName={#ApplicationName}
AppVerName={#ApplicationName}
DefaultDirName={code:DefaultAppDataFolder}
DefaultGroupName={#ApplicationName}
UninstallFilesDir={code:DefaultAppDataFolder}\uninstall
UninstallDisplayName={#ApplicationName}
Compression=lzma2
SolidCompression=yes
OutputDir=.\
DisableDirPage=yes
OutputBaseFilename={#InstallerFilename}
UninstallDisplayIcon={code:DefaultAppDataFolder}\{#ApplicationExe}
DisableProgramGroupPage=yes
AppMutex={#ApplicationInstanceMutex}
WizardImageFile=installer_images\installer-1.bmp
WizardSmallImageFile=installer_images\installer-2.bmp
[Files]
Source: "skins\VclStylesInno.dll"; DestDir: "{code:DefaultAppDataFolder}"; Flags: uninsneveruninstall ignoreversion
Source: "skins\{#SkinName}"; DestDir: "{code:DefaultAppDataFolder}"; Flags: ignoreversion
Source: "root_files\*.*"; DestDir: "{code:DefaultAppDataFolder}"; Flags: ignoreversion
Source: "client_files\*.*"; DestDir: "{code:DefaultAppDataFolder}"; Flags: ignoreversion
Source: "ssl_libs\*.*"; DestDir: "{code:DefaultAppDataFolder}"; Flags: ignoreversion
[Icons]
Name: "{group}\{#ApplicationName}"; Filename: "{code:DefaultAppDataFolder}\{#ApplicationExe}"; WorkingDir: "{code:DefaultAppDataFolder}"
Name: "{group}\Uninstall"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#ApplicationName}"; Filename: "{code:DefaultAppDataFolder}\{#ApplicationExe}"; Tasks: desktopicon
[Run]
Filename: "{code:DefaultAppDataFolder}\{#ApplicationExe}"; Description: "Launch {#ApplicationName}"; Flags: postinstall nowait runascurrentuser
[Tasks]
Name: commondir; Description: "&All users"; GroupDescription: "Install For:"; Flags: exclusive
Name: localdir; Description: "&Current user"; GroupDescription: "Install For:"; Flags: exclusive unchecked
Name: desktopicon; Description: "Create a &desktop icon"
[Code]
procedure LoadVCLStyleS(VClStyleFile: String); external 'LoadVCLStyleW#files:VclStylesInno.dll stdcall setuponly';
procedure UnLoadVCLStylesS; external 'UnLoadVCLStyles#files:VclStylesInno.dll stdcall setuponly';
procedure LoadVCLStyleU(VClStyleFile: String); external 'LoadVCLStyleW#{code:DefaultAppDataFolder}\VclStylesInno.dll stdcall uninstallonly';
procedure UnLoadVCLStylesU; external 'UnLoadVCLStyles#{code:DefaultAppDataFolder}\VclStylesInno.dll stdcall uninstallonly';
var
ApplicationUninstalled: Boolean;
WizardInitialized: Boolean;
function InitializeSetup(): Boolean;
var
C1: Integer;
begin
ExtractTemporaryFile('{#SkinName}');
LoadVCLStyleS(ExpandConstant('{tmp}\{#SkinName}'));
result := TRUE;
end;
procedure InitializeWizard();
begin
WizardInitialized := TRUE;
end;
procedure DeinitializeSetup();
begin
UnLoadVCLStylesS;
end;
function InitializeUninstall(): Boolean;
begin
LoadVCLStyleU(ExpandConstant('{code:DefaultAppDataFolder}\{#SkinName}'));
result := TRUE;
end;
procedure InitializeUninstallProgressForm();
begin
ApplicationUninstalled := TRUE;
end;
procedure DeinitializeUninstall();
begin
UnLoadVCLStylesU;
UnloadDLL(ExpandConstant('{code:DefaultAppDataFolder}\VclStylesInno.dll'));
if ApplicationUninstalled then
begin
DeleteFile(ExpandConstant('{code:DefaultAppDataFolder}\VclStylesInno.dll'));
RemoveDir(ExpandConstant('{code:DefaultAppDataFolder}'));
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
mres: integer;
begin
case CurUninstallStep of
usPostUninstall: begin
mres := MsgBox('Do you want to delete user data?', mbConfirmation, MB_YESNO or MB_DEFBUTTON2)
if mres = IDYES then
begin
DelTree(ExpandConstant('{localappdata}\{#ApplicationName}'), TRUE, TRUE, TRUE);
DelTree(ExpandConstant('{userappdata}\{#ApplicationName}'), TRUE, TRUE, TRUE);
end;
end;
end;
end;
function DefaultAppDataFolder(Param: String): String;
begin
if IsUninstaller then
result := ExtractFileDir(ExtractFileDir(ExpandConstant('{uninstallexe}')))
else
if (WizardInitialized) and
(IsTaskSelected('localdir')) then
result := ExpandConstant('{localappdata}') + '\Programs\{#ApplicationName}'
else
result := ExpandConstant('{commonappdata}') + '\Programs\{#ApplicationName}';
end;
The error you got is not related to the uninstaller; you can narrow the problem down to this:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName=My Program
[Code]
procedure DoSomething;
external 'DoSomething#{code:GetLibPath}\MyLib.dll stdcall setuponly';
function GetLibPath(Value: string): string;
begin
Result := 'C:\ValidPathToLib';
end;
From the above script it seems that you cannot use scripted constants for imported DLL file names. And even delayed loading didn't workaround this limit. But for your case you can use just {app} path since your library is actually there (if I get your intention right):
...
procedure LoadVCLStyleU(VClStyleFile: string);
external 'LoadVCLStyleW#{app}\VclStylesInno.dll stdcall uninstallonly';
procedure UnLoadVCLStylesU;
external 'UnLoadVCLStyles#{app}\VclStylesInno.dll stdcall uninstallonly';
...

Get radio button value [INNO SETUP]

I am trying to create a new window at Inno Setup. In this window :
There should be 5 radio button
User must select only one of this choice
When the user click the next button I have to get and save the value of the radio button (on somewhere ?) and give this value to the batch file(which will run) with parameter
I think I should do some action in the function of NextButtonClick but I cannot figure out how can I reach the value of radio buttons and save.
Any help is appreciated.
The Screenshot of that window :
So now on, my code is like below :
#define MyAppName "CDV Client"
#define MyAppVersion "3.6.1 build 2"
#define MyAppPublisher " CDV"
#define MyAppURL "https://example-cm-1"
#define MyAppExeName "example.exe"
[Setup]
AlwaysUsePersonalGroup=true
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppID={{7C9325AD-6818-42CA-839E}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={code:DriveLetter}:\Tool\CDVClient
DefaultGroupName=Ser
AllowNoIcons=true
OutputBaseFilename=CDVClient_setup
Compression=lzma/Max
SolidCompression=true
SetupLogging=true
PrivilegesRequired=none
DirExistsWarning=yes
AlwaysShowDirOnReadyPage=true
AlwaysShowGroupOnReadyPage=true
[Code]
function DriveLetter(Param: String): String;
begin
if DirExists('d:\') then
Result := 'D'
else if DirExists('e:\') then
Result := 'E'
else
Result := 'C'
end;
var
CDVRadioButton: TNewRadioButton;
ISCRadioButton: TNewRadioButton;
TestRadioButton: TNewRadioButton;
Test2RadioButton: TNewRadioButton;
Test3RadioButton: TNewRadioButton;
lblBlobFileFolder: TLabel;
procedure InitializeWizard;
var
LabelFolder: TLabel;
MainPage: TWizardPage;
FolderToInstall: TNewEdit;
begin
MainPage := CreateCustomPage(wpWelcome, 'Deneme', 'Deneme2');
LabelFolder := TLabel.Create(MainPage);
LabelFolder.Parent := WizardForm;
LabelFolder.Top := 168;
LabelFolder.Left := 6;
LabelFolder.Caption := 'Directory:'
lblBlobFileFolder := TLabel.Create(MainPage);
lblBlobFileFolder.Parent := MainPage.Surface;
lblBlobFileFolder.Top := LabelFolder.Top - 160;
lblBlobFileFolder.Left := LabelFolder.Left;
lblBlobFileFolder.Width := LabelFolder.Width * 5;
lblBlobFileFolder.Caption := 'Please select the convenient extension ';
CDVRadioButton := TNewRadioButton.Create(MainPage);
CDVRadioButton.Parent := MainPage.Surface;
CDVRadioButton.Top := LabelFolder.Top - 120;
CDVRadioButton.Left := LabelFolder.Left;
CDVRadioButton.Width := LabelFolder.Width * 5;
CDVRadioButton.Caption := 'CDV';
CDVRadioButton.Checked := true;
ISCRadioButton := TNewRadioButton.Create(MainPage);
ISCRadioButton.Parent := MainPage.Surface;
ISCRadioButton.Top := LabelFolder.Top - 80;
ISCRadioButton.Left := LabelFolder.Left;
ISCRadioButton.Width := LabelFolder.Width * 5;
ISCRadioButton.Caption := 'ISC';
TestRadioButton := TNewRadioButton.Create(MainPage);
TestRadioButton.Parent := MainPage.Surface;
TestRadioButton.Top := LabelFolder.Top - 40;
TestRadioButton.Left := LabelFolder.Left;
TestRadioButton.Width := LabelFolder.Width * 5;
TestRadioButton.Caption := 'Test1';
Test2RadioButton := TNewRadioButton.Create(MainPage);
Test2RadioButton.Parent := MainPage.Surface;
Test2RadioButton.Top := LabelFolder.Top ;
Test2RadioButton.Left := LabelFolder.Left;
Test2RadioButton.Width := LabelFolder.Width * 5;
Test2RadioButton.Caption := 'Test2';
Test3RadioButton := TNewRadioButton.Create(MainPage);
Test3RadioButton.Parent := MainPage.Surface;
Test3RadioButton.Top := LabelFolder.Top + 40;
Test3RadioButton.Left := LabelFolder.Left;
Test3RadioButton.Width := LabelFolder.Width * 5;
Test3RadioButton.Caption := 'Test3';
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
// I should do something in here but what ? :/
end;
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; OnlyBelowVersion: 0,6.1
[Files]
; add recursesubdirs
Source: "C:\Program Files\Inno Setup 5\Examples\batu.bat"; DestDir: "{app}"; Flags: overwritereadonly recursesubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{userdesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, "&", "&&")}}"; Flags: nowait postinstall skipifsilent
You can check the 'Checked' property of the radio buttons to see which one is selected:
if (CDVRadioButton.Checked) then
begin
Do stuff...
end
else if (ISCRadioButton.Checked) then
begin
Do some other stuff...
end;
HTH

Radiobuttons with InnoSetup : Define files that will be installed or not

With a single executable file generated with InnoSetup (with "IconMain.ico") and a single uninstall(with a different icon "IconUninst.ico"), I would like to install some files in drive "C" and "K". The user will not be allowed to change drive paths/names, as :
STANDART RADIOBUTTON -
Full installation. Files that will be installed in drive "C:" AND "K:"
- Game.exe --> DRIVE C:\games
- Mapping.exe --> DRIVE C:\Mapping
- Pics.dll --> DRIVE C:\Pics
- AAA.dll --> DRIVE K:\Sounds
- BBB.obj --> DRIVE K:\Sounds
'
ADVANCED RADIONBUTTON -
Partial installation.
The only files that will be installed. (IF user agrees to continue)
- AAA.dll --> DRIVE K:\Sounds
- BBB.obj --> DRIVE K:\Sounds
How can I accomplish that?
Thank you !
To conditionally install a certain file you need to use the Check parameter. You need to return True to the expression or function to install the item, False to skip. The example to your previous assignment is shown in the reference page I've linked in the previous sentence.
So to combine it with custom installation type radio buttons you've mentioned, you just need to make a function that will be assigned to the check and that will return its result depending on selected radio button.
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Files]
; these two items will be installed always
Source: "AAA.dll"; DestDir: "K:\Sounds"
Source: "BBB.obj"; DestDir: "K:\Sounds"
; these three items will be installed only when the IsFullInstallation
; function returns True, what will depend on the selected radio button
Source: "Game.exe"; DestDir: "C:\Games"; Check: IsFullInstallation;
Source: "Mapping.exe"; DestDir: "C:\Mapping"; Check: IsFullInstallation;
Source: "Pics.dll"; DestDir: "C:\Pics"; Check: IsFullInstallation;
[Code]
const
FullDescText =
'Full installation. Files will be installed on drives "C:" and "K:"';
PartDescText =
'Partial installation. Files will be installed on drives "C:" and "K:"';
var
FullRadioButton: TNewRadioButton;
PartRadioButton: TNewRadioButton;
procedure InitializeWizard;
var
CustomPage: TWizardPage;
FullDescLabel: TLabel;
PartDescLabel: TLabel;
begin
CustomPage := CreateCustomPage(wpWelcome, 'Installation type', '');
FullRadioButton := TNewRadioButton.Create(WizardForm);
FullRadioButton.Parent := CustomPage.Surface;
FullRadioButton.Checked := True;
FullRadioButton.Top := 16;
FullRadioButton.Width := CustomPage.SurfaceWidth;
FullRadioButton.Font.Style := [fsBold];
FullRadioButton.Font.Size := 9;
FullRadioButton.Caption := 'Full Installation'
FullDescLabel := TLabel.Create(WizardForm);
FullDescLabel.Parent := CustomPage.Surface;
FullDescLabel.Left := 8;
FullDescLabel.Top := FullRadioButton.Top + FullRadioButton.Height + 8;
FullDescLabel.Width := CustomPage.SurfaceWidth;
FullDescLabel.Height := 40;
FullDescLabel.AutoSize := False;
FullDescLabel.Wordwrap := True;
FullDescLabel.Caption := FullDescText;
PartRadioButton := TNewRadioButton.Create(WizardForm);
PartRadioButton.Parent := CustomPage.Surface;
PartRadioButton.Top := FullDescLabel.Top + FullDescLabel.Height + 16;
PartRadioButton.Width := CustomPage.SurfaceWidth;
PartRadioButton.Font.Style := [fsBold];
PartRadioButton.Font.Size := 9;
PartRadioButton.Caption := 'Partial Installation'
PartDescLabel := TLabel.Create(WizardForm);
PartDescLabel.Parent := CustomPage.Surface;
PartDescLabel.Left := 8;
PartDescLabel.Top := PartRadioButton.Top + PartRadioButton.Height + 8;
PartDescLabel.Width := CustomPage.SurfaceWidth;
PartDescLabel.Height := 40;
PartDescLabel.AutoSize := False;
PartDescLabel.Wordwrap := True;
PartDescLabel.Caption := PartDescText;
end;
function IsFullInstallation: Boolean;
begin
Result := FullRadioButton.Checked;
end;
The easiest way to make conditional installations is to use [Types] and [Components].
[Types]
Name: standard; Description: Standard
Name: partial; Description: Partial
[Components]
Name: game; Description: Full game install; Types: standard
Name: sounds; Description: Sound files; Types: standard partial
[Files]
...; Components: game
...; Components: sounds

Resources