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

时间:2018-03-30 14:18:16

标签: inno-setup

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

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

Wizard Page

如果你能帮助我,那将是非常酷的。 :)

1 个答案:

答案 0 :(得分:2)

使用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;