1
votes

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

  1. 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.

1
Only executables (DLLs, Exes) can have file versions. For other types of files (text files) you have to work with time stamp.NineBerry
Or if you cannot rely on file timestamps, you can skip an overwrite of existing files, if you are installing an older version of the installer - is this what you want?Martin Prikryl
@MartinPrikryl I want to overwrite existing files only if they are of newer version. I'm still considering using timestamps. Inno Setup devs don't recommend using them. I know there is a way to do that using the app version from the registry so I can compare it to the installer's version, but that's a bit more tricky. There is no other "easy" way, is there?wunderwaffle
That's what we know already! But the question is, how do you define a file to be "of newer version"?Martin Prikryl
@MartinPrikryl It comes with a new version of installer. That's how I thought it would work at least.wunderwaffle

1 Answers

0
votes

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.