在 Inno Setup 中处理和自定义错误和消息

问题描述

Inno Setup 将向用户显示不同的消息框。 例如,

  1. 当它尝试安装一个正在使用的文件时,它会显示一条消息来中止/忽略/取消。

  2. 当安装程序正在安装文件并且安装时目标路径空间不足时,安装程​​序会出错。

我需要自己定制这些消息框。 (我不希望向用户显示这些本机消息)例如,我需要显示一个消息框,甚至完全不显示来自 Inno Setup 的特定消息,或者在该消息即将触发时更改标签.

解决方法

所有 Inno Setup 消息都可以使用 [Messages] section 进行自定义。

一些例子:


至于消息框布局/设计的变化。你无法真正改变它。通过 CheckBeforeInstall parameters 的一些奇特实现,您可能能够在 Inno Setup 检测到问题并以自定义方式处理它们之前发现一些问题。但这是大量工作,结果不可靠。

如果您更具体地告诉我们您想实现什么目标,您可能会得到更具体的答案。


如果您需要一个允许 Inno Setup 允许的所有错误的解决方案,包括安装的干净中止,CheckBeforeInstall 将无济于事,因为它们没有办法干净地中止

您必须在安装前进行所有检查,例如在CurStepChanged(ssInstall)

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: ShouldInstallFile

[Code]

var
  DontInstallFile: Boolean;

function ShouldInstallFile: Boolean;
begin
  Result := not DontInstallFile;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  FileName: string;
  Msg: string;
  Response: Integer;
begin
  if CurStep = ssInstall then
  begin
    FileName := ExpandConstant('{app}\MyProg.exe');
    repeat
      if FileExists(FileName) and (not DeleteFile(FileName)) then
      begin
        Msg := Format('File %s cannot be replaced',[FileName]);
        Response := MsgBox(Msg,mbError,MB_ABORTRETRYIGNORE)
        case Response of
          IDABORT: Abort;
          IDIGNORE: DontInstallFile := True;
        end;
      end;
    until (Response <> IDRETRY);
  end;
end;