Skip to content

Commit

Permalink
Added new AbortedByUser property to the TDownloadWizardPage support c…
Browse files Browse the repository at this point in the history
…lass.
  • Loading branch information
martijnlaan committed Dec 10, 2020
1 parent 763e3e3 commit 312c0a4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Examples/CodeDownloadFiles.iss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ begin
DownloadPage.Download;
Result := True;
except
SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
if DownloadPage.AbortedByUser then
Log('Aborted by user.')
else
SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
Result := False;
end;
finally
Expand Down
1 change: 1 addition & 0 deletions ISHelp/isxclasses.pas
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ TOutputProgressWizardPage = class(TWizardPage)

TDownloadWizardPage = class(TOutputProgressWizardPage)
property AbortButton: TNewButton; read;
property AbortedByUser: Boolean; read;
procedure Add(const Url, BaseName, RequiredSHA256OfFile: String);
procedure Clear;
function Download: Int64;
Expand Down
1 change: 1 addition & 0 deletions Projects/ScriptClasses_C.pas
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ procedure RegisterDownloadWizardPage_C(Cl: TPSPascalCompiler);
with CL.AddClassN(Cl.FindClass('TOutputProgressWizardPage'),'TDownloadWizardPage') do
begin
RegisterProperty('AbortButton', 'TNewButton', iptr);
RegisterProperty('AbortedByUser', 'Boolean', iptr);
RegisterMethod('procedure Add(const Url, BaseName, RequiredSHA256OfFile: String)');
RegisterMethod('procedure Clear');
RegisterMethod('function Download: Int64');
Expand Down
3 changes: 3 additions & 0 deletions Projects/ScriptClasses_R.pas
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,13 @@ procedure RegisterOutputProgressWizardPage_R(CL: TPSRuntimeClassImporter);
end;

{$IFNDEF PS_NOINT64}
procedure TDownloadPageAbortedByUser_R(Self: TDownloadWizardPage; var T: Boolean); begin T := Self.AbortedByUser; end;

procedure RegisterDownloadWizardPage_R(CL: TPSRuntimeClassImporter);
begin
with CL.Add(TDownloadWizardPage) do
begin
RegisterPropertyHelper(@TDownloadPageAbortedByUser_R,nil,'AbortedByUser');
RegisterMethod(@TDownloadWizardPage.Add, 'Add');
RegisterMethod(@TDownloadWizardPage.Clear, 'Clear');
RegisterMethod(@TDownloadWizardPage.Download, 'Download');
Expand Down
9 changes: 5 additions & 4 deletions Projects/ScriptDlg.pas
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,15 @@ TDownloadWizardPage = class(TOutputProgressWizardPage)
FFiles: TObjectList;
FOnDownloadProgress: TOnDownloadProgress;
FAbortButton: TNewButton;
FShowProgressControlsOnNextProgress, FNeedToAbortDownload: Boolean;
FShowProgressControlsOnNextProgress, FAbortedByUser: Boolean;
procedure AbortButtonClick(Sender: TObject);
function InternalOnDownloadProgress(const Url, BaseName: string; const Progress, ProgressMax: Int64): Boolean;
procedure ShowProgressControls(const AVisible: Boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Initialize; override;
property AbortedByUser: Boolean read FAbortedByUser;
procedure Add(const Url, BaseName, RequiredSHA256OfFile: String);
procedure Clear;
function Download: Int64;
Expand Down Expand Up @@ -895,14 +896,14 @@ TDownloadFile = class

procedure TDownloadWizardPage.AbortButtonClick(Sender: TObject);
begin
FNeedToAbortDownload := LoggedMsgBox(SetupMessages[msgStopDownload], '', mbConfirmation, MB_YESNO, True, ID_YES) = IDYES;
FAbortedByUser := LoggedMsgBox(SetupMessages[msgStopDownload], '', mbConfirmation, MB_YESNO, True, ID_YES) = IDYES;
end;

function TDownloadWizardPage.InternalOnDownloadProgress(const Url, BaseName: string; const Progress, ProgressMax: Int64): Boolean;
var
Progress32, ProgressMax32: LongInt;
begin
if FNeedToAbortDownload then begin
if FAbortedByUser then begin
Log('Need to abort download.');
Result := False;
end else begin
Expand Down Expand Up @@ -1002,7 +1003,7 @@ function TDownloadWizardPage.Download: Int64;
F: TDownloadFile;
I: Integer;
begin
FNeedToAbortDownload := False;
FAbortedByUser := False;

Result := 0;
for I := 0 to FFiles.Count-1 do begin
Expand Down
1 change: 1 addition & 0 deletions whatsnew.htm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<ul>
<li>Added new <tt>ItemFontStyle</tt> and <tt>SubItemFontStyle</tt> properties to the <tt>TNewCheckListBox</tt> support class. See the <i><a href="https://jrsoftware.github.io/issrc/Examples/CodeClasses.iss">CodeClasses.iss</a></i> example script for an example.</li>
<li>Added new <tt>IsMsiProductInstalled</tt> and <tt>StrToVersion</tt> support functions.</li>
<li>Added new <tt>AbortedByUser</tt> property to the <tt>TDownloadWizardPage</tt> support class.</li>
<li><i>Fix:</i> <tt>CreateDownloadPage</tt>'s progress bar now supports files larger than 2 GB.</li>
</ul>
</li>
Expand Down

0 comments on commit 312c0a4

Please sign in to comment.