Inno Setup:如何从 InstallDelete 部分调用自定义函数
Inno Setup: how to call custom functions from the InstallDelete section
如果软件已经安装了旧版本,我需要 Inno Setup 生成的安装程序在安装前删除某些文件。
我试图通过比较版本号(下面的自定义函数)来做到这一点,但是在编译时,Inno Setup 生成错误:
[ISPP] Undeclared identifier: "GetInstalledVersion".
Inno Setup脚本相关摘录为:
(...)
[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
作为 Inno Setup 的新手,这当然是一个微不足道的问题,但在论坛上找不到答案。因此问题是:如何从 [InstallDelete]
部分正确调用函数 GetInstalledVersion
?
是否存在问题,因为 [InstallDelete]
部分可能在读取 [code]
部分之前被调用?
非常感谢您的帮助/提示!
是否要检查当前安装的版本,如果低于 1.013,
然后从 {userappdata}\xxx\*.hhd
?
中删除用户文件
那么你需要的是参数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;
你的例子有什么问题:
您正在从预处理器调用 Pascal 函数。
这是两个不同的东西。
你可以在预处理器中定义一个宏——这有点像一个函数,
但这不是你想要的,因为预处理器只在编译时运行,所以它不能用于检查用户 files/environment.
的状态
如果软件已经安装了旧版本,我需要 Inno Setup 生成的安装程序在安装前删除某些文件。
我试图通过比较版本号(下面的自定义函数)来做到这一点,但是在编译时,Inno Setup 生成错误:
[ISPP] Undeclared identifier: "GetInstalledVersion".
Inno Setup脚本相关摘录为:
(...)
[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
作为 Inno Setup 的新手,这当然是一个微不足道的问题,但在论坛上找不到答案。因此问题是:如何从 [InstallDelete]
部分正确调用函数 GetInstalledVersion
?
是否存在问题,因为 [InstallDelete]
部分可能在读取 [code]
部分之前被调用?
非常感谢您的帮助/提示!
是否要检查当前安装的版本,如果低于 1.013,
然后从 {userappdata}\xxx\*.hhd
?
那么你需要的是参数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;
你的例子有什么问题:
您正在从预处理器调用 Pascal 函数。
这是两个不同的东西。
你可以在预处理器中定义一个宏——这有点像一个函数,
但这不是你想要的,因为预处理器只在编译时运行,所以它不能用于检查用户 files/environment.