1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 17:22:21 -05:00

New SRL Updater with form.

This commit is contained in:
Merlijn Wajer 2010-07-15 17:42:48 +02:00
parent d9446e998c
commit 3358e8806d

View File

@ -4,6 +4,11 @@ var
started: Boolean; started: Boolean;
Timer : TTimer; Timer : TTimer;
Updating : boolean; Updating : boolean;
LocalP,LocalS,OnlineP,OnlineS: Integer;
F: TForm;
Memo: TMemo;
but: TButton;
function GetNumbers(const str : string) : string; function GetNumbers(const str : string) : string;
@ -28,26 +33,17 @@ begin
SRLVersion := StrToIntDef(Settings.GetKeyValueDef('SRLVersion','-1'),-1); SRLVersion := StrToIntDef(Settings.GetKeyValueDef('SRLVersion','-1'),-1);
end; end;
function UpdateSRL : boolean; function UpdatePlugins: Boolean;
var var
LocalP,LocalS,OnlineP,OnlineS,I : integer; I : integer;
Contents : String; Contents : String;
DeContents : string; DeContents : string;
Files : TStringArray; Files : TStringArray;
Failed,OverWrite : boolean; Failed,OverWrite : boolean;
begin begin
Result := false; Memo.Lines.Add('Downloading the plugins...');
if Updating then
exit;
Updating := True;
GetLocalVersion(LocalP,LocalS);
GetOnlineVersion(OnlineP,OnlineS);
Result := True;
if (OnlineP > LocalP) then
begin
Writeln('New plugin(s) are available.');
Writeln('Downloading the new plugins now. Please do not close Simba.');
Contents := GetPage('http://wizzup.org/static/srl/simba_plugins.tar.bz2'); Contents := GetPage('http://wizzup.org/static/srl/simba_plugins.tar.bz2');
Memo.Lines.Add('Uncompressing the plugins...');
Failed := True; Failed := True;
if DecompressBZip2(Contents,DeContents,4096) then if DecompressBZip2(Contents,DeContents,4096) then
if ForceDirectories(IncludePath + 'SRL/SimbaPlugins/') then if ForceDirectories(IncludePath + 'SRL/SimbaPlugins/') then
@ -69,21 +65,32 @@ begin
Failed := not UnTarEx(DeContents,PluginPath,false); Failed := not UnTarEx(DeContents,PluginPath,false);
end; end;
if Failed then if Failed then
Writeln('Somehow failed to update the plugins') begin
Writeln('Failed to update the plugins');
Memo.Lines.Add('Failed to update the plugins');
end
else else
Writeln('Succesfully updated your plugins!'); begin
Writeln('Succesfully updated your plugins.');
Memo.Lines.Add('Succesfully updated your plugins.');
end;
DeContents := ''; DeContents := '';
Contents := ''; Contents := '';
Result := Failed; Result := Failed;
if not Failed then if not Failed then
Settings.SetKeyValue('PluginsVersion',inttostr(OnlineP)); Settings.SetKeyValue('PluginsVersion',inttostr(OnlineP));
end; end;
if (OnlineS > LocalS) then
function UpdateSRL: boolean;
var
Contents : String;
DeContents : string;
Failed : boolean;
begin begin
Writeln('SRL is outdated, updating now!'); Memo.Lines.Add('Downloading SRL...');
Writeln('Downloading the new SRL now. Please do not close Simba.');
Contents := GetPage('http://wizzup.org/static/srl/srl.tar.bz2'); Contents := GetPage('http://wizzup.org/static/srl/srl.tar.bz2');
Failed := True; Failed := True;
Memo.Lines.Add('Uncompressing SRL...');
if DecompressBZip2(Contents,DeContents,4096) then if DecompressBZip2(Contents,DeContents,4096) then
if UnTarEx(DeContents,IncludePath,true) then if UnTarEx(DeContents,IncludePath,true) then
Failed := False; Failed := False;
@ -92,9 +99,66 @@ begin
if Result then if Result then
Result := Failed; Result := Failed;
if not Failed then if not Failed then
begin
Memo.Lines.Add('Succesfully updated your SRL!');
Writeln('Succesfully updated your SRL!'); Writeln('Succesfully updated your SRL!');
end; end;
end;
procedure DoUpdate(Sender: TObject);
begin
if LocalP < OnlineP then
begin
Memo.Lines.Add('Plugins update. Old version: ' + IntToStr(LocalP) +
' New version: ' + IntToStr(OnlineP));
UpdatePlugins;
end;
if LocalS < OnlineS then
begin
Memo.Lines.Add('SRL update. Old version: ' + IntToStr(LocalS) +
' New version: ' + IntToStr(OnlineS));
UpdateSRL;
end;
F.ModalResult := mrOk;
end;
function Update : boolean;
var
OpenForm: Boolean;
begin
Result := false;
if Updating then
Exit;
Updating := True;
GetLocalVersion(LocalP,LocalS);
GetOnlineVersion(OnlineP,OnlineS);
if (LocalP < OnlineP) or (LocalS < OnlineS) then
begin
case MessageDlg('SRL Updater', 'Updates are available. '+
'Do you want to open the Updater now?',
mtConfirmation, [mbNo,mbYes],0) of
mrYes : OpenForm := True;
else
OpenForm := False;
end;
if not OpenForm then
begin
Updating := False; Updating := False;
Exit;
end;
Result := True;
f.ShowModal;
end else
begin
MessageDlg('SRL Updater', 'No SRL update / Plugins update available!' ,mtConfirmation, [mbYes],0);
writeln('No SRL update / Plugins update available!');
end;
Updating := False;
end; end;
procedure OnSRLCheckClick(Sender: TObject); procedure OnSRLCheckClick(Sender: TObject);
@ -104,23 +168,30 @@ begin
GetLocalVersion(LocalP,LocalS); GetLocalVersion(LocalP,LocalS);
GetOnlineVersion(OnlineP,OnlineS); GetOnlineVersion(OnlineP,OnlineS);
if (OnlineP > LocalP) or (OnlineS > LocalS) then if (OnlineP > LocalP) or (OnlineS > LocalS) then
begin;
Writeln('A new SRL version is available'); Writeln('A new SRL version is available');
Update;
end;
end; end;
procedure SetAutoUpdate(Sender: TObject); procedure SetAutoUpdate(Sender: TObject);
begin begin
AutoUpdate.Checked := not AutoUpdate.Checked; AutoUpdate.Checked := not AutoUpdate.Checked;
Timer.Enabled := AutoUpdate.Checked; Timer.Enabled := AutoUpdate.Checked;
if LowerCase(Settings.GetKeyValueDef('AutoUpdate','True')) = 'true' then
Settings.SetKeyValue('AutoUpdate', 'False')
else
Settings.SetKeyValue('AutoUpdate', 'True');
end; end;
procedure OnSRLUpdateClick(Sender: TObject); procedure OnSRLUpdateClick(Sender: TObject);
begin begin
UpdateSRL; Update;
end; end;
procedure OnUpdateTimer(Sender: TObject); procedure OnUpdateTimer(Sender: TObject);
begin; begin;
Timer.Interval := 30 * 60 * 1000; //Every half hour Timer.Interval := 30 * 60 * 1000; //Every half hour
UpdateSRL; Update;
end; end;
procedure Init; procedure Init;
@ -150,6 +221,40 @@ begin;
Timer.OnTimer := @OnUpdateTimer; Timer.OnTimer := @OnUpdateTimer;
Timer.Enabled :=AutoUpdate.Checked; Timer.Enabled :=AutoUpdate.Checked;
F := TForm.Create(nil);
With F Do
begin
Visible := False;
Width := 300;
Height := 300;
BorderStyle := bsSingle;
Caption := 'SRL Updater - Updates Available';
end;
but := TButton.Create(F);
with but do
begin
Parent := F;
Left := 10;
Top := 10;
Caption := 'Update';
Width := 280;
OnClick := @DoUpdate;
end;
Memo := TMemo.Create(F);
with Memo do
begin
Parent := F;
Left := 10;
Top := 40;
Width := 280;
Height := 250;
end;
started := True; started := True;
end; end;
@ -157,7 +262,8 @@ procedure Free;
begin begin
if (started) then if (started) then
Timer.Enabled := False;//Freeing the components is not needed, as they will be freed upon the freeing of Simba. Timer.Enabled := False;//Freeing the components is not needed, as they will be freed upon the freeing of Simba.
if F <> nil then
F.Free;
end; end;
procedure Attach; procedure Attach;