未调用 Inno Setup 函数
Inno Setup function not called
我希望 [InstallDelete]
部分调用一个自定义函数来检查是否安装了旧版本(在这种情况下,需要在安装新版本之前删除某些文件)。
从我的 Inno Setup 脚本中提取。首先是 returns 如果安装了旧版本则为真。
[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', mbInformation, MB_OK);
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('Existing version:'+Version+' New version:'+ExpandConstant('AppVersion'), mbInformation, MB_OK);
if (Version < '1.013') then
begin
Result := True;
end
else
begin
Result := False;
end
end
else
begin
Result := False;
end
end;
然后是应该调用这个函数的部分:
[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;
不幸的是,生成的设置似乎从不调用自定义函数(当使用此设置安装我的程序时,我从未在自定义函数中找到 MsgBox,并且文件未被删除)。
有没有可能我的函数有一些Inno Setup编译时没有指出的错误?如果有,我在哪里可以找到它们?
任何帮助/提示将不胜感激;谢谢!
如果你想在安装新的之前卸载它,你可以使用这个代码:
#define AppName SetupSetting('AppName')
#define AppVersion SetupSetting('AppVersion')
#define AppId SetupSetting('AppId')
#if AppId == ""
#define AppId AppName
#endif
[Code]
procedure InitializeWizard;
var
Uninstall,Version: String;
ResultCode:Integer;
begin
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', mbInformation, MB_OK);
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('Existing version:'+Version+' New version:'+ExpandConstant('{#AppVersion}'), mbInformation, MB_OK);
if (Version < ExpandConstant('{#AppVersion}')) then begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1','UninstallString', Uninstall);
Exec(RemoveQuotes(Uninstall), ' /RECAll /SILENT' , '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end
end
end;
我想我会保留上面的代码,对于您的问题这可能会有所帮助:
#define AppName SetupSetting('AppName')
#define AppVersion SetupSetting('AppVersion')
#define AppId SetupSetting('AppId')
#if AppId == ""
#define AppId AppName
#endif
[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;
[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', mbInformation, MB_OK);
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('Existing version:'+Version+' New version:'+ExpandConstant('{#AppVersion}'), mbInformation, MB_OK);
if (Version < '1.013') then begin
Result := True;
end else Result := False;
end else Result := False;
end;
如果从未调用过 MsgBox,则还有其他问题。
我创建了一个新项目,按原样粘贴您的行,然后弹出第一个消息框。
也许只是开始一个新的,并不断添加旧设置脚本中的部分,直到您找到阻止函数执行的原因。
您知道可以使用 F7 and/or 断点 F5 单步执行代码吗?
这应该可以帮助您找到问题所在,它应该是:[InstallDelete] -> [Dirs] -> [Files]
@IZB 是对的,ExpandConstant('AppId') 将被解析为 AppId 而不是实际 ID。检查调试部分的输出,我在下面添加了您的脚本。在单步执行代码时观察 Inno Seput 编译器底部的 "Debug output"。
并且,您还需要 ExpandConstant :) 因为否则您将获得领先的“{”加倍。它应该在 [Setup] 部分中加倍以转义括号字符。预编译器也会使用 #SetupSetting("AppId") 传递转义前导括号。 ExpandConstant 实际上不会在这里扩展任何常量,但会删除这个双括号。
这是完整的工作 iss 文件的粘贴:
#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"
[Setup]
AppId={{CB77C990-DECF-4697-B377-8F76799CC6B7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
// Debugging
// {#SetupSetting("AppId")} is short from {#emit SetupSetting("AppId")}
Log('Note the double bracket: {#SetupSetting("AppId")}');
Log('Now it''s fine: ' + ExpandConstant('{# SetupSetting("AppId")}'));
Log(' This won''t expand: ' + ExpandConstant('AppId'));
if RegValueExists(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion') then
begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion', Version);
MsgBox('Existing version:' + Version + ' New version:{#SetupSetting("AppVersion")}', mbInformation, MB_OK);
if (Version < '1.013') then Result := True
else Result := False;
end
else Result := False;
end;
[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check: deleteExistingHhd
我希望 [InstallDelete]
部分调用一个自定义函数来检查是否安装了旧版本(在这种情况下,需要在安装新版本之前删除某些文件)。
从我的 Inno Setup 脚本中提取。首先是 returns 如果安装了旧版本则为真。
[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', mbInformation, MB_OK);
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('Existing version:'+Version+' New version:'+ExpandConstant('AppVersion'), mbInformation, MB_OK);
if (Version < '1.013') then
begin
Result := True;
end
else
begin
Result := False;
end
end
else
begin
Result := False;
end
end;
然后是应该调用这个函数的部分:
[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;
不幸的是,生成的设置似乎从不调用自定义函数(当使用此设置安装我的程序时,我从未在自定义函数中找到 MsgBox,并且文件未被删除)。
有没有可能我的函数有一些Inno Setup编译时没有指出的错误?如果有,我在哪里可以找到它们?
任何帮助/提示将不胜感激;谢谢!
如果你想在安装新的之前卸载它,你可以使用这个代码:
#define AppName SetupSetting('AppName')
#define AppVersion SetupSetting('AppVersion')
#define AppId SetupSetting('AppId')
#if AppId == ""
#define AppId AppName
#endif
[Code]
procedure InitializeWizard;
var
Uninstall,Version: String;
ResultCode:Integer;
begin
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', mbInformation, MB_OK);
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('Existing version:'+Version+' New version:'+ExpandConstant('{#AppVersion}'), mbInformation, MB_OK);
if (Version < ExpandConstant('{#AppVersion}')) then begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1','UninstallString', Uninstall);
Exec(RemoveQuotes(Uninstall), ' /RECAll /SILENT' , '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end
end
end;
我想我会保留上面的代码,对于您的问题这可能会有所帮助:
#define AppName SetupSetting('AppName')
#define AppVersion SetupSetting('AppVersion')
#define AppId SetupSetting('AppId')
#if AppId == ""
#define AppId AppName
#endif
[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;
[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', mbInformation, MB_OK);
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('Existing version:'+Version+' New version:'+ExpandConstant('{#AppVersion}'), mbInformation, MB_OK);
if (Version < '1.013') then begin
Result := True;
end else Result := False;
end else Result := False;
end;
如果从未调用过 MsgBox,则还有其他问题。
我创建了一个新项目,按原样粘贴您的行,然后弹出第一个消息框。
也许只是开始一个新的,并不断添加旧设置脚本中的部分,直到您找到阻止函数执行的原因。
您知道可以使用 F7 and/or 断点 F5 单步执行代码吗? 这应该可以帮助您找到问题所在,它应该是:[InstallDelete] -> [Dirs] -> [Files]
@IZB 是对的,ExpandConstant('AppId') 将被解析为 AppId 而不是实际 ID。检查调试部分的输出,我在下面添加了您的脚本。在单步执行代码时观察 Inno Seput 编译器底部的 "Debug output"。
并且,您还需要 ExpandConstant :) 因为否则您将获得领先的“{”加倍。它应该在 [Setup] 部分中加倍以转义括号字符。预编译器也会使用 #SetupSetting("AppId") 传递转义前导括号。 ExpandConstant 实际上不会在这里扩展任何常量,但会删除这个双括号。
这是完整的工作 iss 文件的粘贴:
#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"
[Setup]
AppId={{CB77C990-DECF-4697-B377-8F76799CC6B7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
// Debugging
// {#SetupSetting("AppId")} is short from {#emit SetupSetting("AppId")}
Log('Note the double bracket: {#SetupSetting("AppId")}');
Log('Now it''s fine: ' + ExpandConstant('{# SetupSetting("AppId")}'));
Log(' This won''t expand: ' + ExpandConstant('AppId'));
if RegValueExists(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion') then
begin
RegQueryStringValue(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion', Version);
MsgBox('Existing version:' + Version + ' New version:{#SetupSetting("AppVersion")}', mbInformation, MB_OK);
if (Version < '1.013') then Result := True
else Result := False;
end
else Result := False;
end;
[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check: deleteExistingHhd