Reputation: 13
I'm using Inno Setup to create an installer. When I run an installer of older version (e.g 1.0.0.2) on a computer that already has application of newer version (e.g. 1.0.0.3) installed I don't want files with the same name to be overwritten.
As I understand from here
- If the existing file is a newer version than the file being installed, or if the existing file has version info but the file being installed does not, the existing file will not be replaced.
Inno Setup help, Files section
running an installer of older version over existing newer version must NOT replace existing file.
I've created two installers. Older version (1) has:
AppVersion=1.0.0.2
VersionInfoVersion={#SetupSetting('AppVersion')}
and the newer version (2) has:
AppVersion=1.0.0.3
VersionInfoVersion={#SetupSetting('AppVersion')}
Both installers have the same Files section:
[Files]
Source: "D:\installer\test1003\*"; DestDir: "{app}\app"; Flags: recursesubdirs createallsubdirs
But when I run (1) having (2) installed file with the same name is replaced (and vice versa but that is logical as I understand)
I decided to create log files for both installers and that is what I got:
Dest filename: C:\Program Files\dir\app\tryout.txt
Time stamp of our file: 2019-01-23 13:02:10.000 Dest file exists.
Time stamp of existing file: 2019-01-23 13:01:50.000
Version of our file: (none)
Version of existing file: (none)
These parts are identical except for timestamps.
Any ideas on how to set versions for installed files?
Thanks in advance.
I'm not sure if that's important, but I'm using Unicode version of Inno Setup. Now it supports only one version, but I want to add more later.
Upvotes: 1
Views: 2830
Reputation: 202242
If you want to install a certain file, if installing a newer version of the installer only, you can use the following code:
[Setup]
AppName=My Program
AppVersion=1.5
[Files]
; Overwrite .exe always
Source: "MyProg.exe"; DestDir: "{app}"
; Overwrite .dat file only when installing a newer version
Source: "MyProg.dat"; DestDir: "{app}"; Check: IsInstallingNewerVersion
[Code]
{ Update AppId in the key! }
const
UninstallKey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\My Program_is1';
DisplayVersionValue = 'DisplayVersion';
var
InstallingNewerVersion: Boolean;
function IsInstallingNewerVersion: Boolean;
begin
Result := InstallingNewerVersion;
end;
function InitializeSetup(): Boolean;
var
PrevVersion, CurVersion: string;
begin
if RegQueryStringValue(HKLM, UninstallKey, DisplayVersionValue, PrevVersion) or
RegQueryStringValue(HKCU, UninstallKey, DisplayVersionValue, PrevVersion) then
begin
Log(Format('Previous version %s', [PrevVersion]));
CurVersion := '{#SetupSetting('AppVersion')}';
Log(Format('Installing version %s', [CurVersion]));
InstallingNewerVersion := (CompareVersion(PrevVersion, CurVersion) < 0);
if InstallingNewerVersion then Log('Installing newer version')
else Log('Not installing newer version')
end;
Result := True;
end;
Get the CompareVersion
function from Compare version strings in Inno Setup.
Upvotes: 1