diff --git a/Extensions/Updater.sei b/Extensions/Updater.sei new file mode 100644 index 0000000..47a5014 --- /dev/null +++ b/Extensions/Updater.sei @@ -0,0 +1,363 @@ + +const + ATTACH_HOOK = 0; + DETACH_HOOK = 1; + CHECK_FOR_UPDATE = 2; + BEFORE_UPDATE = 3; + SUCCESS_UPDATE = 4; + AFTER_UPDATE = 5; + +type + THookFunc = function(Param1: string; Param2: integer): boolean; + THookArr = array[ATTACH_HOOK..AFTER_UPDATE] of THookFunc; + TUpdater = record + Name, URL, VersionURL, Folder: string; + CreateMenu, NoMenuTimer, Locked: boolean; + Hooks: THookArr; + ViewMenuItem: TMenuItem; + MainMenu, UpdateMenuItem, CheckMenuItem: TMenuItem; + AutoMenu, AUpdateMenuItem, ACheckMenuItem: TMenuItem; + SettingsMenu, TimerMenuItem, OverrideUpdateMenuItem: TMenuItem; + Timer: TTimer; + end; + TUpdaterArr = array of TUpdater; + +var + UpdaterArr: TUpdaterArr; + +function GetOVersion(Updater: TUpdater): integer; +begin + Result := StrToIntDef(ExtractFromStr(GetPage(Updater.VersionURL), Numbers), -1); +end; + +function GetLVersion(Updater: TUpdater): integer; +begin + Result := StrToIntDef(ExtractFromStr(Settings.GetKeyValueDef(Updater.Name + '_Version', '-1'), Numbers), -1); +end; + +procedure SetLVersion(Updater: TUpdater; Version: integer); +begin + Settings.SetKeyValue(Updater.Name + '_Version', IntToStr(Version)); +end; + +procedure Update(const Sender: TObject; const I: integer); +var + Cont, ExCont: string; +begin + with UpdaterArr[I] do + begin + if (Locked) then + Exit; + + if (Hooks[BEFORE_UPDATE] <> nil) then + if (not (Hooks[BEFORE_UPDATE]('', I))) then + Exit; + + Locked := True; + + WriteLn(Name + ' Updater: Local Version - "' + IntToStr(GetLVersion(UpdaterArr[I])) + '" | Remote Version = "' + IntToStr(GetOVersion(UpdaterArr[I])) + '"'); + WriteLn(Name + ' Updater: Update File - "' + URL + '"'); + WriteLn(Name + ' Updater: Downloading...'); + Cont := GetPage(URL); + if (Cont <> '') then + begin + WriteLn(Name + ' Updater: Decompressing...'); + if (DecompressBZip2(Cont, ExCont, 4096)) then + begin + WriteLn(Name + ' Updater: Extracting...'); + if (UnTarEx(ExCont, Folder, True)) then + begin + if (Hooks[SUCCESS_UPDATE] <> nil) then + if (not (Hooks[SUCCESS_UPDATE](ExCont, I))) then + begin + WriteLn(Name + ' Update ERROR: Kill recieved from Updater.'); + Exit; + end; + SetLVersion(UpdaterArr[I], GetOVersion(UpdaterArr[I])); + WriteLn(Name + ' Update Successful!'); + if (CreateMenu) then + UpdateMenuItem.Enabled := OverrideUpdateMenuItem.Checked; + end else + WriteLn(Name + ' Update ERROR: Couldn''t extract the tar archive.'); + end else + WriteLn(Name + ' Update ERROR: Couldn''t decompress the bzip archive.'); + end else + WriteLn(Name + ' Update ERROR: Didn''t recieve any data from Update URL.'); + + Locked := False; + if (Hooks[AFTER_UPDATE] <> nil) then + if (not (Hooks[AFTER_UPDATE]('', I))) then + Exit; + end; +end; + +procedure Tick(const Sender: TObject); +var + I: integer; + Name: string; +begin + for I := 0 to High(UpdaterArr) + 1 do + if (not (I = High(UpdaterArr) + 1)) then + begin + case Sender of + UpdaterArr[I].Timer: Name := 'Timer'; + UpdaterArr[I].CheckMenuItem: Name := 'Check'; + end; + if (not (Name = '')) then + Break; + end else + Exit; + + if (UpdaterArr[I].Locked) then + Exit; + + if (UpdaterArr[I].Hooks[CHECK_FOR_UPDATE] <> nil) then + if (not (UpdaterArr[I].Hooks[CHECK_FOR_UPDATE](Name, I))) then + Exit; + + if (GetLVersion(UpdaterArr[I]) < GetOVersion(UpdaterArr[I])) then + begin + WriteLn('You have a new update available for ' + UpdaterArr[I].Name + '!'); + + if (UpdaterArr[I].CreateMenu) then + begin + UpdaterArr[I].UpdateMenuItem.Enabled := True; + if (UpdaterArr[I].AUpdateMenuItem.Checked or (Sender = UpdaterArr[I].CheckMenuItem)) then + Update(Sender, I); + end else + Update(Sender, I); + end else + if (Sender = UpdaterArr[I].CheckMenuItem) then + WriteLn('No ' + UpdaterArr[I].Name + ' update available.'); +end; + +procedure Click(Sender: TObject); +var + I: integer; + Value: string; +begin + for I := 0 to High(UpdaterArr) do + with UpdaterArr[I] do + begin + case Sender of + ViewMenuItem: begin + ViewMenuItem.Checked := (not (ViewMenuItem.Checked)); + Settings.SetKeyValue(Name + '_Visible', Lowercase(BoolToStr(ViewMenuItem.Checked))); + MainMenu.Visible := ViewMenuItem.Checked; + end; + UpdateMenuItem: Update(Sender, I); + CheckMenuItem: Tick(Sender); + AUpdateMenuItem, ACheckMenuItem, OverrideUpdateMenuItem: begin + TMenuItem(Sender).Checked := (not (TMenuItem(Sender).Checked)); + Settings.SetKeyValue(UpdaterArr[I].Name + '_' + ExtractFromStr(TMenuItem(Sender).Caption, Letters), BoolToStr(TMenuItem(Sender).Checked)); + case Sender of + OverrideUpdateMenuItem: UpdateMenuItem.Enabled := OverrideUpdateMenuItem.Checked; + ACheckMenuItem: Timer.Enabled := ACheckMenuItem.Checked; + end; + end; + TimerMenuItem: begin + if (InputQuery(Name + ' Updater', 'What would you like the Timer Interval to be? (1 - 100000 seconds)', Value)) then + begin + Value := ExtractFromStr(Value, Numbers); + if ((IntToStr(StrToIntDef(Value, -1)) = Value) and InRange(StrToIntDef(Value, -1), 1, 100000)) then + begin + Timer.Interval := StrToIntDef(Value, (Timer.Interval / 1000)) * 1000; + TimerMenuItem.Caption := 'Timer Interval: ' + IntToStr(Timer.Interval / 1000); + Settings.SetKeyValue(Name + '_TimerInterval', IntToStr(Timer.Interval)); + end; + end; + end; + end; + end; +end; + +function InMenu(const Name: string; const Menu: TMenuItem; out Item: TMenuItem): boolean; +var + I: integer; +begin + for I := 0 to Menu.Count - 1 do + if (Lowercase(Menu.Items[I].Caption) = Lowercase(Name)) then + begin + Result := True; + Item := Menu.Items[I]; + Exit; + end; +end; + +function GetMenuByName(const Name: string; Menu: TMenuItem): TMenuItem; +begin + if (not (InMenu(Name, Menu, Result))) then + begin + Result := TMenuItem.Create(Menu); + Result.Caption := Name; + Menu.Add(Result); + end; +end; + +function MoveMenuItem(Menu: TMenuItem; FromIndex, ToIndex: integer): TMenuItem; +var + TempMenuItem: TMenuItem; +begin + if (InRange(FromIndex, 0, Menu.Count - 1) and InRange(ToIndex, 0, Menu.Count - 1)) then + begin + TempMenuItem := Menu.Items[FromIndex]; + Menu.Delete(FromIndex); + Menu.Insert(ToIndex, TempMenuItem); + Result := Menu.Items[ToIndex]; + end; +end; + +function GetIndex(Menu, MenuItem: TMenuItem): integer; +begin + for Result := 0 to Menu.Count - 1 do + if (Menu.Items[Result] = MenuItem) then + Exit; + Result := -1; +end; + +function IsUpdateMenu(const Menu: TMenuItem): boolean; +var + I: integer; +begin + for I := 0 to Menu.Count - 1 do + if (Menu.Items[I].Caption = 'Update') then + Result := True; +end; + +function AddUpdater(const IncludeName, UpdateURL, VerURL, ExFolder: string; const ShowMenu, TimerIfNoMenu: boolean; var ID: integer): boolean; +var + Seperator: array[0..1] of TMenuItem; + ViewMenu: TMenuItem; +begin + ID := Length(UpdaterArr); + SetLength(UpdaterArr, ID + 1); + with UpdaterArr[ID] do + begin + Name := IncludeName; + URL := UpdateURL; + VersionURL := VerURL; + Folder := ExFolder; + CreateMenu := ShowMenu; + NoMenuTimer := TimerIfNoMenu; + + if (CreateMenu) then + begin + ViewMenu := GetMenuByName('&View', Simba_MainMenu.Items); + if (ViewMenu.Count = 4) then + begin + Seperator[0] := TMenuItem.Create(ViewMenu); + Seperator[0].Caption := '-'; + ViewMenu.Add(Seperator[0]) + end; + + ViewMenuItem := GetMenuByName(Name + ' Menu', ViewMenu); + ViewMenuItem.OnClick := @Click; + ViewMenuItem.Checked := (LowerCase(Settings.GetKeyValueDef(Name + '_Visible', 'true')) = 'true'); + ViewMenuItem.Visible := False; + + MainMenu := GetMenuByName(Name, Simba_MainMenu.Items); + MainMenu.Visible := False; + if (IsUpdateMenu(MainMenu)) then + Exit; + + if (MainMenu.Count > 0) then + begin + Seperator[1] := TMenuItem.Create(MainMenu); + Seperator[1].Caption := '-'; + MainMenu.Add(Seperator[1]) + end; + + UpdateMenuItem := TMenuItem.Create(MainMenu); + UpdateMenuItem.Caption := 'Update'; + UpdateMenuItem.OnClick := @Click; + UpdateMenuItem.Enabled := (LowerCase(Settings.GetKeyValueDef(Name + '_OverrideUpdate', 'false')) = 'true'); + MainMenu.Add(UpdateMenuItem); + + CheckMenuItem := TMenuItem.Create(MainMenu); + CheckMenuItem.Caption := 'Check for Update'; + CheckMenuItem.OnClick := @Click; + MainMenu.Add(CheckMenuItem); + + AutoMenu := TMenuItem.Create(MainMenu); + AutoMenu.Caption := 'Automaticaly ...'; + MainMenu.Add(AutoMenu); + + AUpdateMenuItem := TMenuItem.Create(AutoMenu); + AUpdateMenuItem.Caption := 'Update'; + AUpdateMenuItem.OnClick := @Click; + AUpdateMenuItem.Checked := (LowerCase(Settings.GetKeyValueDef(Name + '_Update', 'true')) = 'true'); + AutoMenu.Add(AUpdateMenuItem); + + ACheckMenuItem := TMenuItem.Create(AutoMenu); + ACheckMenuItem.Caption := 'Check for Updates'; + ACheckMenuItem.OnClick := @Click; + ACheckMenuItem.Checked := (LowerCase(Settings.GetKeyValueDef(Name + '_CheckforUpdates', 'true')) = 'true'); + AutoMenu.Add(ACheckMenuItem); + + SettingsMenu := TMenuItem.Create(MainMenu); + SettingsMenu.Caption := 'Settings'; + MainMenu.Add(SettingsMenu); + + TimerMenuItem := TMenuItem.Create(SettingsMenu); + TimerMenuItem.Caption := 'Timer Interval: ' + IntToStr(StrToIntDef(ExtractFromStr(Settings.GetKeyValueDef(Name + '_TimerInterval', '3600000'), Numbers), 3600000) / 1000); + TimerMenuItem.OnClick := @Click; + SettingsMenu.Add(TimerMenuItem); + + OverrideUpdateMenuItem := TMenuItem.Create(SettingsMenu); + OverrideUpdateMenuItem.Caption := 'Override Update'; + OverrideUpdateMenuItem.OnClick := @Click; + OverrideUpdateMenuItem.Checked := (LowerCase(Settings.GetKeyValueDef(Name + '_OverrideUpdate', 'false')) = 'true'); + SettingsMenu.Add(OverrideUpdateMenuItem); + end; + + Timer := TTimer.Create(nil); + Timer.Interval := StrToIntDef(ExtractFromStr(Settings.GetKeyValueDef(Name + '_TimerInterval', '3600000'), Numbers), 3600000); + if (ShowMenu) then + Timer.Enabled := ACheckMenuItem.Checked + else + Timer.Enabled := NoMenuTimer; + Timer.OnTimer := @Tick; + end; + + Result := True; +end; + +procedure Attach; +var + I: integer; +begin + for I := 0 to High(UpdaterArr) do + begin + if (UpdaterArr[I].Hooks[ATTACH_HOOK] <> nil) then + UpdaterArr[I].Hooks[ATTACH_HOOK]('', I); + + if (UpdaterArr[I].CreateMenu) then + begin + UpdaterArr[I].ViewMenuItem.Visible := True; + UpdaterArr[I].MainMenu.Visible := UpdaterArr[I].ViewMenuItem.Checked; + UpdaterArr[I].Timer.Enabled := UpdaterArr[I].ACheckMenuItem.Checked; + end else + UpdaterArr[I].Timer.Enabled := UpdaterArr[I].NoMenuTimer; + WriteLn(UpdaterArr[I].Name + ' Updater Enabled!'); + end; +end; + +procedure Detach; +var + I: integer; +begin + for I := High(UpdaterArr) downto 0 do + begin + if (UpdaterArr[I].Hooks[DETACH_HOOK] <> nil) then + UpdaterArr[I].Hooks[DETACH_HOOK]('', I); + + if (UpdaterArr[I].CreateMenu) then + begin + UpdaterArr[I].ViewMenuItem.Visible := False; + UpdaterArr[I].MainMenu.Visible := False; + end; + UpdaterArr[I].Timer.Enabled := False; + WriteLn(UpdaterArr[I].Name + ' Updater Disabled.'); + end; +end; + diff --git a/Extensions/reflection.sex b/Extensions/reflection.sex deleted file mode 100644 index d0ca477..0000000 --- a/Extensions/reflection.sex +++ /dev/null @@ -1,244 +0,0 @@ -program ReflectionUpdater; -var - MainMenuItem, MenuCheck, MenuUpdate,AutoUpdate : TMenuItem; - started: Boolean; - Timer : TTimer; - Updating : boolean; - LocalR,OnlineR: Integer; - - F: TForm; - Memo: TMemo; - but: TButton; - - -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 RefVersion : integer); -begin - RefVersion := strtointdef(GetNumbers(getpage('http://wizzup.org/static/srl/srl_refl_version')),-1); -end; - -procedure GetLocalVersion(out RefVersion : integer); -begin - RefVersion := StrToIntDef(Settings.GetKeyValueDef('RefVersion','-1'),-1); -end; - - -function UpdateRef: boolean; -var - Contents : String; - DeContents : string; - Failed : boolean; -begin - Memo.Lines.Add('Downloading Reflection...'); - Contents := GetPage('http://wizzup.org/static/srl/srlref.tar.bz2'); - Failed := True; - Memo.Lines.Add('Uncompressing Reflection...'); - if DecompressBZip2(Contents,DeContents,4096) then - if UnTarEx(DeContents,IncludePath,true) then - Failed := False; - if not Failed then - Settings.SetKeyValue('RefVersion',inttostr(OnlineR)); - if Result then - Result := Failed; - if not Failed then - begin - Memo.Lines.Add('Succesfully updated your Reflection!'); - Writeln('Succesfully updated your Reflection!'); - end; -end; - -procedure DoUpdate(Sender: TObject); -begin - if LocalR < OnlineR then - begin - Memo.Lines.Add('Reflection update. Old version: ' + IntToStr(LocalR) + - ' New version: ' + IntToStr(OnlineR)); - UpdateRef; - end; - F.ModalResult := mrOk; -end; - - -function Update : boolean; -var - OpenForm: Boolean; -begin - Result := false; - if Updating then - Exit; - Updating := True; - - if (LocalR < OnlineR) then - begin - case MessageDlg('Reflection 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 Reflection update'); - end; - - Updating := False; - -end; - -procedure OnReflectionCheckClick(Sender: TObject); -var - LocalR,OnlineR : integer; -begin - GetLocalVersion(LocalR); - GetOnlineVersion(OnlineR); - - if (LocalR < OnlineR) then - begin - Writeln('A new Reflection 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 OnReflectionUpdateClick(Sender: TObject); -begin - GetLocalVersion(LocalR); - GetOnlineVersion(OnlineR); - - if (OnlineR <= LocalR) then - MessageDlg('Reflection Updater', 'No Reflection update' ,mtConfirmation, [mbYes],0) - else - Update; -end; - -procedure OnUpdateTimer(Sender: TObject); -begin; - Timer.Interval := 30 * 60 * 1000; //Every half hour - GetLocalVersion(LocalR); - GetOnlineVersion(OnlineR); - Update; -end; - -procedure Init; -begin; - MainMenuItem := TMenuItem.Create(Simba_MainMenu); - MainMenuItem.Caption := 'Reflection'; - Simba_MainMenu.Items.Add(MainMenuItem); - - MenuCheck := TMenuItem.Create(MainMenuItem); - MenuCheck.Caption := 'Check for new Reflection'; - MenuCheck.OnClick := @OnReflectionCheckClick; - MainMenuItem.Add(MenuCheck); - - MenuUpdate := TMenuItem.Create(MainMenuItem); - MenuUpdate.Caption := 'Update Reflection'; - MenuUpdate.OnClick := @OnReflectionUpdateClick; - 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 := 'Reflection 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 Reflection 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 := 'Reflection Updater'; -end; - -function GetVersion : string; -begin; - result := '1.0'; -end; - -begin -end. diff --git a/Extensions/srl.sex b/Extensions/srl.sex index d32702b..c449ac4 100644 --- a/Extensions/srl.sex +++ b/Extensions/srl.sex @@ -1,297 +1,108 @@ program SRLUpdater; + +{.INCLUDE ..\Extensions\Updater.sei} + +function CheckSRL(Name: string; I: integer): boolean; var - MainMenuItem, MenuCheck, MenuUpdate,AutoUpdate : TMenuItem; - started: Boolean; - Timer : TTimer; - Updating : boolean; - LocalP,LocalS,OnlineP,OnlineS: Integer; - - F: TForm; - Memo: TMemo; - but: TButton; - - -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); + X: 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; - -function UpdatePlugins: Boolean; -var - I : integer; - Contents : String; - DeContents : string; - Files : TStringArray; - Failed,OverWrite : boolean; -begin - Memo.Lines.Add('Downloading the plugins...'); - Contents := GetPage('http://wizzup.org/static/srl/simba_plugins.tar.bz2'); - Memo.Lines.Add('Uncompressing the plugins...'); - 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 + Result := True; + for X := 0 to Length(UpdaterArr) do + if (UpdaterArr[X].Name = 'Plugins') 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(OnlineP)); -end; - -function UpdateSRL: boolean; -var - Contents : String; - DeContents : string; - Failed : boolean; -begin - Memo.Lines.Add('Downloading SRL...'); - Contents := GetPage('http://wizzup.org/static/srl/srl.tar.bz2'); - Failed := True; - Memo.Lines.Add('Uncompressing SRL...'); - 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 - begin - Memo.Lines.Add('Succesfully updated your SRL!'); - Writeln('Succesfully updated your SRL!'); - 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; - - - 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; + if (Name = 'Check') then + Tick(UpdaterArr[X].CheckMenuItem) + else + Tick(UpdaterArr[X].Timer); Exit; end; - Result := True; - f.ShowModal; - end else - begin - writeln('No SRL update / Plugins update available!'); - end; - - Updating := False; - end; -procedure OnSRLCheckClick(Sender: TObject); +procedure OpenDefScript(Sender: TObject); var - LocalP,LocalS,OnlineP,OnlineS : integer; + Script: TStringArray; begin - GetLocalVersion(LocalP,LocalS); - GetOnlineVersion(OnlineP,OnlineS); - if (OnlineP > LocalP) or (OnlineS > LocalS) then - begin; - Writeln('A new SRL version is available'); - Update; + SetLength(Script, 6); + Script[0] := 'program Untitled;'; + Script[1] := '//{$DEFINE SMART} //Uncomment for SMART'; + Script[2] := '{.include SRL/SRL.scar}'; + if (TMenuItem(Sender).Parent.Caption = 'Reflection') then + begin + SetLength(Script, 7); + Script[1] := '{$DEFINE SMART}'; + Script[3] := '{.include Reflection/Reflection.scar}'; end; + Script[Length(Script) - 3] := ''; + Script[Length(Script) - 2] := 'begin'; + Script[Length(Script) - 1] := 'end.'; + + WriteLn('Opening ' + TMenuItem(Sender).Parent.Caption + ' Default Script...'); + OpenScript('', Implode({$IFDEF WIN}#13+{$ENDIF}#10, Script), False); end; -procedure SetAutoUpdate(Sender: TObject); +function OpenDefMenu(const Blank: string; const ID: integer): boolean; +var + OpenMenuItem: TMenuItem; 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'); + OpenMenuItem := MoveMenuItem(UpdaterArr[ID].MainMenu, GetIndex(UpdaterArr[ID].MainMenu, GetMenuByName('Open', UpdaterArr[ID].MainMenu)), GetIndex(UpdaterArr[ID].MainMenu, GetMenuByName('Update', UpdaterArr[ID].MainMenu))); + OpenMenuItem.OnClick := @OpenDefScript; + OpenMenuItem.Visible := True; end; -procedure OnSRLUpdateClick(Sender: TObject); +function BeforePlugins(NotNeeded: string; I: integer): boolean; begin - GetLocalVersion(LocalP,LocalS); - GetOnlineVersion(OnlineP,OnlineS); - if (OnlineP <= LocalP) and (OnlineS <= LocalS) then - MessageDlg('SRL Updater', 'No SRL update / Plugins update available!', mtConfirmation, [mbYes], 0) - else - Update; + Result := ForceDirectories(UpdaterArr[I].Folder); end; -procedure OnUpdateTimer(Sender: TObject); -begin; - Timer.Interval := 30 * 60 * 1000; //Every half hour - GetLocalVersion(LocalP,LocalS); - GetOnlineVersion(OnlineP,OnlineS); - Update; +function SuccessPlugins(Cont: string; I: integer): boolean; +var + X: integer; + Files: TStringArray; + Overwrite: boolean; +begin + Files := GetFiles(UpdaterArr[I].Folder, {$IFDEF WIN}'dll'{$ELSE}'so'{$ENDIF}); + Overwrite := True; + for X := 0 to High(Files) do + if (FileExists(PluginPath + Files[X])) then + begin + Overwrite := (MessageDlg('SRL Updater', 'Do you want to overwrite the plugins?', mtConfirmation, [mbNo, mbYes], 0) = mrYes); + Break; + end; + + Result := UnTarEx(Cont, PluginPath, Overwrite); 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; +var + SRL, Plugins, Refl: integer; 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; } + if (AddUpdater('SRL', 'http://wizzup.org/static/srl/srl.tar.bz2', 'http://wizzup.org/static/srl/srl_version', IncludePath, True, True, SRL)) then + begin + UpdaterArr[SRL].Hooks[CHECK_FOR_UPDATE] := @CheckSRL; + UpdaterArr[SRL].Hooks[ATTACH_HOOK] := @OpenDefMenu; + end; + + if (AddUpdater('Plugins', 'http://wizzup.org/static/srl/simba_plugins.tar.bz2', 'http://wizzup.org/static/srl/plugins_version', IncludePath + 'SRL/SimbaPlugins/', False, False, Plugins)) then + begin + UpdaterArr[Plugins].Hooks[BEFORE_UPDATE] := @BeforePlugins; + UpdaterArr[Plugins].Hooks[SUCCESS_UPDATE] := @SuccessPlugins; + end; + + if (AddUpdater('Reflection', 'http://wizzup.org/static/srl/srlref.tar.bz2', 'http://wizzup.org/static/srl/srl_refl_version', IncludePath, True, True, Refl)) then + begin + UpdaterArr[Refl].Hooks[ATTACH_HOOK] := @OpenDefMenu; + end; 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; +function GetName: string; begin - Timer.Enabled := False; - MainMenuItem.Visible := False; + Result := 'SRL Updater'; end; -function GetName : string; -begin; - result := 'SRL Updater'; +function GetVersion: string; +begin + Result := '0.1'; end; -function GetVersion : string; -begin; - result := '1.0'; -end; begin end.