1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-26 01:09:08 -05:00
Simba/Extensions/srl.sex

298 lines
7.3 KiB
Plaintext
Raw Normal View History

2010-04-16 10:08:41 -04:00
program SRLUpdater;
var
MainMenuItem, MenuCheck, MenuUpdate,AutoUpdate : TMenuItem;
started: Boolean;
Timer : TTimer;
Updating : boolean;
2010-07-15 11:42:48 -04:00
LocalP,LocalS,OnlineP,OnlineS: Integer;
F: TForm;
Memo: TMemo;
but: TButton;
2010-04-16 10:08:41 -04:00
function GetNumbers(const str : string) : string;
var
i : integer;
begin;
for i := 1 to length(str) do
case str[i] of
'0'..'9': result := result + str[i];
end;
end;
procedure GetOnlineVersion(out PluginsVersion,SRLVersion : integer);
begin
PluginsVersion := strtointdef(GetNumbers(getpage('http://wizzup.org/static/srl/plugins_version')),-1);
SRLVersion := strtointdef(GetNumbers(getpage('http://wizzup.org/static/srl/srl_version')),-1);
end;
procedure GetLocalVersion(out PluginsVersion,SRLVersion : integer);
begin
PluginsVersion := StrToIntDef(Settings.GetKeyValueDef('PluginsVersion','-1'),-1);
SRLVersion := StrToIntDef(Settings.GetKeyValueDef('SRLVersion','-1'),-1);
end;
2010-07-15 11:42:48 -04:00
function UpdatePlugins: Boolean;
2010-04-16 10:08:41 -04:00
var
2010-07-15 11:42:48 -04:00
I : integer;
2010-04-16 10:08:41 -04:00
Contents : String;
DeContents : string;
Files : TStringArray;
Failed,OverWrite : boolean;
begin
2010-07-15 11:42:48 -04:00
Memo.Lines.Add('Downloading the plugins...');
2010-04-16 10:08:41 -04:00
Contents := GetPage('http://wizzup.org/static/srl/simba_plugins.tar.bz2');
2010-07-15 11:42:48 -04:00
Memo.Lines.Add('Uncompressing the plugins...');
2010-04-16 10:08:41 -04:00
Failed := True;
if DecompressBZip2(Contents,DeContents,4096) then
if ForceDirectories(IncludePath + 'SRL/SimbaPlugins/') then
if UnTarEx(DeContents,IncludePath + 'SRL/SimbaPlugins/',true) then
begin;
Files := GetFiles(IncludePath + 'SRL/SimbaPlugins/','dll');
for i := 0 to high(Files) do
if FileExists(PluginPath + Files[i]) then
OverWrite := True;
if OverWrite then
begin;
case MessageDlg('SRL Updater', 'Do you want to overwrite the plugins?' ,mtConfirmation, [mbNo,mbYes],0) of
mrYes : Failed := not UnTarEx(DeContents,PluginPath,True)
else
Failed := not UnTarEx(DeContents,PluginPath,false);
end;
Writeln('A restart is necessary to activate the new plugins.');
end else
Failed := not UnTarEx(DeContents,PluginPath,false);
end;
if Failed then
2010-07-15 20:10:01 -04:00
begin
2010-07-15 11:42:48 -04:00
Writeln('Failed to update the plugins');
2010-07-15 20:10:01 -04:00
Memo.Lines.Add('Failed to update the plugins');
end
2010-04-16 10:08:41 -04:00
else
2010-07-15 20:10:01 -04:00
begin
2010-07-15 11:42:48 -04:00
Writeln('Succesfully updated your plugins.');
2010-07-15 20:10:01 -04:00
Memo.Lines.Add('Succesfully updated your plugins.');
end;
2010-04-16 10:08:41 -04:00
DeContents := '';
Contents := '';
Result := Failed;
if not Failed then
Settings.SetKeyValue('PluginsVersion',inttostr(OnlineP));
2010-07-15 11:42:48 -04:00
end;
function UpdateSRL: boolean;
var
Contents : String;
DeContents : string;
Failed : boolean;
begin
2010-07-15 20:10:01 -04:00
Memo.Lines.Add('Downloading SRL...');
2010-04-16 10:08:41 -04:00
Contents := GetPage('http://wizzup.org/static/srl/srl.tar.bz2');
Failed := True;
2010-07-15 20:10:01 -04:00
Memo.Lines.Add('Uncompressing SRL...');
2010-04-16 10:08:41 -04:00
if DecompressBZip2(Contents,DeContents,4096) then
if UnTarEx(DeContents,IncludePath,true) then
Failed := False;
if not Failed then
Settings.SetKeyValue('SRLVersion',inttostr(OnlineS));
if Result then
Result := Failed;
if not Failed then
2010-07-15 20:10:01 -04:00
begin
Memo.Lines.Add('Succesfully updated your SRL!');
2010-04-16 10:08:41 -04:00
Writeln('Succesfully updated your SRL!');
2010-07-15 20:10:01 -04:00
end;
2010-07-15 11:42:48 -04:00
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;
if (LocalP < OnlineP) or (LocalS < OnlineS) then
begin
2010-07-15 20:10:01 -04:00
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;
2010-07-15 11:42:48 -04:00
if not OpenForm then
begin
Updating := False;
Exit;
end;
Result := True;
f.ShowModal;
end else
begin
writeln('No SRL update / Plugins update available!');
end;
2010-04-16 10:08:41 -04:00
Updating := False;
2010-07-15 11:42:48 -04:00
2010-04-16 10:08:41 -04:00
end;
procedure OnSRLCheckClick(Sender: TObject);
var
LocalP,LocalS,OnlineP,OnlineS : integer;
begin
GetLocalVersion(LocalP,LocalS);
GetOnlineVersion(OnlineP,OnlineS);
if (OnlineP > LocalP) or (OnlineS > LocalS) then
2010-07-15 11:42:48 -04:00
begin;
Writeln('A new SRL version is available');
Update;
end;
2010-04-16 10:08:41 -04:00
end;
procedure SetAutoUpdate(Sender: TObject);
begin
AutoUpdate.Checked := not AutoUpdate.Checked;
Timer.Enabled := AutoUpdate.Checked;
2010-07-15 11:42:48 -04:00
if LowerCase(Settings.GetKeyValueDef('AutoUpdate','True')) = 'true' then
Settings.SetKeyValue('AutoUpdate', 'False')
else
Settings.SetKeyValue('AutoUpdate', 'True');
2010-04-16 10:08:41 -04:00
end;
2010-07-15 20:10:01 -04:00
2010-04-16 10:08:41 -04:00
procedure OnSRLUpdateClick(Sender: TObject);
begin
2010-07-15 20:10:01 -04:00
GetLocalVersion(LocalP,LocalS);
GetOnlineVersion(OnlineP,OnlineS);
if (OnlineP <= LocalP) and (OnlineS <= LocalS) then
2010-07-15 20:13:24 -04:00
MessageDlg('SRL Updater', 'No SRL update / Plugins update available!', mtConfirmation, [mbYes], 0)
2010-07-15 20:10:01 -04:00
else
Update;
2010-04-16 10:08:41 -04:00
end;
procedure OnUpdateTimer(Sender: TObject);
begin;
2010-07-17 17:30:58 -04:00
Timer.Interval := 30 * 60 * 1000; //Every half hour
2010-07-15 20:46:54 -04:00
GetLocalVersion(LocalP,LocalS);
GetOnlineVersion(OnlineP,OnlineS);
2010-07-15 11:42:48 -04:00
Update;
2010-04-16 10:08:41 -04:00
end;
procedure Init;
begin;
MainMenuItem := TMenuItem.Create(Simba_MainMenu);
MainMenuItem.Caption := 'SRL';
Simba_MainMenu.Items.Add(MainMenuItem);
MenuCheck := TMenuItem.Create(MainMenuItem);
MenuCheck.Caption := 'Check for new SRL';
MenuCheck.OnClick := @OnSRLCheckClick;
MainMenuItem.Add(MenuCheck);
MenuUpdate := TMenuItem.Create(MainMenuItem);
MenuUpdate.Caption := 'Update SRL';
MenuUpdate.OnClick := @OnSRLUpdateClick;
MainMenuItem.Add(MenuUpdate);
2010-07-15 11:42:48 -04:00
2010-04-16 10:08:41 -04:00
AutoUpdate := TMenuItem.Create(MainMenuItem);
AutoUpdate.Caption := 'Automatically update';
AutoUpdate.OnClick := @SetAutoUpdate;
AutoUpdate.Checked := LowerCase(Settings.GetKeyValueDef('AutoUpdate','True')) = 'true';
MainMenuItem.Add(AutoUpdate);
Timer := TTimer.Create(Simba);
Timer.Interval := 5000;
Timer.OnTimer := @OnUpdateTimer;
Timer.Enabled :=AutoUpdate.Checked;
2010-07-15 11:42:48 -04:00
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;
2010-04-16 10:08:41 -04:00
started := True;
end;
procedure Free;
begin
if (started) then
2010-07-15 11:42:48 -04:00
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; }
2010-04-16 10:08:41 -04:00
end;
procedure Attach;
begin;
Writeln('From now on, you shall be alerted as to when your SRL is out of date!');
MainMenuItem.Visible := True;
Timer.Enabled := AutoUpdate.Checked;
end;
Procedure Detach;
begin
Timer.Enabled := False;
MainMenuItem.Visible := False;
end;
function GetName : string;
begin;
result := 'SRL Updater';
end;
function GetVersion : string;
begin;
result := '1.0';
end;
begin
2010-07-15 20:10:01 -04:00
end.