Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program SRLInstaller;
- var
- MainMenuItem, MenuCheck, MenuUpdate, MenuMove, MenuSetVersion: TMenuItem;
- started: Boolean;
- procedure init;
- begin
- end;
- procedure free;
- begin
- end;
- 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;
- function PosEx(find, str: string; start: Integer): Integer;
- var
- o, t: Integer;
- begin
- Result := 0;
- o := 0;
- repeat
- t := Pos(find, str);
- if (t + o >= start) or (t = 0) then
- Break;
- Delete(str, 1, t);
- o := o + t;
- Until Length(str) < start;
- if (t + o >= start) then
- Result := t + o;
- end;
- function Between(start, finish, str: string): string;
- var
- b, e: Integer;
- begin
- Result := '';
- b := Pos(start, str);
- if (b <> 0) then
- begin
- e := PosEx(finish, str, b + 1);
- if (e <> 0) then
- Result := Copy(str, b, e - b);
- end;
- end;
- function GetRemoteSRLVersion(tryagain: Boolean): Integer;
- begin
- Result := StrToIntDef(GetNumbers(GetPage('http://wizzup.org/simba/srl/srl_version')), -1);
- if (Result = -1) then
- begin
- if (tryagain) then
- begin
- Writeln('Error retrieving remote SRL version. Trying again');
- Result := GetRemoteSRLVersion(False);
- end
- else
- begin
- Writeln('Error retrieving the remote SRL version. Not trying again');
- end;
- end;
- end;
- function IsSRLDownloaded(out uptodate: Boolean): Boolean;
- var
- remoteVersion, localVersion: Integer;
- begin
- Result := Settings.IsKey('SRLVersion');
- if (Result) then
- begin
- remoteVersion := GetRemoteSRLVersion(True);
- if (remoteVersion = -1) then
- begin
- Writeln('Unable to get remote version - assuming SRL include is up to date');
- uptodate := True;
- end
- else
- begin
- localVersion := StrToIntDef(Settings.GetKeyValue('SRLVersion'), -1);
- uptodate := localVersion = remoteVersion;
- if (uptodate) then
- Writeln('The local SRL include is up-to-date!')
- else
- begin
- if (localVersion < remoteVersion) then
- Writeln('The local SRL include is not up-to-date')
- else
- Writeln('You some how ended up with a newer version than the remote!')
- end;
- end;
- end
- else
- begin
- uptodate := False;
- Writeln('There currently is no local version of the SRL includes!');
- end;
- end;
- procedure UpdateLocalSRLVersionSetting;
- var
- ver: Integer;
- begin
- ver := GetRemoteSRLVersion(True);
- if ver = -1 then
- begin
- Writeln('Unable to get the remote version.')
- Writeln('If SRL has just been installed or you are confident you have the latest version, please try again later');
- end
- else
- begin
- Settings.SetKeyValue('SRLVersion', IntToStr(ver));
- Writeln('Successfully updated the local version setting to match the remote!');
- end;
- end;
- procedure DownloadSRL;
- var
- sauce, contents: string;
- begin
- Writeln('Downloading SRL');
- sauce := GetPage('http://wizzup.org/simba/srl/srl.tar.bz2');
- if DecompressBZip2(sauce, contents, 4096) then
- begin
- UnTarEx(contents, IncludePath, True);
- UpdateLocalSRLVersionSetting;
- Writeln('SRL was successfully downloaded and installed without a problem!');
- end
- else
- Writeln('SRL failed to install correctly. Please try again and if the problem persists, check the forums or the IRC channel for news or help');
- end;
- procedure CheckSRLVersion;
- var
- uptodate: Boolean;
- option: Integer;
- begin
- if not(IsSRLDownloaded(uptodate) and uptodate) then
- begin
- option := MessageDlg('SRL Updater', 'SRL was detected as not up-to-date - would you like to update it?', mtConfirmation, [mbYes, mbNo], 0);
- if option = mrYes then
- DownloadSRL
- else
- begin
- Writeln('If you are confident your SRL is up-to-date, you can update the local version setting');
- Writeln('Or you can choose to update SRL - both are accessible via the SRL menu');
- end;
- end;
- end;
- procedure OnSRLUpdaterClick(Sender: TObject);
- begin
- if (Sender = MenuCheck) then
- CheckSRLVersion
- else if (Sender = MenuUpdate) then
- DownloadSRL
- else if (Sender = MenuMove) then
- Writeln('Coming soon!')
- else if (Sender = MenuSetversion) then
- UpdateLocalSRLVersionSetting;
- end;
- procedure Attach;
- var
- uptodate: Boolean;
- option: Integer;
- begin;
- if not started then
- 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 := @OnSRLUpdaterClick;
- MainMenuItem.Add(MenuCheck);
- MenuUpdate := TMenuItem.Create(MainMenuItem);
- MenuUpdate.Caption := 'Update SRL';
- MenuUpdate.OnClick := @OnSRLUpdaterClick;
- MainMenuItem.Add(MenuUpdate);
- MenuMove := TMenuItem.Create(MainMenuItem);
- MenuMove.Caption := 'Move SRL plugins';
- MenuMove.OnClick := @OnSRLUpdaterClick;
- MainMenuItem.Add(MenuMove);
- MenuSetversion := TMenuItem.Create(MainMenuItem);
- MenuSetversion.Caption := 'Set local version to remote';
- MenuSetversion.OnClick := @OnSRLUpdaterClick;
- MainMenuItem.Add(MenuSetversion);
- started := True;
- end
- else
- begin
- MainMenuItem.Visible := True;
- end;
- CheckSRLVersion;
- end;
- Procedure Detach;
- begin
- Writeln('SRL version checking and the like will no longer be checked');
- if started then
- begin
- MainMenuItem.Visible := False;
- end;
- end;
- function GetName : string;
- begin;
- result := 'SRL Include Downloader';
- end;
- function GetVersion : string;
- begin;
- result := '1.0';
- end;
- begin
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement