Inno Setup - 检查目标中是否存在文件,否则不会中止安装 [英] Inno Setup - Check if file exist in destination or else if doesn't abort the installation

查看:21
本文介绍了Inno Setup - 检查目标中是否存在文件,否则不会中止安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的安装程序检查目标位置中是否存在文件,如果不存在,则安装中止.我的项目是一个更新补丁,所以如果应用程序的主 exe 不在目标中,我希望安装程序避免安装更新文件.我该怎么做?

I need my installer to check if a file exists in the destination location, and if is not there, then the installation aborts. My project is a update patch, so I want the installer to avoid installing the update files if the main exe of the application is not in the destination. How can I do this?

谁能给出一个通过 Windows 注册表检查文件版本的代码示例?

Can someone give an example of code to check file version through the Windows registry?

[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;

推荐答案

在用户选择正确的文件夹之前不要让他们继续.

Just don't let the user proceed until they pick the correct folder.

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;

当然,尝试自动为他们选择正确的文件夹也是一个好主意,例如.通过从注册表中检索正确的位置.

Of course, it's also a good idea to try to automatically pick the correct folder for them, eg. by retrieving the correct location out of the registry.

这篇关于Inno Setup - 检查目标中是否存在文件,否则不会中止安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆