nizcoz
Участник
Hi! i wish add a percentage, time elapse, etc to my script (progress bar). And mix this script with my script:
But this code interfere with my script, not show the TotalSpaceLabel, FreeSpaceLabel and InstallSpacelabel.
This is the script to add TotalSpaceLabel, FreeSpaceLabel, InstallSpacelabel:
Код:
[Code]
function GetTickCount: DWORD;
external 'GetTickCount@kernel32.dll stdcall';
var
StartTick: DWORD;
PercentLabel: TNewStaticText;
ElapsedLabel: TNewStaticText;
RemainingLabel: TNewStaticText;
function TicksToStr(Value: DWORD): string;
var
I: DWORD;
Hours, Minutes, Seconds: Integer;
begin
I := Value div 1000;
Seconds := I mod 60;
I := I div 60;
Minutes := I mod 60;
I := I div 60;
Hours := I mod 24;
Result := Format('%.2d:%.2d:%.2d', [Hours, Minutes, Seconds]);
end;
procedure InitializeWizard;
begin
PercentLabel := TNewStaticText.Create(WizardForm);
PercentLabel.Parent := WizardForm.ProgressGauge.Parent;
PercentLabel.Left := 0;
PercentLabel.Top := WizardForm.ProgressGauge.Top +
WizardForm.ProgressGauge.Height + 12;
ElapsedLabel := TNewStaticText.Create(WizardForm);
ElapsedLabel.Parent := WizardForm.ProgressGauge.Parent;
ElapsedLabel.Left := 0;
ElapsedLabel.Top := PercentLabel.Top + PercentLabel.Height + 4;
RemainingLabel := TNewStaticText.Create(WizardForm);
RemainingLabel.Parent := WizardForm.ProgressGauge.Parent;
RemainingLabel.Left := 0;
RemainingLabel.Top := ElapsedLabel.Top + ElapsedLabel.Height + 4;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpInstalling then
StartTick := GetTickCount;
end;
procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
if CurPageID = wpInstalling then
begin
Cancel := False;
if ExitSetupMsgBox then
begin
Cancel := True;
Confirm := False;
PercentLabel.Visible := False;
ElapsedLabel.Visible := False;
RemainingLabel.Visible := False;
end;
end;
end;
procedure CurInstallProgressChanged(CurProgress, MaxProgress: Integer);
var
CurTick: DWORD;
begin
CurTick := GetTickCount;
PercentLabel.Caption :=
Format('Done: %.2f %%', [(CurProgress * 100.0) / MaxProgress]);
ElapsedLabel.Caption :=
Format('Elapsed: %s', [TicksToStr(CurTick - StartTick)]);
if CurProgress > 0 then
begin
RemainingLabel.Caption :=
Format('Remaining: %s', [TicksToStr(
((CurTick - StartTick) / CurProgress) * (MaxProgress - CurProgress))]);
end;
end;
This is the script to add TotalSpaceLabel, FreeSpaceLabel, InstallSpacelabel:
Код:
var
TotalSpaceLabel, FreeSpaceLabel, NeedSpacelabel, InstallSpaceLabel: TLabel;
FreeMB, TotalMB: Cardinal;
function MbOrTb(Float: Extended): String;
begin
if Float < 1024 then Result:= FormatFloat('0', Float)+ ExpandConstant(' {cm:Mb}') else
if Float/1024 < 1024 then Result:= format('%.2n', [Float/1024])+ ExpandConstant(' {cm:Gb}') else
Result:= format('%.2n', [Float/(1024*1024)])+ ExpandConstant(' {cm:Tb}'); StringChange(Result, ',', '.');
end;
procedure DirEditOnChange(Sender: TObject);
var Drive: String;
begin
Drive:= ExtractFileDrive(WizardForm.DirEdit.Text);
GetSpaceOnDisk(Drive, True, FreeMB, TotalMB);
TotalSpaceLabel.Caption:= ExpandConstant('{cm:TotalSpaceLabel} ')+MbOrTb(TotalMB);
FreeSpaceLabel.Caption:= ExpandConstant('{cm:FreeSpaceLabel} ')+MbOrTb(FreeMB)+' ('+IntToStr(round(FreeMB*100/TotalMB))+'%)';
InstallSpacelabel.Caption:= ExpandConstant('{cm:InstallSpacelabel} ')+MbOrTb({#NeedInstallSize});
NeedSpaceLabel.Caption:= ExpandConstant('{cm:NeedSpaceLabel} ')+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;
Modificado por mí y agregado que se vea en rojo cuando no hay espacio disponible:
#define NeedInstallSize 100
[Languages]
Name: "eng"; MessagesFile: "Idiomas\English.isl"
Name: "spa"; MessagesFile: "Idiomas\Spanish.isl"
[CustomMessages]
eng.Finished=The installation is completed.
spa.Finished=La instalación se ha completado.
eng.TotalSpaceLabel=Total disk space:
eng.FreeSpaceLabel=Available disk space:
eng.InstallSpacelabel=Required space for installation:
spa.TotalSpaceLabel=Espacio total en disco:
spa.FreeSpaceLabel=Espacio disponible:
spa.InstallSpacelabel=Espacio necesario para la instalación:
[code]
[Code]
var
TotalSpaceLabel, FreeSpaceLabel, InstallSpaceLabel: TLabel;
FreeMB, TotalMB: Cardinal;
Function NumToStr(Float: Extended): String;
Begin
Result:= Format('%.2n', [Float]); StringChange(Result, ',', '.');
while ((Result[Length(Result)] = '0') or (Result[Length(Result)] = '.')) and (Pos('.', Result) > 0) do
SetLength(Result, Length(Result)-1);
End;
Function MbOrTb(Byte: Extended): String;
begin
if Byte < 1024 then Result:= NumToStr(Byte) + ' Mb' else
if Byte/1024 < 1024 then Result:= NumToStr(round(Byte/1024*100)/100) + ' Gb' else
Result:= NumToStr(round((Byte/(1024*1024))*100)/100) + ' Tb'
end;
procedure DirEditOnChange(Sender: TObject);
var Drive: String;
begin
Drive:= ExtractFileDrive(WizardForm.DirEdit.Text);
GetSpaceOnDisk(Drive, True, FreeMB, TotalMB);
TotalSpaceLabel.Caption:= ExpandConstant('{cm:TotalSpaceLabel} ')+MbOrTb(TotalMB);
FreeSpaceLabel.Caption:= ExpandConstant('{cm:FreeSpaceLabel} ')+MbOrTb(FreeMB)+' ('+IntToStr(round(FreeMB*100/TotalMB))+'%)';
InstallSpacelabel.Caption:= ExpandConstant('{cm:InstallSpacelabel} ')+MbOrTb({#NeedInstallSize});
if (FreeMB<{#NeedInstallSize}) then
InstallSpacelabel.Font.Color:=clRed
else
InstallSpacelabel.Font.Color:=InstallSpacelabel.Font.Color;
WizardForm.NextButton.Enabled:= (FreeMB>{#NeedInstallSize})
end;
procedure InitializeWizard;
begin
TotalSpaceLabel:= TLabel.Create(WizardForm);
TotalSpaceLabel.AutoSize:= False;
TotalSpaceLabel.SetBounds(0, 140, 300, 20);
TotalSpaceLabel.Parent:= WizardForm.SelectDirpage;
FreeSpaceLabel:= TLabel.Create(WizardForm);
FreeSpaceLabel.AutoSize:= False;
FreeSpaceLabel.SetBounds(0, 160, 300, 20);
FreeSpaceLabel.Parent:= WizardForm.SelectDirpage;
InstallSpacelabel:= TLabel.Create(WizardForm);
InstallSpacelabel.AutoSize:= False;
InstallSpacelabel.SetBounds(0, 180, 300, 20);
InstallSpacelabel.Parent:= WizardForm.SelectDirpage;
WizardForm.DirEdit.OnChange:=@DirEditOnChange;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID=wpSelectDir then begin
DirEditOnChange(nil)
end;
end;