SRL Archive - Extensions

Updater


Sex

2010-12-31 07:14:55

This is an updater I made. I was going to edit the extension included with Simba, but then I ended up making a new one for some reason. It's like 4am though so there may be something wrong with it although I have tested it and it seems to work fine for me.

The only two things different are that it combines both updaters (SRL and Reflection) into one and it can update each without user interaction..(by that I mean no clicking). Edit: Oh, also, it adds two options to the View menu in Simba so you can show and hide the menu inserts :p. I can also implement MSI into it if you want too.

Reflection updater is turned off by default, however if you click View -> Reflection Menu, you shall see it appear. Auto updates are on by default as well for both.

Anyways, here you go :). Simba Code:
[LEFT]program Updater;

var
SRLView, RefView, SRLMenu, RefMenu, SRLUpdate, RefUpdate, SRLAutoUpdate,
RefAutoUpdate : TMenuItem;
SRLTimer, RefTimer : TTimer;
LocalRV, OnlineRV, LocalSV, OnlineSV, LocalSPV,OnlineSPV : integer;
RefShown, SRLShown : boolean;

function GetNumbers(s : string) : string;
var
i, l : integer;
begin;
l := length(s);
for i := 1 to l do
case s of
'0'..'9': result := result + s;
end;
end;

procedure GetSRLVersion(Local : boolean; var SV, PV : integer);
begin
if Local then
begin
PV := StrToIntDef(Settings.GetKeyValueDef('PluginsVersion', '-1'), -1);
SV := StrToIntDef(Settings.GetKeyValueDef('SRLVersion', '-1'), -1);
end else
begin
PV := StrToIntDef(GetNumbers(GetPage('http://wizzup.org/static/srl/plugins_version')), -1);
SV := StrToIntDef(GetNumbers(GetPage('http://wizzup.org/static/srl/srl_version')), -1);
end;
end;

procedure GetRefVersion(Local : boolean; var RV : integer);
begin
if Local then
RV := StrToIntDef(Settings.GetKeyValueDef('RefVersion', '-1'), -1)
else
RV := StrToIntDef(GetNumbers(GetPage('http://wizzup.org/static/srl/srl_refl_version')), -1);
end;

procedure HandleClick(Sender : TObject); forward;

procedure SRLMMenu(Show : boolean);
begin
if Show then
begin
SRLMenu := TMenuItem.Create(Simba_MainMenu);
SRLMenu.Caption := 'SRL';
Simba_MainMenu.Items.Add(SRLMenu);

SRLUpdate := TMenuItem.Create(SRLMenu);
SRLUpdate.Caption := 'Update now';
SRLUpdate.OnClick := @HandleClick;
SRLMenu.Add(SRLUpdate);

SRLAutoUpdate := TMenuItem.Create(SRLMenu);
SRLAutoUpdate.Caption := 'Automatically update';
SRLAutoUpdate.Checked := StrToBool(Settings.GetKeyValueDef('SRLAutoUpdate', 'true'));
SRLAutoUpdate.OnClick := @HandleClick;
SRLMenu.Add(SRLAutoUpdate);
SRLTimer := TTimer.Create(Simba);
SRLTimer.Interval := 3000;
SRLTimer.OnTimer := @HandleClick;
SRLTimer.Enabled :=SRLAutoUpdate.Checked;
SRLShown := True;
end;
if not Show and SRLShown then
begin
Simba_MainMenu.Items.Delete(Simba_MainMenu.Items.IndexOf(SRLMenu));
SRLShown := False;
end;
end;

procedure RefMMenu(Show : boolean);
begin
if Show then
begin
RefMenu := TMenuItem.Create(Simba_MainMenu);
RefMenu.Caption := 'Reflection';
Simba_MainMenu.Items.Add(RefMenu);

RefUpdate := TMenuItem.Create(RefMenu);
RefUpdate.Caption := 'Update now';
RefUpdate.OnClick := @HandleClick;
RefMenu.Add(RefUpdate);

RefAutoUpdate := TMenuItem.Create(RefMenu);
RefAutoUpdate.Caption := 'Automatically update';
RefAutoUpdate.OnClick := @HandleClick;
RefAutoUpdate.Checked := StrToBool(Settings.GetKeyValueDef('RefAutoUpdate', 'true'));
RefMenu.Add(RefAutoUpdate);
RefTimer := TTimer.Create(Simba);
RefTimer.Interval := 3000;
RefTimer.OnTimer := @HandleClick;
RefTimer.Enabled :=RefAutoUpdate.Checked;
RefShown := True;
end;
if not Show and RefShown then
begin
Simba_MainMenu.Items.Delete(Simba_MainMenu.Items.IndexOf(RefMenu));
RefShown := False;
end;
end;

function UpdateReflection : boolean;
var
ArchiveC, ArchiveD : string;
Failed : boolean;
begin
ArchiveC := GetPage('http://wizzup.org/static/srl/srlref.tar.bz2');
if DecompressBZip2(ArchiveC, ArchiveD, 4096) then
Failed := not UnTarEx(ArchiveD, IncludePath, True);
if not Failed then
begin
Settings.SetKeyValue('RefVersion', IntToStr(OnlineRV));
result := True;
Writeln('Reflection updated to v' + IntToStr(OnlineRV) + '.');
end else
Writeln('Failed updating Reflection.');
end;

function UpdateSRL : boolean;
var
Failed : boolean;
ArchiveC, ArchiveD : string;
begin
ArchiveC := GetPage('http://wizzup.org/static/srl/srl.tar.bz2');
if DecompressBZip2(ArchiveC, ArchiveD, 4096) then
Failed := not UnTarEx(ArchiveD, IncludePath, True);
if not Failed then
begin
Settings.SetKeyValue('SRLVersion', IntToStr(OnlineSV));
Writeln('SRL updated to v' + IntToStr(OnlineSV) + '.');
result := True;
end else
Writeln('Failed updating SRL.');
end;

function UpdateSRLPlugins : boolean;
var
ArchiveC, ArchiveD : string;
Failed : boolean;
begin
ArchiveC := GetPage('http://wizzup.org/static/srl/simba_plugins.tar.bz2');
if DecompressBZip2(ArchiveC, ArchiveD, 4096) then
if ForceDirectories(PluginPath) then
Failed := not UnTarEx(ArchiveD, PluginPath, True);
if not Failed then
begin
Settings.SetKeyValue('PluginsVersion',inttostr(OnlineSPV));
Writeln('Plugins updated to v' + IntToStr(OnlineSPV) + '. A Simba restart is required to activate new plugins.');
Result := True;
end else
Writeln('Failed updating your plugins.');
end;

procedure CheckForSRLUpdates(Manual : boolean);
begin
if not SRLShown then
exit;
GetSRLVersion(True, LocalSV, LocalSPV);
GetSRLVersion(False, OnlineSV, OnlineSPV);
if LocalSV < OnlineSV then
begin
Writeln(Format('Updating SRL from v%d to v%d…', [LocalSV, OnlineSV]));
UpdateSRL;
end else
if Manual then Writeln('No SRL updates found.');
if LocalSPV < OnlineSPV then
begin
Writeln(Format('Updating plugins from v%d to v%d…', [LocalSPV, OnlineSPV]));
UpdateSRLPlugins;
end else
if Manual then
Writeln('No plugin updates found.');
end;

Procedure CheckForReflectionUpdates(Manual : boolean);
begin
if not RefShown then
exit;
GetRefVersion(True, LocalRV);
GetRefVersion(False, OnlineRV);
if LocalRV < OnlineRV then
begin
Writeln(Format('Updating Reflection from v%d to v%d…', [LocalRV, OnlineRV]));
UpdateReflection;
end else
if Manual then Writeln('No Reflection updates found.');
end;

procedure Init;
begin
SRLView := TMenuItem.Create(Simba_MainMenu);
SRLView.Caption := 'SRL Menu';
SRLView.Checked := Lowercase(Settings.GetKeyValueDef('ShowSRL', 'true')) = 'true';
SRLView.OnClick := @HandleClick;
Simba_MainMenu.Items.Items[3].Insert(Simba_MainMenu.Items.Items[3].Count, SRLView);

RefView := TMenuItem.Create(Simba_MainMenu);
RefView.Caption := 'Reflection Menu';
RefView.Checked := Lowercase(Settings.GetKeyValueDef('ShowRef', 'false')) = 'true';
RefView.OnClick := @HandleClick;
Simba_MainMenu.Items.Items[3].Insert(Simba_MainMenu.Items.Items[3].Count, RefView);

SRLMMenu(SRLView.Checked);
RefMMenu(RefView.Checked);
end;

procedure HandleClick(Sender : TObject);
begin
case Sender of
SRLUpdate : CheckForSRLUpdates(True); // SRL -> Update now
RefUpdate : CheckForReflectionUpdates(True); // Reflection -> Update now
SRLView : // View -> SRL Menu
begin
Settings.SetKeyValue('ShowSRL', BoolToStr(not SRLView.Checked));
SRLView.Checked := StrToBool(Settings.GetKeyValue('ShowSRL'));
SRLMMenu(SRLView.Checked);
end;
RefView : // View -> Reflection Menu
begin
Settings.SetKeyValue('ShowRef', BoolToStr(not RefView.Checked));
RefView.Checked := StrToBool(Settings.GetKeyValue('ShowRef'));
RefMMenu(RefView.Checked);
end;
SRLTimer :
begin
SRLTimer.Interval := 15 * 60 * 1000; //Every quarter hour
CheckForSRLUpdates(False);
end;
RefTimer :
begin
RefTimer.Interval := 15 * 60 * 1000; //Every quarter hour
CheckForReflectionUpdates(False);
end;
SRLAutoUpdate : // SRL -> Automatically update
begin
Settings.SetKeyValue('SRLAutoUpdate', BoolToStr(not SRLAutoUpdate.Checked));
SRLTimer.Enabled := not SRLAutoUpdate.Checked;
SRLAutoUpdate.Checked := not SRLAutoUpdate.Checked;
end;
RefAutoUpdate : // Reflection -> Automatically update
begin
Settings.SetKeyValue('RefAutoUpdate', BoolToStr(not RefAutoUpdate.Checked));
RefTimer.Enabled := not RefAutoUpdate.Checked;
RefAutoUpdate.Checked := not RefAutoUpdate.Checked;
end;
end;
end;

function GetName : string;
begin;
result := 'SRL/Reflection Updater';
end;

function GetVersion : string;
begin;
result := '0.2';
end;

begin
end.
[/LEFT]

Updated 0.2 - 1/8/11

HyperSecret

2010-12-31 09:16:18

I like the option to update or not (user interaction). I have certain edits that I made to SRL after every update and sometimes I don't update right away.

Gu3st...

2010-12-31 09:44:34

Didn't Dgby714 made one like this too?

Dgby714

2010-12-31 10:45:58

From: Zyt3x
Didn't Dgby714 made one like this too?


Yes I did. Tho I liked his idea about a view menu option to hide the menus, Im adding that to mine too. =)

O and btw from my quick glance your missing quite a bit in the plugins updater.

Sex

2010-12-31 12:06:45

It probably is messed up xD. I wanted mine to overwrite always but it was like 3am or whatever when I wrote that. I'll take a better look this afternoon and change it up.

MylesMadness

2010-12-31 12:12:51

program SRLUpdater;

type
TInclude = Record
name : String;
varName : String;
reposURL : String;
localV : integer;
onlineV : integer;
outdated : boolean;
end;

var
MainMenuItem, MenuCheck, MenuUpdate,AutoUpdate : TMenuItem;
started: Boolean;
Timer : TTimer;
Updating, NeedSomeUpdating: boolean;

F: TForm;
Memo: TMemo;
but: TButton;

Includes: array of TInclude;

const
I_SRL = 0;
I_Pluggins = 1;
I_Ref = 2;

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 LoadIncludes;
var
i: integer;
begin
SetLength(Includes, 3);

with Includes[I_SRL] do
begin
name := 'SRL';
varName := 'SRLVersion';
reposURL := 'http://wizzup.org/static/srl/srl.tar.bz2';
onlineV := strtointdef(GetNumbers(getpage('http://wizzup.org/static/srl/srl_version')),-1);
end;

with Includes[I_Pluggins] do
begin
name := 'Pluggins';
varName := 'PlugginsVersion';
reposURL := 'http://wizzup.org/static/srl/simba_plugins.tar.bz2';
onlineV := strtointdef(GetNumbers(getpage('http://wizzup.org/static/srl/plugins_version')),-1);
end;

with Includes[I_Ref] do
begin
name := 'Reflection';
varName := 'RefVersion';
reposURL := 'http://wizzup.org/static/srl/srlref.tar.bz2';
onlineV := strtointdef(GetNumbers(getpage('http://wizzup.org/static/srl/srl_refl_version')),-1);
end;

for i := High(Includes) DownTo 0 do
begin
includes[I].localV := StrToIntDef(Settings.GetKeyValueDef(Includes[i].varName, '-1'), -1);

if Includes[i].onlineV > Includes[i].localV then
begin
NeedSomeUpdating := true;
Includes[i].outdated := true;
end;
end;
end;



function UpdatePlugins: Boolean;
var
I : integer;
Contents : String;
DeContents : string;
Files : TStringArray;
Failed,OverWrite : boolean;
begin
Memo.Lines.Add('Downloading ' + Includes[I_Pluggins].name +'...');
Contents := GetPage(Includes[I_Pluggins].reposURL);
Failed := True;
Memo.Lines.Add('Uncompressing ' + Includes[I_Pluggins].name +'...');
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
begin
Writeln('Failed to update the plugins');
Memo.Lines.Add('Failed to update the plugins');
end
else
begin
Writeln('Succesfully updated your plugins.');
Memo.Lines.Add('Succesfully updated your plugins.');
end;
DeContents := '';
Contents := '';
Result := Failed;
if not Failed then
Settings.SetKeyValue('PluginsVersion',inttostr(Includes[I_Pluggins].OnlineV));
end;

Function UpdateInclude(Which:Integer):Boolean;
var
Contents : String;
DeContents : string;
Failed: boolean;
begin
Memo.Lines.Add('Downloading ' + Includes[Which].name +'...');
Contents := GetPage(Includes[Which].reposURL);
Failed := True;
Memo.Lines.Add('Uncompressing ' + Includes[Which].name +'...');
if DecompressBZip2(Contents,DeContents,4096) then
if UnTarEx(DeContents,IncludePath,true) then
Failed := False;
if not Failed then
Settings.SetKeyValue(Includes[Which].varName, inttostr(Includes[Which].OnlineV));
if Result then
Result := Failed;
if not Failed then
begin
Memo.Lines.Add('Succesfully updated your ' + Includes[Which].name +'!');
Writeln('Succesfully updated your ' + Includes[Which].name +'!');
end;
end;

procedure DoUpdate(Sender: TObject);
var
I:integer;
begin
if Includes[I_Pluggins].outdated then
begin
Memo.Lines.Add('Plugins update. Old version: ' + IntToStr(Includes[I_Pluggins].localV) +
' New version: ' + IntToStr(Includes[I_Pluggins].OnlineV));
UpdatePlugins;
end;
for I:=0 to high(Includes) do
begin
if Includes[I].outdated then
begin
Memo.Lines.Add(Includes[I].name+' update. Old version: ' + IntToStr(Includes[I].LocalV) +
' New version: ' + IntToStr(Includes[I].OnlineV));
UpdateInclude(I);
end;
end;
F.ModalResult := mrOk;
end;


function Update : boolean;
var
OpenForm: Boolean;
begin
Result := false;
if Updating then
Exit;
Updating := True;


if NeedSomeUpdating 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;
Exit;
end;
Result := True;
f.ShowModal;
end else
begin
writeln('No SRL update / Plugins update available!');
end;

Updating := False;

end;

procedure OnSRLCheckClick(Sender: TObject);
begin
if NeedSomeUpdating then
begin;
Writeln('A new SRL version is available');
Update;
end;
end;

procedure SetAutoUpdate(Sender: TObject);
begin
AutoUpdate.Checked := not AutoUpdate.Checked;
Timer.Enabled := AutoUpdate.Checked;
if LowerCase(Settings.GetKeyValueDef('AutoUpdate','True')) = 'true' then
Settings.SetKeyValue('AutoUpdate', 'False')
else
Settings.SetKeyValue('AutoUpdate', 'True');
end;

procedure OnSRLUpdateClick(Sender: TObject);
begin
if NeedSomeUpdating then
MessageDlg('SRL Updater', 'No SRL update / Plugins update available!', mtConfirmation, [mbYes], 0)
else
Update;
end;

procedure OnSRLSettingsClick(Sender: TObject);
begin
end;

procedure OnUpdateTimer(Sender: TObject);
begin;
Timer.Interval := 30 * 60 * 1000; //Every half hour
Update;
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);

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;

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;
end;

procedure Free;
begin
if (started) then
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;

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
end.
Thats how far I got, but its broken and I have no idea why. It just needs a way to change some settings, and to work off course.

Sex

2010-12-31 12:31:46

From: Dgby714
Yes I did. Tho I liked his idea about a view menu option to hide the menus, Im adding that to mine too. =)

O and btw from my quick glance your missing quite a bit in the plugins updater.

Also, mind posting yours as well? I wasn't aware that you made one :p.

Edit: Just saying, this does work updating plugins. Maybe the reason you thought it didn't was because I deleted a bunch of the code from the other extension, but I wanted it to overwrite automatically :p. I tested.
Updating plugins from v10 to v11...
Plugins updated to v11. A Simba restart is required to activate new plugins.

Dgby714

2011-01-08 07:27:03

From: Sex
Also, mind posting yours as well? I wasn't aware that you made one :p.

Edit: Just saying, this does work updating plugins. Maybe the reason you thought it didn't was because I deleted a bunch of the code from the other extension, but I wanted it to overwrite automatically :p. I tested.
Updating plugins from v10 to v11...
Plugins updated to v11. A Simba restart is required to activate new plugins.


Mine has been included with Simba.

You are extracting the plugins into "IncludePath + 'SRL/SimbaPlugins/'".
They need to go in PluginPath, the old srl.sex put them in ^ too check if any files existed yet.

Bad Processor

2011-01-08 07:35:32

This looks interesting - I tend not to work with Simba in Simba, though, I prefer something different. Nevertheless, good work! Have a cookie.
– BP

Sex

2011-01-08 19:19:34

Failed := not UnTarEx(ArchiveD, PluginPath, True);

Dgby714

2011-01-08 19:38:16

From: Sex
Failed := not UnTarEx(ArchiveD, PluginPath, True);


You don't need "UnTarEx(ArchiveD,IncludePath + 'SRL/SimbaPlugins/', True)" at all.

Sex

2011-01-08 20:52:44

But that extracts the tar archive into the PluginPath? I even tested this and it downloaded the plugins and put it in Simba/Plugins..

Edit: Wait, nevermind, I see what you saying.