mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-25 10:42:20 -05:00
Changed the updateform a bit.. Made Cancel button behave more noob-friendly, and added a speed label -> "Downloading at x kB/s". git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@425 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
1839f12c24
commit
8e617c9f35
@ -100,6 +100,7 @@ end;
|
|||||||
|
|
||||||
procedure TScriptFrame.SynEditDragDrop(Sender, Source: TObject; X, Y: Integer);
|
procedure TScriptFrame.SynEditDragDrop(Sender, Source: TObject; X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
|
if Source is TFunctionListFrame then
|
||||||
if TFunctionListFrame(Source).DraggingNode.Data <> nil then
|
if TFunctionListFrame(Source).DraggingNode.Data <> nil then
|
||||||
SynEdit.InsertTextAtCaret( GetMethodName(PChar(TFunctionListFrame(Source).DraggingNode.Data),true));
|
SynEdit.InsertTextAtCaret( GetMethodName(PChar(TFunctionListFrame(Source).DraggingNode.Data),true));
|
||||||
end;
|
end;
|
||||||
|
@ -14,7 +14,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
|
|||||||
object DownloadProgress: TProgressBar
|
object DownloadProgress: TProgressBar
|
||||||
Left = 24
|
Left = 24
|
||||||
Height = 28
|
Height = 28
|
||||||
Top = 72
|
Top = 64
|
||||||
Width = 413
|
Width = 413
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
Smooth = True
|
Smooth = True
|
||||||
@ -23,7 +23,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
|
|||||||
object UpdateButton: TButton
|
object UpdateButton: TButton
|
||||||
Left = 24
|
Left = 24
|
||||||
Height = 40
|
Height = 40
|
||||||
Top = 16
|
Top = 8
|
||||||
Width = 413
|
Width = 413
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
Caption = 'Update!'
|
Caption = 'Update!'
|
||||||
@ -33,7 +33,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
|
|||||||
object OkButton: TButton
|
object OkButton: TButton
|
||||||
Left = 362
|
Left = 362
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 344
|
Top = 352
|
||||||
Width = 75
|
Width = 75
|
||||||
Anchors = [akRight, akBottom]
|
Anchors = [akRight, akBottom]
|
||||||
Caption = 'Ok'
|
Caption = 'Ok'
|
||||||
@ -43,7 +43,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
|
|||||||
object CancelButton: TButton
|
object CancelButton: TButton
|
||||||
Left = 24
|
Left = 24
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 344
|
Top = 352
|
||||||
Width = 75
|
Width = 75
|
||||||
Anchors = [akLeft, akBottom]
|
Anchors = [akLeft, akBottom]
|
||||||
Caption = 'Cancel'
|
Caption = 'Cancel'
|
||||||
@ -53,9 +53,18 @@ object SimbaUpdateForm: TSimbaUpdateForm
|
|||||||
object UpdateLog: TMemo
|
object UpdateLog: TMemo
|
||||||
Left = 24
|
Left = 24
|
||||||
Height = 207
|
Height = 207
|
||||||
Top = 120
|
Top = 128
|
||||||
Width = 413
|
Width = 413
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
TabOrder = 4
|
TabOrder = 4
|
||||||
end
|
end
|
||||||
|
object DownloadSpeed: TLabel
|
||||||
|
Left = 24
|
||||||
|
Height = 14
|
||||||
|
Top = 104
|
||||||
|
Width = 78
|
||||||
|
Caption = 'DownloadSpeed'
|
||||||
|
ParentColor = False
|
||||||
|
Visible = False
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,17 +6,19 @@ LazarusResources.Add('TSimbaUpdateForm','FORMDATA',[
|
|||||||
+'BorderIcons'#11#12'biSystemMenu'#10'biMinimize'#0#7'Caption'#6#12'Update Si'
|
+'BorderIcons'#11#12'biSystemMenu'#10'biMinimize'#0#7'Caption'#6#12'Update Si'
|
||||||
+'mba'#12'ClientHeight'#3#135#1#11'ClientWidth'#3#211#1#8'OnCreate'#7#10'Form'
|
+'mba'#12'ClientHeight'#3#135#1#11'ClientWidth'#3#211#1#8'OnCreate'#7#10'Form'
|
||||||
+'Create'#6'OnShow'#7#15'CleanUpdateForm'#10'LCLVersion'#6#6'0.9.29'#0#12'TPr'
|
+'Create'#6'OnShow'#7#15'CleanUpdateForm'#10'LCLVersion'#6#6'0.9.29'#0#12'TPr'
|
||||||
+'ogressBar'#16'DownloadProgress'#4'Left'#2#24#6'Height'#2#28#3'Top'#2'H'#5'W'
|
+'ogressBar'#16'DownloadProgress'#4'Left'#2#24#6'Height'#2#28#3'Top'#2'@'#5'W'
|
||||||
+'idth'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#6'Smooth'#9#8'T'
|
+'idth'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#6'Smooth'#9#8'T'
|
||||||
+'abOrder'#2#0#0#0#7'TButton'#12'UpdateButton'#4'Left'#2#24#6'Height'#2'('#3
|
+'abOrder'#2#0#0#0#7'TButton'#12'UpdateButton'#4'Left'#2#24#6'Height'#2'('#3
|
||||||
+'Top'#2#16#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#7
|
+'Top'#2#8#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#7'C'
|
||||||
+'Caption'#6#7'Update!'#7'OnClick'#7#17'UpdateButtonClick'#8'TabOrder'#2#1#0#0
|
+'aption'#6#7'Update!'#7'OnClick'#7#17'UpdateButtonClick'#8'TabOrder'#2#1#0#0
|
||||||
+#7'TButton'#8'OkButton'#4'Left'#3'j'#1#6'Height'#2#25#3'Top'#3'X'#1#5'Width'
|
+#7'TButton'#8'OkButton'#4'Left'#3'j'#1#6'Height'#2#25#3'Top'#3'`'#1#5'Width'
|
||||||
+#2'K'#7'Anchors'#11#7'akRight'#8'akBottom'#0#7'Caption'#6#2'Ok'#7'OnClick'#7
|
+#2'K'#7'Anchors'#11#7'akRight'#8'akBottom'#0#7'Caption'#6#2'Ok'#7'OnClick'#7
|
||||||
+#13'OkButtonClick'#8'TabOrder'#2#2#0#0#7'TButton'#12'CancelButton'#4'Left'#2
|
+#13'OkButtonClick'#8'TabOrder'#2#2#0#0#7'TButton'#12'CancelButton'#4'Left'#2
|
||||||
+#24#6'Height'#2#25#3'Top'#3'X'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akB'
|
+#24#6'Height'#2#25#3'Top'#3'`'#1#5'Width'#2'K'#7'Anchors'#11#6'akLeft'#8'akB'
|
||||||
+'ottom'#0#7'Caption'#6#6'Cancel'#7'OnClick'#7#17'CancelButtonClick'#8'TabOrd'
|
+'ottom'#0#7'Caption'#6#6'Cancel'#7'OnClick'#7#17'CancelButtonClick'#8'TabOrd'
|
||||||
+'er'#2#3#0#0#5'TMemo'#9'UpdateLog'#4'Left'#2#24#6'Height'#3#207#0#3'Top'#2'x'
|
+'er'#2#3#0#0#5'TMemo'#9'UpdateLog'#4'Left'#2#24#6'Height'#3#207#0#3'Top'#3
|
||||||
+#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#8
|
+#128#0#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBott'
|
||||||
+'TabOrder'#2#4#0#0#0
|
+'om'#0#8'TabOrder'#2#4#0#0#6'TLabel'#13'DownloadSpeed'#4'Left'#2#24#6'Height'
|
||||||
|
+#2#14#3'Top'#2'h'#5'Width'#2'N'#7'Caption'#6#13'DownloadSpeed'#11'ParentColo'
|
||||||
|
+'r'#8#7'Visible'#8#0#0#0
|
||||||
]);
|
]);
|
@ -22,6 +22,7 @@ type
|
|||||||
procedure Execute; override;
|
procedure Execute; override;
|
||||||
end;
|
end;
|
||||||
TSimbaUpdateForm = class(TForm)
|
TSimbaUpdateForm = class(TForm)
|
||||||
|
DownloadSpeed: TLabel;
|
||||||
UpdateLog: TMemo;
|
UpdateLog: TMemo;
|
||||||
UpdateButton: TButton;
|
UpdateButton: TButton;
|
||||||
OkButton: TButton;
|
OkButton: TButton;
|
||||||
@ -38,8 +39,12 @@ type
|
|||||||
{ private declarations }
|
{ private declarations }
|
||||||
|
|
||||||
Updater: TMMLFileDownloader;
|
Updater: TMMLFileDownloader;
|
||||||
|
FStartTime : longword;
|
||||||
FCancelling: Boolean;
|
FCancelling: Boolean;
|
||||||
FDone: Boolean;
|
FDone: Boolean;
|
||||||
|
FUpdating : boolean;
|
||||||
|
FOldSpeed : integer;
|
||||||
|
FLastUpdateSpeed : longword;
|
||||||
FSimbaVersion: Integer;
|
FSimbaVersion: Integer;
|
||||||
SimbaVersionThread : TSimbaVersionThread;
|
SimbaVersionThread : TSimbaVersionThread;
|
||||||
private
|
private
|
||||||
@ -52,6 +57,9 @@ type
|
|||||||
FCancelled: Boolean;
|
FCancelled: Boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
const
|
||||||
|
DownloadSpeedTextRunning = 'Downloading at %d kB/s';
|
||||||
|
DownloadSpeedTextEnded = 'Downloaded at %d kB/s';
|
||||||
|
|
||||||
var
|
var
|
||||||
SimbaUpdateForm: TSimbaUpdateForm;
|
SimbaUpdateForm: TSimbaUpdateForm;
|
||||||
@ -59,7 +67,7 @@ var
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
internets, TestUnit, simbasettings;
|
internets, TestUnit, simbasettings,lclintf;
|
||||||
|
|
||||||
function TSimbaUpdateForm.CanUpdate: Boolean;
|
function TSimbaUpdateForm.CanUpdate: Boolean;
|
||||||
begin
|
begin
|
||||||
@ -104,6 +112,9 @@ end;
|
|||||||
|
|
||||||
procedure TSimbaUpdateForm.UpdateButtonClick(Sender: TObject);
|
procedure TSimbaUpdateForm.UpdateButtonClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
if FUpdating then
|
||||||
|
UpdateLog.Lines.Add('Already performing an update!')
|
||||||
|
else
|
||||||
Self.PerformUpdate;
|
Self.PerformUpdate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -124,11 +135,14 @@ begin
|
|||||||
Self.DownloadProgress.Position:=0;
|
Self.DownloadProgress.Position:=0;
|
||||||
Self.UpdateLog.Clear;
|
Self.UpdateLog.Clear;
|
||||||
Self.UpdateLog.Lines.Add('---------- Update Session ----------');
|
Self.UpdateLog.Lines.Add('---------- Update Session ----------');
|
||||||
|
Self.DownloadSpeed.Visible:= false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSimbaUpdateForm.FormCreate(Sender: TObject);
|
procedure TSimbaUpdateForm.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FDone := True;
|
FDone := True;
|
||||||
|
FUpdating:= false;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSimbaUpdateForm.OkButtonClick(Sender: TObject);
|
procedure TSimbaUpdateForm.OkButtonClick(Sender: TObject);
|
||||||
@ -141,19 +155,29 @@ end;
|
|||||||
function TSimbaUpdateForm.OnUpdateBeat: Boolean;
|
function TSimbaUpdateForm.OnUpdateBeat: Boolean;
|
||||||
var
|
var
|
||||||
Percentage: Integer;
|
Percentage: Integer;
|
||||||
|
NewSpeed : integer;
|
||||||
begin
|
begin
|
||||||
Application.ProcessMessages;
|
Application.ProcessMessages;
|
||||||
|
|
||||||
Percentage := Updater.GetPercentage();
|
Percentage := Updater.GetPercentage();
|
||||||
if Percentage <> -1 then
|
if Percentage <> -1 then
|
||||||
DownloadProgress.Position:=Percentage;
|
DownloadProgress.Position:=Percentage;
|
||||||
|
// Formula for speed (kB/s) -> (Bytes div 1000) / (MSecSinceStart div 1000) = Bytes/ MSecSinceStart
|
||||||
|
NewSpeed :=(Updater.DownloadedSize) div ((GetTickCount-FStartTime));
|
||||||
|
if abs(NewSpeed - FOldSpeed) > 1 then
|
||||||
|
if (GetTickCount - FLastUpdateSpeed) > 1000 then //Only update the speed text every second
|
||||||
|
begin;
|
||||||
|
FOldSpeed:= NewSpeed;
|
||||||
|
DownloadSpeed.Caption:= Format(DownloadSpeedTextRunning,[NewSpeed]);
|
||||||
|
FLastUpdateSpeed:= GetTickCount;
|
||||||
|
end;
|
||||||
Result := FCancelling;
|
Result := FCancelling;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSimbaUpdateForm.PerformUpdate;
|
procedure TSimbaUpdateForm.PerformUpdate;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
FUpdating:= True;
|
||||||
Updater := TMMLFileDownloader.Create;
|
Updater := TMMLFileDownloader.Create;
|
||||||
|
|
||||||
FDone := False;
|
FDone := False;
|
||||||
@ -176,24 +200,30 @@ begin
|
|||||||
Self.UpdateLog.Lines.Add('Starting download of ' + Updater.FileURL + ' ...');
|
Self.UpdateLog.Lines.Add('Starting download of ' + Updater.FileURL + ' ...');
|
||||||
try
|
try
|
||||||
Self.OkButton.Enabled := False; // grey out button
|
Self.OkButton.Enabled := False; // grey out button
|
||||||
|
DownloadSpeed.Visible:= true;
|
||||||
|
DownloadSpeed.Caption:= Format(DownloadSpeedTextRunning,[0]);
|
||||||
|
FStartTime:= GetTickCount - 1;//Be sure that we don't get div 0
|
||||||
Updater.DownloadAndSave;
|
Updater.DownloadAndSave;
|
||||||
|
DownloadSpeed.Caption := Format(DownloadSpeedTextEnded,[Updater.FileSize div (GetTickCount-FStartTime)]);
|
||||||
Self.UpdateLog.Lines.Add('Downloaded to ' + Updater.ReplacementFile + '_ ...');
|
Self.UpdateLog.Lines.Add('Downloaded to ' + Updater.ReplacementFile + '_ ...');
|
||||||
Updater.Replace;
|
Updater.Replace;
|
||||||
Self.UpdateLog.Lines.Add('Renaming ' + Updater.ReplacementFile + ' to ' + Updater.ReplacementFile + '_old_');
|
Self.UpdateLog.Lines.Add('Renaming ' + Updater.ReplacementFile + ' to ' + Updater.ReplacementFile + '_old_');
|
||||||
Self.UpdateLog.Lines.Add('Renaming ' + Updater.ReplacementFile + '_ to ' + Updater.ReplacementFile);
|
Self.UpdateLog.Lines.Add('Renaming ' + Updater.ReplacementFile + '_ to ' + Updater.ReplacementFile);
|
||||||
Self.UpdateLog.Lines.Add('Deleting ' + Updater.ReplacementFile + '_old_');
|
Self.UpdateLog.Lines.Add('Deleting ' + Updater.ReplacementFile + '_old_');
|
||||||
Updater.Free;
|
Updater.Free;
|
||||||
|
Self.UpdateLog.Lines.Add('Done ... ');
|
||||||
|
Self.UpdateLog.Lines.Add('Please restart all currently running Simba binaries.');
|
||||||
except
|
except
|
||||||
FCancelling := False;
|
FCancelling := False;
|
||||||
FCancelled := True;
|
FCancelled := True;
|
||||||
Self.UpdateLog.Lines.Add('Download stopped ...');
|
DownloadSpeed.Visible:= false;
|
||||||
|
Self.UpdateLog.Lines.Add('Download stopped at '+inttostr(DownloadProgress.Position)+'%... Simba did not succesfully update.');
|
||||||
// more detailed info
|
// more detailed info
|
||||||
writeln('EXCEPTION IN UPDATEFORM: We either hit Cancel, or something went wrong with files');
|
writeln('EXCEPTION IN UPDATEFORM: We either hit Cancel, or something went wrong with files');
|
||||||
end;
|
end;
|
||||||
FDone := True;
|
FDone := True;
|
||||||
Self.UpdateLog.Lines.Add('Done ... ');
|
|
||||||
Self.UpdateLog.Lines.Add('Please restart all currently running Simba binaries.');
|
|
||||||
Self.OkButton.Enabled := True; // un-grey out button
|
Self.OkButton.Enabled := True; // un-grey out button
|
||||||
|
FUpdating:= false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSimbaVersionThread }
|
{ TSimbaVersionThread }
|
||||||
|
@ -66,6 +66,8 @@ type
|
|||||||
{ Called every 50ms }
|
{ Called every 50ms }
|
||||||
property OnBeat: TMMLFunctionBoolean read FOnBeat write FOnBeat;
|
property OnBeat: TMMLFunctionBoolean read FOnBeat write FOnBeat;
|
||||||
|
|
||||||
|
property DownloadedSize : Integer read FTotal;
|
||||||
|
property FileSize : integer read FFileSize;
|
||||||
function GetPercentage: Integer;
|
function GetPercentage: Integer;
|
||||||
private
|
private
|
||||||
procedure TryToGetFileSize;
|
procedure TryToGetFileSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user