Inno Setup Check if file exist in selected destination location - inno-setup

I have created files for a program I want to make as an update.
I would like it, before the installation, to check whether the program is also in the standard directory, and if not the one itself the right directory can choose where the program is.
I have tried this:
[Files]
Source: "C:\Data"; DestDir: "{app}"; Flags: ignoreversion
[Code]
function NextButtonClick(PageId: Integer): Boolean;
begin
Result := True;
if (PageId = wpSelectDir) and not FileExists(ExpandConstant('C:\Program\Test\Test.exe')) then begin
MsgBox('YourApp does not seem to be installed in that folder. Please select the correct folder.', mbError, MB_OK);
Result := False;
exit;
end;
end;
But during the installation it does not check it.
Whether the program is available or not, it installs it anyway.
I hope someone can help me.

You have to use the {app} constant in the test to check the selected folder:
FileExists(ExpandConstant('{app}\Test.exe'))

Related

Inno Setup will not create folder under C:\Users\Public - will instead do C:\Users\Public\Public Documents

I am using Inno Setup to build my installer and I have the C:\Users\Public folder hardcoded in my [Files] section to place some files (Inno Setup does not have a constant for this folder)
My goal is to have the install create a C:\Users\Public\MyApp folder with some files in it. However when I run the install, it is creating the folder here:
C:\Users\Public\Public Documents\MyApp
Is this a permissions issue where the installer doesn't have access to create a folder directly under C:\Users\Public?
[Files]
Source: "MyApp\db.mdf"; DestDir: "{drive:{src}}\Users\Public\MyApp"; Flags: ignoreversion;
I cannot reproduce your problem. For me your code works. I've tested it on Windows Vista, 7 and 10. It always installs to C:\Users\Public\MyApp.
Though I do not understand the {drive:{src}}. How does the drive of the Users folder relate to the drive of the installer? You should use the {sd} constant:
[Files]
Source: "MyApp\db.mdf"; DestDir: "{sd}\Users\Public\MyApp"; Flags: ignoreversion
But anyway, to resolve the path to the C:\Users\Public, you can use the PUBLIC environment variable:
[Files]
Source: "MyApp\db.mdf"; DestDir: "{%PUBLIC}\MyApp"; Flags: ignoreversion
It works since Windows Vista.
Alternatively, you can use SHGetKnownFolderPath with FOLDERID_Public. For an example code, see Constant for AppData\LocalLow?
If you need to support even Windows XP, where there is no C:\Users\Public folder or PUBLIC variable, you have to find out, what path your need to use there instead (probably C:\Documents and Settings\All Users), and implement a fallback using a scripted constant:
[Files]
Source: "MyProg.exe"; DestDir: "{code:GetPublicPath}\MyApp"; Flags: ignoreversion
[Code]
function GetPublicPath(Param: string): string;
begin
Result := GetEnv('PUBLIC');
if Result <> '' then
begin
Log(Format('PUBLIC is "%s"', [Result]));
end
else
begin
Result := GetEnv('ALLUSERSPROFILE');
Log(Format('PUBLIC is not set, ALLUSERSPROFILE is "%s"', [Result]));
end;
end;
And for others, it's worth noting that your need for resolve C:\Users\Public is very specific, related to this question: C++ app MDB in ProgramData copies to user's AppData folder when I dont want it to.
One usually does not want the C:\Users\Public, but C:\Users\Public\Documents (= {commondocs}) or C:\ProgramData aka C:\Users\All Users (= {commonappdata}).

Inno Setup: How to dynamically add files to the installation?

Is there a way to dynamically fill the [Dirs] and [Files] sections of an Inno Setup script?
Here is what I am trying to do:
during the install process, the user will select foo (foo matches a repository to get from our SCM)
Setup will run a batch to checkout foo from our SCM
then the content of foo must be added to the [Dirs] and [Files] sections of the script
Everything works fine except for the last step. I searched around and couldn't find explanations on how to do this. I have the feeling that my script should embed all the repositories of our SCM to then be able to copy only the selected ones to the destination directory.
Thanks for your help!
Regards,
See Inno Setup Prompt for external file location.
And add the recursesubdirs flag.
You may also need the createallsubdirs flag (assuming from your reference to the [Dirs] section).
[Files]
Source: "{code:GetScmPath}"; DestDir: "{app}"; \
Flags: external recursesubdirs createallsubdirs
[Code]
function GetScmPath(Param: string): string;
begin
Result := { make it return path to the checked out files }
end;

How to get path to the current InnoSetup script file?

How to get path, where the InnoSetup script file you are currently compiling is located ?
To get script source path, use the preprocessor's predefined variable SourcePath. That variable you can expand in your script as an ordinary define. In case, the script was not yet been saved, it returns path to My Documents directory. Here's just a useless example to test:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
procedure InitializeWizard;
begin
MsgBox(ExpandConstant('{#SourcePath}'), mbInformation, MB_OK);
end;
Don't forget that you have to compile the script (CTRL + F9) not only run (F9) to invoke preprocessor to rebuild the script.

Backup files and restore them on uninstall with InnoSetup?

Consider the following:
I have two files, for example XXX.txt and YYY.txt
I want to install them to a folder (let's say files), in which there are already XXX.txt and YYY.txt files
I want to "back up" the two original files, renaming them to XXX.txt.backup and YYY.txt.backup
On uninstall I want to restore the two files to their original state
How can I achieve this with Inno Setup?
Add
[Files]
; Backup Function_Template
Source: "{app}\XXX.txt"; DestDir: "{app}"; DestName: "XXX.txt.bkup"; Flags: external skipifsourcedoesntexist uninsneveruninstall
That would move the existing file, and the flags will prevent from uninstalling it. Now in the code you can put
[Code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
OldFile: string;
begin
case CurUninstallStep of
usPostUninstall:
begin
OldFile := ExpandConstant('{app}\XXX.txt.bkup');
if FileExists(OldFile) then
RenameFile(OldFile, ExpandConstant('{app}\XXX.txt'));
end;
end;
end;
Source: "{app}\XXX.txt"; DestDir: "{app}"; DestName: "XXX.txt.bkup"; Flags: external skipifsourcedoesntexist uninsneveruninstall
Did not appear to work, since "The compiler will prepend the path of your installation's source directory if you do not specify a fully qualified pathname."
However, I just discovered this works fine! I had left off the "external" flag.
Well, maybe a popup saying "There is already an XXX.txt.backup. Do you really want to overwrite it?"

jre 1.6 check and progress bar in inno

I want to check whether hre 1.6 or higher is installed or not. If installed I want to progress my application. If not installed , I want to install jre-6u17-windows-i586-s.exe after successfully installing jre , my control not returns to inno again. Please send a inno script for that.
best regards
SOumen
For the [FILES] section:
[Files]
Source: "jre-6u17-windows-i586-s.exe"; DestDir: "{app}\JRE 1.6"; Flags: onlyifdoesntexist
For the [CODE] section:
[Code]
Function JREInstallPrompt:Boolean;
begin
if ((msgBox ('Do you want to install JRE 1.6?',mbinformation,mb_YesNo)=idYes)) then
begin
msgBox ('JRE 1.6 will being installing now. Please do not restart the machine or log off until it is complete!',mbinformation,mb_OK);
Result:=True;
end
else Result:=False;
end;
Function JREVerifyInstall:Boolean;
begin
if ((RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\JavaSoft','InstallerVersion')) or (JREInstallPrompt=False)) then //Exists or do not install
Result:=False
else Result:=True;
end;
And for the RUN section:
[Run]
;SQL Server Express 2005 Installer
Filename: "{app}\JRE 1.6\jre-6u17-windows-i586-s.exe"; WorkingDir: {app}\JRE 1.6; StatusMsg: Installing Java Runtime Environment... Please Wait...;Check:JREVerifyInstall
Hopefully that will get you pointed in the right direction.

Resources