Inno Setup unzip file from input user - inno-setup

I try to unzip in installation file which I download from my repository. I found this code:
How to get Inno Setup to unzip a file it installed (all as part of the one installation process)
But I need to input from user in custom page about version of application in the repository, download it and try unzip. How send to value from input to ExtractMe('{tmp}\INPUT FROM USER VERSION.zip', '{app}\');
begin
{Page for input Version}
UserPage := CreateInputQueryPage(wpWelcome,
'Number of Version', 'example : 1.8.20',
'Program will download your input');
UserPage.Add('Version:', False);
UserPage.Values[0] := GetPreviousData('Version', '1.8.20');
end;
{Called when the user clicks the Next button}
function NextButtonClick(CurPageID: Integer): Boolean;
var
Version: string;
FileURL: string;
begin
if CurPageID = wpReady then
begin
Version := UserPage.Values[0];
{Download}
FileURL := Format('http://127.0.0.1/repository/ia/ats-apps/ia-client.zip/%s/ia-client.zip-%0:s.zip', [Version]); <-- FROM HERE TO BELOW
idpAddFile(FileURL, ExpandConstant(Format('{tmp}\%s.zip', [Version])));
idpDownloadAfter(wpReady);
end;
Result := True;
end;
procedure unzip(src, target: AnsiString);
external 'unzip#files:unzipper.dll stdcall delayload';
procedure ExtractMe(src, target : AnsiString);
begin
unzip(ExpandConstant(src), ExpandConstant(target));
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
ExtractMe('{tmp}\INPUT FROM USER VERSION.zip', '{app}\'); <--HERE
end;
end;
Thanks for tip.

The same way as you are already using in the NextButtonClick: Read the UserPage.Values[0].
ExtractMe(Format('{tmp}\%s.zip', [UserPage.Values[0]]), '{app}\');

Related

Check installation path for spaces and special symbol in Inno Setup

I cannot find a solution for checking the user selected path to be without any spaces or special characters.
Can you help me?
You can check for space like this:
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
Dir: string;
Msg: string;
begin
Result := True;
if CurPageID = wpSelectDir then
begin
Dir := WizardForm.DirEdit.Text;
if Pos(' ', Dir) > 0 then
begin
Msg := 'The path cannot contain spaces';
if WizardSilent then Log(Msg)
else MsgBox(Msg, mbError, MB_OK);
Result := False;
end;
end;
end;
You may consider using SuppressibleMsgBox function:
What does it mean that message boxes are being suppressed in Inno Setup?

Download additional files based on contents of first download using IDP

Want to download files based on contents of first download using Inno Download Plugin (IDP). How to do that?
Here is my code
[Code]
procedure InitializeWizard();
var
line: string;
line2: string;
url: string;
appname: string;
begin
idpAddFile('http://download.website.com/files.txt', ExpandConstant('{tmp}\files.txt'));
idpDownloadAfter(wpReady);
TryGetFileLine(expandConstant('{tmp}\files.txt'), 0, line);
TryGetFileLine(expandConstant('{tmp}\files.txt'), 1, line2);
url := line;
appname := line2;
idpAddFile(url, ExpandConstant('{tmp}\'+appname));
idpDownloadAfter(wpReady);
end;
Here second file starts downloading before the first file finishes. So how to make it one after another?
Tell IDP to only download the list initially. Then wait for the download to finish (for that see Running a program after it is downloaded in Code section in Inno Setup) and based on the results, create new download list and restart the download.
var
ListDownloaded: Boolean;
procedure InitializeWizard();
begin
idpAddFile('http://www.example.com/files.txt', ExpandConstant('{tmp}\files.txt'));
idpDownloadAfter(wpReady);
ListDownloaded := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
Url, AppName: string;
begin
Result := True;
if CurPageID = IDPForm.Page.ID then
begin
if not ListDownloaded then
begin
TryGetFileLine(ExpandConstant('{tmp}\files.txt'), 0, Url);
TryGetFileLine(ExpandConstant('{tmp}\files.txt'), 1, AppName);
idpClearFiles;
idpAddFile(Url, ExpandConstant('{tmp}\' + AppName));
idpFormActivate(nil); { This restarts the download }
Result := False;
ListDownloaded := True;
end;
end;
end;

Inno Setup: how can I execute multiple files after downloading them? [duplicate]

How do I run an application I have downloaded over the Internet, in the code section using, and also wait for that application to finish running. I have, using InnoTools downloader, downloaded these two files and I want to, after the second one is done downloading to run that download, or jdk-8u111-windows-x64.exe, then continue the installation.
[Code] 
procedure InitializeWizard(); 
begin 
     ITD_Init;
     ITD_AddFile('http://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M13/bin/apache-tomcat-9.0.0.M13-windows-x64.zip', expandconstant('{tmp}\apache-tomcat-9.0.0.M13-windows-x64.zip'));
     ITD_DownloadAfter(1); 
     ITD_AddFile('http://files.downloadnow-1.com/s/software/15/62/36/39/jdk-8u111-windows-x64.exe?token=1479511171_b51e94edd4e002c94fd60a570a7dd270&fileName=jdk-8u111-windows-x64.exe',expandconstant('{tmp}\jdk-8u111-windows-x64.exe'));
     ITD_DownloadAfter(2);       
end;
Use other download plugin, not ITD (see below for reasons).
Inno Setup 6.1 supports downloads natively. See Inno Setup: Install file from Internet
If you are stuck with an older version of Inno Setup, use the Inno Download Plugin.
When you include idp.iss, it defines a global IDPForm structure. Its Page field is the TWizardPage, representing a download page. Use its ID in the NextButtonClick to run the downloaded file, once the download finishes (the "Next" button on the download page is "pressed" automatically):
#include <idp.iss>
[Code]
procedure InitializeWizard;
begin
idpAddFile(
'https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.0.M13/bin/' +
'apache-tomcat-9.0.0.M13-windows-x64.zip',
ExpandConstant('{tmp}\apache-tomcat-9.0.0.M13-windows-x64.zip'));
idpAddFile(
'https://www.example.com/jdk-8u111-windows-x64.exe',
ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe'));
idpDownloadAfter(wpSelectDir);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
FileName: string;
begin
if CurPageID = IDPForm.Page.ID then
begin
FileName := ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe');
Result := Exec(FileName, '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
if not Result then
begin
MsgBox('Cannot execute sub-installer', mbError, MB_OK);
end
else
begin
Result := (ResultCode = 0);
if not Result then
begin
MsgBox('Sub-installer failed', mbError, MB_OK);
end
end;
end
else
begin
Result := True;
end;
end;
There's also DwinsHs (Downloader for Inno Setup).
While you can implement the same using InnoTools Downloader, you should avoid it:
It's outdated and not maintained anymore;
Does not support Unicode Inno Setup (do not use Ansi Inno Setup for new projects);
Does not support HTTPS;
Its download page does not scale on high DPI.
Anyway, for completeness: the ITD_DownloadAfter returns TWizardPage, representing a download page. Use its ID in the NextButtonClick to run the downloaded file, once the download finishes (the "Next" button on the download page is "pressed" automatically):
var
DownloadPage: TWizardPage;
procedure InitializeWizard();
begin
ITD_Init;
ITD_AddFile(
'http://www.example.com/jdk-8u111-windows-x64.exe',
ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe'));
DownloadPage := ITD_DownloadAfter(wpSelectDir);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
begin
if CurPageID = DownloadPage.ID then
begin
Result :=
Exec(
ExpandConstant('{tmp}\jdk-8u111-windows-x64.exe'),
'', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
if not Result then
begin
MsgBox('Cannot execute sub-installer', mbError, MB_OK);
end
else
begin
Result := (ResultCode = 0);
if not Result then
begin
MsgBox('Sub-installer failed', mbError, MB_OK);
end
end;
end
else
begin
Result := True;
end;
end;

Goes to a site when setup is closed / finished / uninstalled

Inno Setup Compiler: How to auto start the default browser with given url? is not what I am wanting for. How / what code in Inno Setup when I want my setup.exe that if it's closed / finished / uninstalled, it will go to a certain site.
To open a web browser from a Pascal Script use a function like this:
procedure OpenBrowser(Url: string);
var
ErrorCode: Integer;
begin
ShellExec('open', Url, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;
To trigger it, when installer closes, you can use the CurStepChanged(ssDone) event:
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssDone then
begin
OpenBrowser('https://www.example.com/');
end;
end;
Similarly for an uninstaller, use the CurUninstallStepChanged(usDone) event:
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
if CurUninstallStep = usDone then
begin
OpenBrowser('https://www.example.com/');
end;
end;

Inno UninstallRun How To get global variable by executing

My target is to read a registry entry at [UninstallRun].
The issue is, if Inno Setup is running in an install process the Function GetRegistryVar() is called here ? It should be called when the UnInstall process is running. If I start the UnInstall process the Function GetRegistryVar() will not called here ? Only the CurUninstallStepChanged() and PGetRegistryVal(). So I can't receive my global variable gStrPrnName ?
[UninstallRun]
Filename: "{#dInst64bitDir}\{#dUnInstDrvExeName}"; Parameters: "-f {code:GetGlobalRegistryVar}"; WorkingDir: "{#dInst64bitDir}"; Flags: runhidden runascurrentuser;
[Code]
var
gStrPrnName: string;
function GetGlobalRegistryVar(Value: string): string;
begin
Result := gStrPrnName;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
case CurUninstallStep of
usUninstall:
begin
// ...insert code to perform pre-uninstall tasks here...
PGetRegistryVal(gStrPrnName);
end;
usPostUninstall:
begin
// ...insert code to perform post-uninstall tasks here...
end;
end;
end;
function PGetRegistryVal(Value: String): String;
var
strPrnName: string;
i: Integer;
begin
for i:=0 to 2 do
begin
if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\GetDevice_1', 'Name', strPrnName) then
Result := strPrnName;
if RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\GetDevice_2', 'Name', strPrnName) then
Result := strPrnName;
...
end;
end;
Has somebody a solution for this issue ?
Thanks

Resources