在 Inno Setup 的“选择目标位置”页面上显示所选驱动器上的可用磁盘空间

问题描述 投票:0回答:1

我正在使用 Inno Setup 创建一个安装程序,我的问题是:

如何添加自定义文本标签,例如:“当前驱动器中的空间:XXX Mb”以及该向导页面上所需的空间数量:

Wizard Page

如果你能帮助我,那就太好了。 :)

inno-setup
1个回答
3
投票

使用

GetSpaceOnDisk64
查询可用磁盘空间:

var
  FreeDiskSpaceLabel: TNewStaticText;
 
procedure UpdateDiskSpaceLabel;
var
  Path, Path2: string;
  Free, Total: Int64;
  FreeGB: Extended;
  S: string;
begin
  Path := WizardDirValue;
  // Installation path will be typically absent,
  // so find the first parent path that really exists
  while not DirExists(Path) do
  begin
    Path2 := RemoveBackslash(ExtractFilePath(RemoveBackslash(Path)));
    if (Path2 = '') or (Path2 = Path) then break;
    Path := Path2;
  end;
  if GetSpaceOnDisk64(Path, Free, Total) then
  begin
    FreeGB := Extended(Free) / (1024*1024*1024);
    S := Format('There is %.1n GB free space on selected drive.', [FreeGB]);
  end
    else
  begin
    S := 'Error querying free space on selected drive';
  end;
  FreeDiskSpaceLabel.Caption := S;
end;

procedure DirEditChange(Sender: TObject);
begin
  UpdateDiskSpaceLabel;
end;

procedure InitializeWizard();
begin
  FreeDiskSpaceLabel := TNewStaticText.Create(WizardForm);
  FreeDiskSpaceLabel.Parent := WizardForm.DiskSpaceLabel.Parent;
  FreeDiskSpaceLabel.Top :=
    WizardForm.DiskSpaceLabel.Top - WizardForm.DiskSpaceLabel.Height -
    ScaleY(8);
  FreeDiskSpaceLabel.Left := WizardForm.DiskSpaceLabel.Left;

  WizardForm.DirEdit.OnChange := @DirEditChange;
  // Update for default/previous path
  UpdateDiskSpaceLabel;
end;

© www.soinside.com 2019 - 2024. All rights reserved.