InnoSetup : Problem with file check function - inno-setup

I try to make a setup wizard with InnoSetup software to deploy easily my program but I encounter currently a problem with my script.
I am used to make basic setup wizard but now I have to implement a new functionality whose :
I want to check if a file exist on the computer to not overwrite it.
I made like this (in the [files] section):
[Files]
Source: "{#MyAppExeFile}"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#MyAppSrcFolder}*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#MyAppSrcFolder}FileFolder\testFile.py"; DestDir: "D:\Users\{username}\myFolderTest\"; Flags: ignoreversion recursesubdirs createallsubdirs;Check: needInstallFile(ExpandConstant('{username}'))
And i added this following [code] section:
[code]
function needInstallFile(user : string) : Boolean;
begin
if IsTaskSelected('initFile') then begin
if FileExists('D:\Users\' + user + '\myFolderTest\testFile.py') then begin
MsgBox('The file already exist', mbInformation, MB_OK);
Result:=False;
exit;
end else begin
Result:=True;
exit;
end;
end;
end;
When i compile my code, it's work but if the file already exist, i have three popup (and not just one like i would want to have). I DON'T understand despite my researches on Internet.
If you have a lead to help me, I'm interested because i'm stuck.
Thank you in advance for your help.
PS : Sorry for my English, i am unfortunatly a french guy.
Thomas

Related

Inno Setup - Avoid displaying filenames of sub-installers

I am trying to use the idea from Inno Setup - How to hide certain filenames while installing? (FilenameLabel)
The only sure solution is to avoid installing the files, you do not want to show, using the [Files] section. Install them using a code instead. Use the ExtractTemporaryFile and FileCopy functions
But the files that I want to hide are using in the [Run] Section:
[Files]
Source: "_Redist\DXWebSetup.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Run]
Filename: "{tmp}\DXWebSetup.exe"; Components: DirectX; StatusMsg: "Installing DirectX..."; \
BeforeInstall: StartWaitingForDirectXWindow; AfterInstall: StopWaitingForDirectXWindow
How to hide (while installing, in filenamelabel) using [Files] section, ExtractTemporaryFile and FileCopy functions?
The easiest is to give up on the standard [Files] and [Run] sections and code everything on your own in the CurStepChanged event fuction:
[Files]
Source: "dxwebsetup.exe"; Flags: dontcopy
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
ProgressPage: TOutputProgressWizardPage;
ResultCode: Integer;
begin
if CurStep = ssInstall then { or maybe ssPostInstall }
begin
if IsComponentSelected('DirectX') then
begin
ProgressPage := CreateOutputProgressPage('Installing prerequsities', '');
ProgressPage.SetText('Installing DirectX...', '');
ProgressPage.Show;
try
ExtractTemporaryFile('dxwebsetup.exe');
StartWaitingForDirectXWindow;
Exec(ExpandConstant('{tmp}\dxwebsetup.exe'), '', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode);
finally
StopWaitingForDirectXWindow;
ProgressPage.Hide;
end;
end;
end;
end;
This even gives you a chance to check for results of the sub-installer. And you can e.g. prevent the installation from continuing, when the sub-installer fails or is cancelled.
Then it's easier to use the PrepareToInstall instead of the CurStepChanged.
Another option is to display a custom label, while extracting the sub-installer.
See Inno Setup - How to create a personalized FilenameLabel with the names I want?

Copying hidden files in Inno Setup

How to use copy hidden external files in Inno Setup? Not to make a file hidden, but to work with hidden files. Because for now: the hidden files are being ignored
Any help? Thanks )
[Files]
Source: "{src}\folder\*"; DestDir: "{app}"; \
Flags: skipifsourcedoesntexist external ignoreversion recursesubdirs createallsubdirs;
When you select files in [Files] section entry using a wildcard, Inno Setup installer explicitly skips hidden files.
You cannot do anything about it.
See RecurseExternalCopyFiles function in Projects\Install.pas, particularly this part:
if SourceIsWildcard then begin
if FindData.dwFileAttributes and FILE_ATTRIBUTE_HIDDEN <> 0 then
Continue; { <-- Skip hidden files, comment by #MartinPrikryl }
FileName := FindData.cFileName;
end
else
FileName := SearchWildcard; { use the case specified in the script }
(This is for external files, as that's what you use. But for compile-time files, it's the same. See BuildFileList in Compile.pas).
All you can do, is to implement the installation in [Code] script yourself, instead of using the [Files] section.
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssInstall then
begin
Log('Installing files');
DirectoryCopy(ExpandConstant('{src}\folder'), ExpandConstant('{app}'));
end;
end;
For implementation of DirectoryCopy, see my answer to question Inno Setup: copy folder, subfolders and files recursively in Code section.
For compile-time files (without external flag), you can generate list of [Files] entries using a preprocessor function FindFirst.
the answer is You CAN
make windows display hidden files just for you to be able to see them
with your files hidden as you want them inside the folder.
when adding source folder and files step just add the folder (this wildcard *) normally, Inno setup won't add the hidden files. so add them separately.
after you finsih all steps don't run the script and edit the code..
go to [Files] section:
[Files]
Source: "H:\tmp\sweetInstaller\installer.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "H:\tmp\sweetInstaller\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "H:\tmp\sweetInstaller\hidden_file1.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "H:\tmp\sweetInstaller\hidden_file2.bat"; DestDir: "{app}"; Flags: ignoreversion
AND insert Attribs: hidden; next to files you wish to hide just before Flags:
[Files]
Source: "H:\tmp\sweetInstaller\installer.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "H:\tmp\sweetInstaller\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "H:\tmp\sweetInstaller\hidden_file1.txt"; DestDir: "{app}"; Attribs: hidden; Flags: ignoreversion
Source: "H:\tmp\sweetInstaller\hidden_file2.bat"; DestDir: "{app}"; Attribs: hidden; Flags: ignoreversion
then you can run the script from the little green play button at the top bar to compile. and you're done ;)

Inno Setup: Asking for directory page if a task checked

Under the task section I have
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; \
GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "installFolder"; Description: "Install project folder."; \
GroupDescription:" folder";
and in the Files section is this particular folder
Source: "C:\\Output\LEA\*.*"; DestDir: {code:GetDataDir}; \
Flags: createallsubdirs recursesubdirs ignoreversion;
My aim is to test the for the checked button and then have a window to ask for the directory to install the folder to.
if WizardForm.TasksList.Checked[3] then
GetDataDir;
Can this be done without the need to create pages or the one page to get the directory?
Also, is this a good way to handle extra files that are optional and will be installed to a different location than the default {app} location?
The confusing part for me thus far is when it's all compiled, the GetDataDir is being called before the page to select Tasks. So I choose my directory and then I'm asked whether I want to install it or not. I don't know how to go about getting the GetDataDir to occur afterwards.
The wizard model in Inno Setup means you should always create the wizard pages, but you can skip the ones that don't need to be shown.
This can be done in the ShouldSkipPage() event function by calling IsTaskSelected():
function ShouldSkipPage(PageID: Integer): Boolean;
begin
if (PageID = InstallFolderPage.ID) and not IsTaskSelected('installFolder') then
Result := True
else
Result := False
end;
In this case, with only a single check, it can be shortened to:
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := (PageID = InstallFolderPage.ID) and not IsTaskSelected('installFolder')
end;
As TLama said, you don't need to do anything special in the {code:...} functions, just return the appropriate value directly.
You simply need to add '; Tasks: installFolder' at the end of your Source... line, then it won't be called unless the task as been selected.
Source: "C:\\Output\LEA\*.*"; DestDir: {code:GetDataDir}; Flags: createallsubdirs recursesubdirs ignoreversion; Tasks: installFolder

Inno Setup - Transparent Splash Screen

I have a problem and I need your help..I want to find a differente way to put a transparent splash screen or the correction of my code. The code here works... but there is a problem, some people get an error at the end of the installation.
This is how look the error at the end of the installation
I check another lines in my code and I found that the problem was the code of the splash screen, if I delete it the installer works perfect, I see that what I need is a procedure DeinitializeSetup(); but I don't know how tu put it in the splash screen section, I get this kind of error if I delete the procedure DeinitializeSetup(); in another codes, like skin, logo, etc.. the files that goes to temp folder of windows... then what I need is the procedure DeinitializeSetup(); in the splash screen code to solve this... :( here is the dll file for anyone to test IsUtilsHb.dll
then...please if anybody know a different way to put a transparent splash screen... ill be grateful.. or better.. to fix this code section :)
[setup]
AppName=Slash PNG
AppVerName=1.0
DefaultDirName={pf}\program
[Languages]
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
[Files]
Source: IsUtilsHb.dll; DestDir: {app}; Flags: dontcopy
Source: SplashScreen.png; DestDir: {app}; Flags: dontcopy
[Code]
function SplashScreen(hWnd: Integer; pathPng: String; nSleep: Integer): Integer;
external 'SplashScreen#files:IsUtilsHb.dll stdcall';
procedure InitializeWizard();
var
SplashFileName: string;
begin
SplashFileName := ExpandConstant('{tmp}\SplashScreen.png');
ExtractTemporaryFile('SplashScreen.png');
SplashScreen(StrToInt(ExpandConstant('{hwnd}')), SplashFileName, 5000);
end;
After looking all around the internet, I got this solution:
This is the DLL am using:
isgsg.dll
[setup]
AppName=Slash PNG
AppVerName=1.0
DefaultDirName={pf}\program
[Languages]
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Source: "Splash.png"; DestDir: {tmp}; Flags: ignoreversion dontcopy nocompression
Source: isgsg.dll; DestDir: {tmp}; Flags: ignoreversion dontcopy nocompression
[Code]
procedure ShowSplashScreen(p1:HWND;p2:string;p3,p4,p5,p6,p7:integer;p8:boolean;p9:Cardinal;p10:integer); external 'ShowSplashScreen#files:isgsg.dll stdcall delayload';
procedure InitializeWizard();
begin
ExtractTemporaryFile('Splash.png');
ShowSplashScreen(WizardForm.Handle,ExpandConstant('{tmp}\Splash.png'),1000,3000,1000,0,255,True,$FFFFFF,10);
end;
Just added:
ShowSplashScreen(WizardForm.Handle,ExpandConstant('{tmp}\Splash.png'),1000,3000,1000,0,255,True,$FFFFFF,10);
Interpretation:
ShowSplashScreen(WizardForm.Handle,ExpandConstant('{tmp}\Splash.png'),1000(appear time),3000(show time),1000(disappear time),0(like a intermittent reload time),255(transparency 0..255),True,$FFFFFF (transparency color if not png transp),10);
like a intermittent reload time = use 9999999 and you see like a thunder image

Runtime error (at -1:0): Cannot import ISSkin.dll with InnoSetup

My program installs fine in my computer, which has ISSkin installed. I tried then to install my program in a different computer that has not got ISSkin installed and I get this message upon installation : "Runtime error (at -1:0): Cannot import dll:c:\Folder00\ISSkin.dll".
I searched on the net but nothing so far. I have the following code in my INNO:
[Files]
Source: "c:\Folder00\ISSkin.dll"; DestDir: {tmp}; Flags: dontcopy; Attribs: hidden system
[Code]
procedure LoadSkin(lpszPath: String; lpszIniFileName: String); external 'LoadSkin#c:\Folder00\ISSkin.dll cdecl';
procedure UnloadSkin();
external 'UnloadSkin#c:\Folder00\ISSkin.dll cdecl'
Im am using a *.cjstyles skin for the innosetup. I changed from STDCALL to CDECL but to no avail. Has anyone had this problem and how it can be solved?
You're extracting the dll to temporary files but trying to load it from some 'c:\folder00\', which most probably won't exist in the target computer.
Follow the example on the product page and you'll be fine. Relevant pieces from the linked example:
[Files]
Source: ISSkin.dll; DestDir: {app}; Flags: dontcopy
Source: Office2007.cjstyles; DestDir: {tmp}; Flags: dontcopy
[Code]
procedure LoadSkin(lpszPath: String; lpszIniFileName: String); external 'LoadSkin#files:isskin.dll stdcall';
function InitializeSetup(): Boolean;
begin
ExtractTemporaryFile('Office2007.cjstyles');
LoadSkin(ExpandConstant('{tmp}\Office2007.cjstyles'), '');
Result := True;
end;

Resources