2013-11-20 13 views

risposta

18

non fosse così facile da implementare questa funzione prima che il metodo CurInstallProgressChanged evento è stato introdotto nel Inno Setup 5.5.4. Ma ora, avendo questo evento disponibile, puoi scrivere uno script come questo:

Un ringraziamento speciale a user1662035 per l'idea proposta per la correzione delle etichette nascoste durante il processo di rollback.

[Setup] 
AppName=My Program 
AppVersion=1.5 
DefaultDirName={pf}\My Program 

[Files] 
Source: "MyProg.exe"; DestDir: "{app}" 
Source: "MyProg.chm"; DestDir: "{app}" 
Source: "Readme.txt"; DestDir: "{app}" 

[Code] 
function GetTickCount: DWORD; 
    external '[email protected] 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; 
+1

Ottimo lavoro, TLama, grazie! Penso che l'unica soluzione per nascondere le etichette sia una finestra di messaggio personalizzata e invocare manualmente la cancellazione. Forse questo è il trucco: [link] (http://pastebin.com/SJwjVGvs) Ma non l'ho provato. – user1662035

+0

@ user1662035, sì, quello era il pensiero immediato che avevo. Ma cercherò di guardare qualcosa di più preciso ancora. Ad ogni modo, è possibile utilizzare la funzione ['ExitSetupMsgBox'] (http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_exitsetupmsgbox) pronta per mostrare la finestra di dialogo di conferma dell'uscita. Tuttavia, questo messaggio non è diverso da "* Vuoi uscire dalla configurazione? *". In questo momento non ho ancora installato Inno Setup per verificare ... – TLama

+0

Ho completamente dimenticato questa funzione ... Ho appena provato entrambe le versioni ed entrambe mostrano la solita finestra di dialogo di uscita. Posso chiederti cosa intendi per "più preciso"? – user1662035

Problemi correlati