如何在 Inno Setup 中禁用磁盘 Space 警告消息?

How to disable Disk Space Warning message in Inno Setup?

我正在使用 Inno Setup 创建安装程序。我使用函数 GetSpaceOnDisk 计算了可用磁盘 space。如果可用磁盘 space 不够,我会显示错误消息,然后安装程序将无法继续。

但在我的错误消息显示之前,Inno Setup Disk space 警告与 Yes/No 选项一起显示。如何禁用此警告?

您不能禁用检查,也不能更改按钮。


您可以做的是通过使用 [Messages] 部分覆盖默认文本来恢复消息中问题的含义,例如:

Do you want to cancel installation?

如果用户按下 ,安装程序会停留在Select目标位置页面上。如果用户按下 Yes,则会调用 NextButtonClick(wpSelectDir)。在那里你重复检查磁盘 space(以区分调用与基本场景,没有警告),如果 space 不够,你将强制中止安装程序。

[Messages]
DiskSpaceWarning=Setup requires at least %1 KB of free space to install, but the selected drive only has %2 KB available.%n%nDo you want to cancel installation?
[Code]

function NotEnoughSpace: Boolean;
begin
  Result := { Check disk space };
end;

procedure ExitProcess(exitCode:integer);
  external 'ExitProcess@kernel32.dll stdcall';
  
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID = wpSelectDir then
  begin
    if NotEnoughSpace then
    begin
      ExitProcess(0);
    end; 
  end;
  Result := True;
end;

最终解决方案是重新实现Select目标位置页面。这并不难。只有一个编辑框和一个按钮。