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