Tom
Tom

Reputation: 1385

Inno Setup: how to call custom functions from the InstallDelete section

I would need Inno Setup generated installer to delete certain files prior installation if the software is already installed with an older version.

I tried to do this by comparing version numbers (custom function below) but when compiling, Inno Setup generates an error:

[ISPP] Undeclared identifier: "GetInstalledVersion".

The Inno Setup script relevant extract is:

(...)
[Code]
function GetInstalledVersion(MandatoryButNotUsedParam: String): String;
var Version: String;
begin
  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', 'DisplayVersion') then
    begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', 'DisplayVersion', Version);
      MsgBox(ExpandConstant('Existing version:'+Version+'  New version:'+ExpandConstant('AppVersion')), mbInformation, MB_OK);
      Result := Version;
    end
  else
    begin
      Result := '';
    end
end;
(...)
[InstallDelete]
#define InstalledAppVersion GetInstalledVersion('')
#if "1.013" > InstalledAppVersion
  Type: files; Name: {userappdata}\xxx\*.hhd
#endif

Being new to Inno Setup, this is certainly a trivial question but no answer found on forums. The question is thus: how can I properly call the function GetInstalledVersion from the [InstallDelete] section?

Is there an issue because [InstallDelete] section might be called before [code] section is read?

Many thanks for any help / hint!

Upvotes: 0

Views: 4148

Answers (1)

papo
papo

Reputation: 1949

Do you want to check for currently installed version and if it's below 1.013, then remove user files from {userappdata}\xxx\*.hhd ?

then what you need is parameter Check http://www.jrsoftware.org/ishelp/index.php?topic=scriptcheck

[Code]
function isOldVersionInstalled: Boolean;
begin
  // Result := <True|False>;
end;

[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:isOldVersionInstalled;

What is wrong with your example:

You are calling a Pascal function from the pre-processor. Those are two different things.
You can define a macro in pre-processor - that's kind of like a function, but that's not what you want because Pre-processor only runs on compile time and so it can't be used to check on state of User's files/environment.

Upvotes: 5

Related Questions