#define NeedSize 4380
#define NeedInstallSize 7890
[Setup]
AppName=MyApp
AppVerName=MyApp
DefaultDirname={pf}\MyApp
[code]
var
TotalSpaceLabel, FreeSpaceLabel, NeedSpacelabel, InstallSpaceLabel: TLabel;
FreeMB, TotalMB: Cardinal;
function NumToStr(Float: Extended): String;
begin
Result:= Format('%.2f', [Float]);
StringChange(Result, ',', '.');
while ( Pos('.', Result) > 0 ) and ( (Result[Length(Result)] = '0') or (Result[Length(Result)] = '.') ) do
SetLength(Result, Length(Result) - 1);
end;
function MbOrTb(Float: Extended): String;
begin
if Float < 1024 then Result:= NumToStr(Float)+' Мб' else
if Float/1024 < 1024 then Result:= NumToStr(Float/1024)+' Гб' else
Result:= NumToStr(Float/(1024*1024))+' Тб';
end;
procedure DirEditOnChange(Sender: TObject);
var Drive: String;
begin
Drive:= ExtractFileDrive(WizardForm.DirEdit.Text);
GetSpaceOnDisk(Drive, True, FreeMB, TotalMB);
TotalSpaceLabel.Caption:= 'Всего места на диске: '+MbOrTb(TotalMB);
FreeSpaceLabel.Caption:= 'Доступно места на диске: '+MbOrTb(FreeMB)+' ('+IntToStr(round(FreeMB*100/TotalMB))+'%)';
InstallSpacelabel.Caption:= 'Требуется места для установки: '+MbOrTb({#NeedInstallSize});
NeedSpaceLabel.Caption:= 'Требуется места на диске: '+MbOrTb({#NeedSize});
WizardForm.NextButton.Enabled:= (FreeMB>{#NeedInstallSize})and(FreeMB>{#NeedSize});
end;
procedure InitializeWizard();
begin
TotalSpaceLabel:= TLabel.Create(WizardForm);
TotalSpaceLabel.AutoSize:= False;
TotalSpaceLabel.SetBounds(0, 120, 300, 20);
TotalSpaceLabel.Parent:= WizardForm.SelectDirpage;
FreeSpaceLabel:= TLabel.Create(WizardForm);
FreeSpaceLabel.AutoSize:= False;
FreeSpaceLabel.SetBounds(0, 140, 300, 20);
FreeSpaceLabel.Parent:= WizardForm.SelectDirpage;
InstallSpacelabel:= TLabel.Create(WizardForm);
InstallSpacelabel.AutoSize:= False;
InstallSpacelabel.SetBounds(0, 160, 300, 20);
InstallSpacelabel.Parent:= WizardForm.SelectDirpage;
NeedSpaceLabel:= TLabel.Create(WizardForm);
NeedSpaceLabel.AutoSize:= False;
NeedSpaceLabel.SetBounds(0, 180, 300, 20);
NeedSpaceLabel.Parent:= WizardForm.SelectDirpage;
WizardForm.DirEdit.OnChange:=@DirEditOnChange;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID=wpSelectDir then begin
DirEditOnChange(nil)
end;
end;