Refs #130. Keep Microboot open when cancel is clicked.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@192 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
Frank Voorburg 2016-12-17 10:40:29 +00:00
parent 5168861331
commit 18090ed664
4 changed files with 66 additions and 30 deletions

Binary file not shown.

Binary file not shown.

View File

@ -82,6 +82,7 @@ type
StopWatch : TStopWatch; StopWatch : TStopWatch;
StayOpen : Boolean; StayOpen : Boolean;
FormCaption : string; FormCaption : string;
DownloadInProgress: Boolean;
procedure OnMbiStarted(length: Longword); procedure OnMbiStarted(length: Longword);
procedure OnMbiProgress(progress: Longword); procedure OnMbiProgress(progress: Longword);
procedure OnMbiDone; procedure OnMbiDone;
@ -90,6 +91,7 @@ type
procedure OnMbiInfo(info: ShortString); procedure OnMbiInfo(info: ShortString);
procedure StartFileDownload(fileName : ShortString); procedure StartFileDownload(fileName : ShortString);
procedure UpdateInterfaceLabel; procedure UpdateInterfaceLabel;
procedure ResetUserInterface;
public public
{ Public declarations } { Public declarations }
function IsMbiInterface(libFile : string) : Boolean; function IsMbiInterface(libFile : string) : Boolean;
@ -156,15 +158,13 @@ end; //*** end of OnMbiProgress ***
//*************************************************************************************** //***************************************************************************************
procedure TmainForm.OnMbiDone; procedure TmainForm.OnMbiDone;
begin begin
DownloadInProgress := False; // reset flag
Timer.Enabled := false; // stop the timer Timer.Enabled := false; // stop the timer
StopWatch.Stop; // stop the stopwatch StopWatch.Stop; // stop the stopwatch
mainForm.Caption := FormCaption; // restore caption mainForm.Caption := FormCaption; // restore caption
if StayOpen then if StayOpen then
begin ResetUserInterface // reset the user interface to allow a new download to be started
NtbPages.PageIndex := 0; // go to the next page
btnSettings.Enabled := true; // settings can't be changed anymore
end
else else
Close; // done so close the application Close; // done so close the application
end; //*** end of OnMbiDone *** end; //*** end of OnMbiDone ***
@ -180,18 +180,12 @@ end; //*** end of OnMbiDone ***
//*************************************************************************************** //***************************************************************************************
procedure TmainForm.OnMbiError(error: ShortString); procedure TmainForm.OnMbiError(error: ShortString);
begin begin
DownloadInProgress := False; // reset flag
ShowMessage(String(error)); // display error ShowMessage(String(error)); // display error
Timer.Enabled := false; // stop the timer Timer.Enabled := false; // stop the timer
StopWatch.Stop; // stop the stopwatch StopWatch.Stop; // stop the stopwatch
mainForm.Caption := FormCaption; // restore caption mainForm.Caption := FormCaption; // restore caption
ResetUserInterface; // download failed so reset user interface for retry
if StayOpen then
begin
NtbPages.PageIndex := 0; // go to the next page
btnSettings.Enabled := true; // settings can't be changed anymore
end
else
Close; // can't continue so close the application
end; //*** end of OnMbiError *** end; //*** end of OnMbiError ***
@ -411,12 +405,13 @@ procedure TmainForm.StartFileDownload(fileName : ShortString);
begin begin
if FileExists(String(fileName)) and (MbiInterfaced = True) then if FileExists(String(fileName)) and (MbiInterfaced = True) then
begin begin
FormCaption := mainForm.Caption; // backup original caption
mainForm.Caption := FormCaption + ' - Downloading ' + mainForm.Caption := FormCaption + ' - Downloading ' +
ExtractFileName(String(fileName)) + '...'; ExtractFileName(String(fileName)) + '...';
prgDownload.Position := 0; // reset the progress bar prgDownload.Position := 0; // reset the progress bar
NtbPages.PageIndex := 1; // go to the next page NtbPages.PageIndex := 1; // go to the next page
btnSettings.Enabled := false; // settings can't be changed anymore btnSettings.Enabled := false; // settings can't be changed anymore
btnCancel.Caption := 'Cancel'; // change caption to cancel download
DownloadInProgress := True; // set flag
MbiInterface.Download(fileName); MbiInterface.Download(fileName);
end; end;
end; //*** end of StartFileDownload *** end; //*** end of StartFileDownload ***
@ -444,6 +439,35 @@ begin
end; //*** end of UpdateInterfaceLabel *** end; //*** end of UpdateInterfaceLabel ***
//***************************************************************************************
// NAME:
// PARAMETER: none
// RETURN VALUE: none
// DESCRIPTION: Resets the user interface to the default state, which is the state
// when the program is started for the first time.
//
//***************************************************************************************
procedure TmainForm.ResetUserInterface;
begin
// stop the timer
Timer.Enabled := False;
// stop the stopwatch
StopWatch.Stop;
// restore form caption
mainForm.Caption := FormCaption;
// clear download file
edtDownloadFile.Text := '';
// go to the default page
NtbPages.PageIndex := 0;
// enable settings button
btnSettings.Enabled := True;
// change caption to exit program
btnCancel.Caption := 'Exit';
// empty elapsted time label
lblElapsedTime.Caption := '';
end; //*** end of ResetUserInterface ***
//*************************************************************************************** //***************************************************************************************
// NAME: btnCancelClick // NAME: btnCancelClick
// PARAMETER: none // PARAMETER: none
@ -459,7 +483,11 @@ begin
MbiInterface.Cancel; MbiInterface.Cancel;
end; end;
Close; // no download in progress so just close the program
if not DownloadInProgress then
begin
Close;
end
end; //*** end of btnCancelClick *** end; //*** end of btnCancelClick ***
@ -479,6 +507,9 @@ var
winRegistry : TRegistry; winRegistry : TRegistry;
libFileList : TStrings; libFileList : TStrings;
begin begin
btnCancel.Caption := 'Exit'; // change caption to exit program
DownloadInProgress := False; // init flag
FormCaption := mainForm.Caption; // backup original caption
LogLines := TStringList.Create; LogLines := TStringList.Create;
StayOpen := false; StayOpen := false;
MbiLogging := false; MbiLogging := false;
@ -502,20 +533,19 @@ begin
end; end;
end; end;
// this feature is unstable so do not yet support it in a release version
// determine if tool should stay open after a download completion // determine if tool should stay open after a download completion
//if (ParamCount > 0) then if (ParamCount > 0) then
//begin begin
// // no options will be in Param 0 // no options will be in Param 0
// for cnt := 1 to ParamCount do for cnt := 1 to ParamCount do
// begin begin
// // look for -l option // look for -s option
// if System.Pos('-s', ParamStr(cnt)) > 0 then if System.Pos('-s', ParamStr(cnt)) > 0 then
// begin begin
// StayOpen := True; StayOpen := True;
// end; end;
// end; end;
//end; end;
// determine what interface library to use on startup // determine what interface library to use on startup
// 1) -------- From commandline parameter --------------- // 1) -------- From commandline parameter ---------------
@ -648,7 +678,7 @@ begin
// no options will be in Param 0 // no options will be in Param 0
for cnt := 1 to ParamCount do for cnt := 1 to ParamCount do
begin begin
// look for -i option // look for -p option
if System.Pos('-p', ParamStr(cnt)) > 0 then if System.Pos('-p', ParamStr(cnt)) > 0 then
begin begin
if OpenDialog.Execute then if OpenDialog.Execute then
@ -727,6 +757,12 @@ begin
begin begin
LogLines.SaveToFile(ExePath + 'log.txt'); LogLines.SaveToFile(ExePath + 'log.txt');
end; end;
// pass on cancel request to the library if a download is in progress
if MbiInterfaced = True then
begin
MbiInterface.Cancel;
end;
end; //*** end of FormClose *** end; //*** end of FormClose ***

View File

@ -84,8 +84,8 @@
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames> <DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''"> <PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_MinorVer>2</VerInfo_MinorVer> <VerInfo_MinorVer>3</VerInfo_MinorVer>
<VerInfo_Keys>CompanyName=Feaser;FileDescription=PC download tool for the OpenBLT bootloader;FileVersion=1.2.0.0;InternalName=;LegalCopyright=Feaser;LegalTrademarks=;OriginalFilename=;ProductName=MicroBoot;ProductVersion=1.2.0.0;Comments=</VerInfo_Keys> <VerInfo_Keys>CompanyName=Feaser;FileDescription=PC download tool for the OpenBLT bootloader;FileVersion=1.3.0.0;InternalName=;LegalCopyright=Feaser;LegalTrademarks=;OriginalFilename=;ProductName=MicroBoot;ProductVersion=1.3.0.0;Comments=</VerInfo_Keys>
<AppEnableHighDPI>true</AppEnableHighDPI> <AppEnableHighDPI>true</AppEnableHighDPI>
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes> <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
<VerInfo_Locale>1033</VerInfo_Locale> <VerInfo_Locale>1033</VerInfo_Locale>