我需要安装程序来检查目标位置是否存在文件,如果不存在,则安装将中止。我的项目是一个更新补丁,因此如果应用程序的主要exe文件不在目标位置,则我希望安装程序避免安装更新文件。我怎样才能做到这一点?
有人可以举例说明通过Windows注册表检查文件版本的代码吗?
[Files]
Source C:\filename.exe; DestDir {app}; Flags: ignoreversion; BeforeInstall: CheckForFile;
[code]
procedure CheckForFile(): Boolean;
begin
if (FileExists('c:\somefile.exe')) then
begin
MsgBox('File exists, install continues', mbInformation, MB_OK);
Result := True;
end
else
begin
MsgBox('File does not exist, install stops', mbCriticalError, MB_OK);
Result := False;
end;
end;
最佳答案
只是在选择正确的文件夹之前,不要让用户继续。
function NextButtonClick(PageId: Integer): Boolean;
begin
Result := True;
if (PageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\yourapp.exe')) then begin
MsgBox('YourApp does not seem to be installed in that folder. Please select the correct folder.', mbError, MB_OK);
Result := False;
exit;
end;
end;
当然,尝试自动为其选择正确的文件夹也是一个好主意。通过从注册表中检索正确的位置。