1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-21 16:55:01 -05:00

Fixed #63 (and #64).

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:
Raymond 2010-01-18 11:52:02 +00:00
parent 1839f12c24
commit 8e617c9f35
5 changed files with 66 additions and 22 deletions

View File

@ -100,8 +100,9 @@ end;
procedure TScriptFrame.SynEditDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
if TFunctionListFrame(Source).DraggingNode.Data <> nil then
SynEdit.InsertTextAtCaret( GetMethodName(PChar(TFunctionListFrame(Source).DraggingNode.Data),true));
if Source is TFunctionListFrame then
if TFunctionListFrame(Source).DraggingNode.Data <> nil then
SynEdit.InsertTextAtCaret( GetMethodName(PChar(TFunctionListFrame(Source).DraggingNode.Data),true));
end;
procedure TScriptFrame.SynEditDragOver(Sender, Source: TObject; X, Y: Integer;

View File

@ -14,7 +14,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
object DownloadProgress: TProgressBar
Left = 24
Height = 28
Top = 72
Top = 64
Width = 413
Anchors = [akTop, akLeft, akRight]
Smooth = True
@ -23,7 +23,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
object UpdateButton: TButton
Left = 24
Height = 40
Top = 16
Top = 8
Width = 413
Anchors = [akTop, akLeft, akRight]
Caption = 'Update!'
@ -33,7 +33,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
object OkButton: TButton
Left = 362
Height = 25
Top = 344
Top = 352
Width = 75
Anchors = [akRight, akBottom]
Caption = 'Ok'
@ -43,7 +43,7 @@ object SimbaUpdateForm: TSimbaUpdateForm
object CancelButton: TButton
Left = 24
Height = 25
Top = 344
Top = 352
Width = 75
Anchors = [akLeft, akBottom]
Caption = 'Cancel'
@ -53,9 +53,18 @@ object SimbaUpdateForm: TSimbaUpdateForm
object UpdateLog: TMemo
Left = 24
Height = 207
Top = 120
Top = 128
Width = 413
Anchors = [akTop, akLeft, akRight, akBottom]
TabOrder = 4
end
object DownloadSpeed: TLabel
Left = 24
Height = 14
Top = 104
Width = 78
Caption = 'DownloadSpeed'
ParentColor = False
Visible = False
end
end

View File

@ -6,17 +6,19 @@ LazarusResources.Add('TSimbaUpdateForm','FORMDATA',[
+'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'
+'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'
+'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
+'Caption'#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'
+'Top'#2#8#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#7'C'
+'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'`'#1#5'Width'
+#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
+#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'
+'er'#2#3#0#0#5'TMemo'#9'UpdateLog'#4'Left'#2#24#6'Height'#3#207#0#3'Top'#2'x'
+#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#8
+'TabOrder'#2#4#0#0#0
]);
+'er'#2#3#0#0#5'TMemo'#9'UpdateLog'#4'Left'#2#24#6'Height'#3#207#0#3'Top'#3
+#128#0#5'Width'#3#157#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBott'
+'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
]);

View File

@ -22,6 +22,7 @@ type
procedure Execute; override;
end;
TSimbaUpdateForm = class(TForm)
DownloadSpeed: TLabel;
UpdateLog: TMemo;
UpdateButton: TButton;
OkButton: TButton;
@ -38,8 +39,12 @@ type
{ private declarations }
Updater: TMMLFileDownloader;
FStartTime : longword;
FCancelling: Boolean;
FDone: Boolean;
FUpdating : boolean;
FOldSpeed : integer;
FLastUpdateSpeed : longword;
FSimbaVersion: Integer;
SimbaVersionThread : TSimbaVersionThread;
private
@ -52,6 +57,9 @@ type
FCancelled: Boolean;
end;
const
DownloadSpeedTextRunning = 'Downloading at %d kB/s';
DownloadSpeedTextEnded = 'Downloaded at %d kB/s';
var
SimbaUpdateForm: TSimbaUpdateForm;
@ -59,7 +67,7 @@ var
implementation
uses
internets, TestUnit, simbasettings;
internets, TestUnit, simbasettings,lclintf;
function TSimbaUpdateForm.CanUpdate: Boolean;
begin
@ -104,7 +112,10 @@ end;
procedure TSimbaUpdateForm.UpdateButtonClick(Sender: TObject);
begin
Self.PerformUpdate;
if FUpdating then
UpdateLog.Lines.Add('Already performing an update!')
else
Self.PerformUpdate;
end;
procedure TSimbaUpdateForm.CancelButtonClick(Sender: TObject);
@ -124,11 +135,14 @@ begin
Self.DownloadProgress.Position:=0;
Self.UpdateLog.Clear;
Self.UpdateLog.Lines.Add('---------- Update Session ----------');
Self.DownloadSpeed.Visible:= false;
end;
procedure TSimbaUpdateForm.FormCreate(Sender: TObject);
begin
FDone := True;
FUpdating:= false;
end;
procedure TSimbaUpdateForm.OkButtonClick(Sender: TObject);
@ -141,19 +155,29 @@ end;
function TSimbaUpdateForm.OnUpdateBeat: Boolean;
var
Percentage: Integer;
NewSpeed : integer;
begin
Application.ProcessMessages;
Percentage := Updater.GetPercentage();
if Percentage <> -1 then
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;
end;
procedure TSimbaUpdateForm.PerformUpdate;
begin
FUpdating:= True;
Updater := TMMLFileDownloader.Create;
FDone := False;
@ -176,24 +200,30 @@ begin
Self.UpdateLog.Lines.Add('Starting download of ' + Updater.FileURL + ' ...');
try
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;
DownloadSpeed.Caption := Format(DownloadSpeedTextEnded,[Updater.FileSize div (GetTickCount-FStartTime)]);
Self.UpdateLog.Lines.Add('Downloaded to ' + Updater.ReplacementFile + '_ ...');
Updater.Replace;
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('Deleting ' + Updater.ReplacementFile + '_old_');
Updater.Free;
Self.UpdateLog.Lines.Add('Done ... ');
Self.UpdateLog.Lines.Add('Please restart all currently running Simba binaries.');
except
FCancelling := False;
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
writeln('EXCEPTION IN UPDATEFORM: We either hit Cancel, or something went wrong with files');
end;
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
FUpdating:= false;
end;
{ TSimbaVersionThread }

View File

@ -66,6 +66,8 @@ type
{ Called every 50ms }
property OnBeat: TMMLFunctionBoolean read FOnBeat write FOnBeat;
property DownloadedSize : Integer read FTotal;
property FileSize : integer read FFileSize;
function GetPercentage: Integer;
private
procedure TryToGetFileSize;