From 87781e7b9159d77a89002442a05c6c15a1dbdfde Mon Sep 17 00:00:00 2001 From: Olly Date: Tue, 18 Feb 2014 16:45:20 +0000 Subject: [PATCH 1/2] Add new SRL extension. --- Extensions/srl.sex | 167 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 133 insertions(+), 34 deletions(-) diff --git a/Extensions/srl.sex b/Extensions/srl.sex index bc83e8a96..3a9d290bd 100644 --- a/Extensions/srl.sex +++ b/Extensions/srl.sex @@ -31,41 +31,139 @@ begin Result := ForceDirectories(UpdaterArr[I].Folder); end; -function SuccessPlugins(Cont: string; I: integer): boolean; +(* +** Adds a file extension 'bak' to all the files in path, used to we can add files that are currently loaded. +*) +procedure BackupFiles(path: string; files: TStringArray); var - X: integer; - Files: TStringArray; - Overwrite: boolean; + i, h: integer; begin - Files := GetFiles(UpdaterArr[I].Folder, {$IFDEF WIN32}'dll'{$ELSE}'so'{$ENDIF}); - Overwrite := True; + h := high(files); - 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; + if (h < 0) then + exit; + + for i := 0 to h do + begin + if (fileExists(path + files[i] + '.bak')) then // previous backups? + deleteFile(path + files[i] + '.bak'); + + if (fileExists(path + files[i])) then + if (renameFile(path + files[i], path + files[i] + '.bak')) then + writeln('Plugins Updater: Renamed '+ path + files[i] +' to ' + path + files[i] + '.bak') + else + writeln('Plugins Updater: Failed to rename file ' + path + files[i]); + end; +end; + +(* +** Adds a file extension 'bak' to all the directorys in path, used to we can add files that are currently loaded. +*** TO-DO replace rename hack with DeleteDirectory when added to (public) simba version. +*) +procedure BackupDirectorys(path: string; files: TStringArray); +var + i, h, hack: integer; +begin + h := high(files); + + if (h < 0) then + exit; + + for i := 0 to h do + begin + if (directoryExists(path + files[i] + '.bak')) then // previous backups? //TO:DO: REPLACE WITH DELETE_DIRECTORY WHEN IN SIMBA! + begin // DIRTY FIX UNTIL DELETE DIRECTORY IS IN SIMBA! + hack := 0; + + while (directoryExists(path + files[i] + '.bak' + toStr(hack))) do + inc(hack); + + renameFile(path + files[i] + '.bak', path + files[i] + '.bak' + toStr(hack)); end; - if overwrite then + if (directoryExists(path + files[i])) then + if (renameFile(path + files[i], path + files[i] + '.bak')) then + writeln('Plugins Updater: Renamed '+ path + files[i] +' to ' + path + files[i] + '.bak') + else + writeln('Plugins Updater: Failed to rename directory ' + path + files[i]); + end; +end; + +(* +** Gets file but with an array of extensions to find rather than a single one. +*) +function GetFilesEx(path: string; extensions: TStringArray): TStringArray; +var + tmp: TStringArray; + i, h, l, j: integer; +begin + h := high(extensions); + + if (h < 0) then + exit; + + for i := 0 to h do begin - for x := 0 to high(files) do - if FileExists(PluginPath + Files[X]) then - begin - if FileExists(PluginPath + Files[X] + '.bak') then - DeleteFile(PluginPath + Files[X] + '.bak'); - - if RenameFile(PluginPath + Files[X], PluginPath + Files[X] + '.bak') then - writeln('Renamed ' + PluginPath + Files[X] + ' to ' + PluginPath + Files[X] + '.bak') - else - writeln('Plugins Updater: failed to rename ' + PluginPath + Files[X] + ' to ' + - PluginPath + Files[X] + '.bak'); - end; + tmp := GetFiles(path, extensions[i]); + l := length(tmp); + + if (l < 1) then + continue; + + setLength(result, length(result) + l); + + for j := high(tmp) downto 0 do + result[high(result) - j] := tmp[j]; end; +end; + +(* +** Moves files 'srcFiles' from 'srcPath' into 'targPath'. +*) +procedure MoveFiles(srcPath: string; srcFiles: TStringArray; targPath: string); +var + i, h: integer; +begin + h := high(srcfiles); + + if (h < 0) then + exit; + + for i := 0 to h do + if (RenameFile(srcPath + srcFiles[i], targPath + srcFiles[i])) then + writeln('Plugins Updater: Moved file '+srcFiles[i]+' into '+targPath) + else + writeln('Plugins Updater: Failed to move file '+srcPath+srcFiles[i]); +end; + +function SuccessDownload(Cont: string; I: integer): boolean; // called if files are succesfully dl'd +var + ExtensionPath, SavePath: string; + PluginFiles, ExtensionFiles, Folders: TStringArray; +begin + SavePath := PluginPath + '.temp/'; // paths to save the tar.bz2 into + ExtensionPath := AppPath + 'Extensions\'; //dunno why Simba doesn't have this - Result := UnTarEx(Cont, PluginPath, Overwrite); - if not Result then - writeln('Failed to update plugins! Restart Simba and update before starting a script.'); + WriteLn('Plugins Updater: Success Download entered'); + + // gather files + PluginFiles := GetFilesEx(SavePath + 'plugins/', ['dll', 'so', 'jar']); + ExtensionFiles := GetFilesEx(SavePath + 'extensions/', ['sex', 'sei']); + Folders := GetDirectories(SavePath + 'folders/'); + + // backup previous files (so we can keep the current running and update) + BackupFiles(PluginPath, PluginFiles); + BackupFiles(ExtensionPath, ExtensionFiles); + BackupDirectorys(AppPath, Folders); + + // finally move our files into the target directories + MoveFiles(SavePath + 'plugins/', PluginFiles, PluginPath); + MoveFiles(SavePath + 'extensions/', ExtensionFiles, ExtensionPath); + MoveFiles(SavePath + 'folders/', Folders, AppPath); + + Writeln('Plugins Updater: Updated plugins, restart Simba to load the new ones'); + + Result := true; end; procedure ClickRafiki(Sender: TObject); @@ -108,18 +206,19 @@ begin MenuItems[1].OnClick := @ClickBugs; MenuItems[2].OnClick := @ClickHelp; end; - - Settings.GetKeyValueDef('Plugins_Visible', 'false'); - if (AddUpdater('Plugins', 'http://wizzup.org/static/srl/simba_plugins.tar.bz2', 'http://wizzup.org/static/srl/plugins_version', PluginPath + '.temp\', True, True, Plugins)) then - begin - UpdaterArr[Plugins].Hooks[BEFORE_UPDATE] := @BeforeUpdateEx; - UpdaterArr[Plugins].Hooks[SUCCESS_UPDATE] := @SuccessPlugins; - end; if (AddUpdater('SPS', 'http://wizzup.org/static/srl/sps.tar.bz2', 'http://wizzup.org/static/srl/sps_version', IncludePath, True, False, SPS)) then begin UpdaterArr[SPS].Hooks[BEFORE_UPDATE] := @BeforeUpdate; end; + + Settings.SetKeyValue('Plugins_Visible', 'True'); + if (AddUpdater('Plugins', 'http://wizzup.org/static/srl/simba_plugins_new.tar.bz2', 'http://wizzup.org/static/srl/plugins_new_version', PluginPath + '.temp\', True, True, Plugins)) then + begin + UpdaterArr[Plugins].MainMenu.Visible := true; + UpdaterArr[Plugins].Hooks[BEFORE_UPDATE] := @BeforeUpdateEx; + UpdaterArr[Plugins].Hooks[SUCCESS_UPDATE] := @SuccessDownload; + end; end; function GetName: string; From 9f01c94b4d65876eb0aabfa6281d25375eb21037 Mon Sep 17 00:00:00 2001 From: Olly Date: Mon, 3 Mar 2014 20:17:23 +0000 Subject: [PATCH 2/2] Update to use new features. --- Extensions/srl.sex | 96 +++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 60 deletions(-) diff --git a/Extensions/srl.sex b/Extensions/srl.sex index 3a9d290bd..538e6efcf 100644 --- a/Extensions/srl.sex +++ b/Extensions/srl.sex @@ -1,7 +1,6 @@ program SRLUpdater; {$I ./Updater.sei} -{$I ./PlayerManager.sei} function CheckSRL(Name: string; I: integer): boolean; var @@ -58,11 +57,10 @@ end; (* ** Adds a file extension 'bak' to all the directorys in path, used to we can add files that are currently loaded. -*** TO-DO replace rename hack with DeleteDirectory when added to (public) simba version. *) procedure BackupDirectorys(path: string; files: TStringArray); var - i, h, hack: integer; + i, h: integer; begin h := high(files); @@ -71,15 +69,8 @@ begin for i := 0 to h do begin - if (directoryExists(path + files[i] + '.bak')) then // previous backups? //TO:DO: REPLACE WITH DELETE_DIRECTORY WHEN IN SIMBA! - begin // DIRTY FIX UNTIL DELETE DIRECTORY IS IN SIMBA! - hack := 0; - - while (directoryExists(path + files[i] + '.bak' + toStr(hack))) do - inc(hack); - - renameFile(path + files[i] + '.bak', path + files[i] + '.bak' + toStr(hack)); - end; + if (directoryExists(path + files[i] + '.bak')) then // previous backups? + deleteDirectory(path + files[i] + '.bak/', true); if (directoryExists(path + files[i])) then if (renameFile(path + files[i], path + files[i] + '.bak')) then @@ -89,34 +80,6 @@ begin end; end; -(* -** Gets file but with an array of extensions to find rather than a single one. -*) -function GetFilesEx(path: string; extensions: TStringArray): TStringArray; -var - tmp: TStringArray; - i, h, l, j: integer; -begin - h := high(extensions); - - if (h < 0) then - exit; - - for i := 0 to h do - begin - tmp := GetFiles(path, extensions[i]); - l := length(tmp); - - if (l < 1) then - continue; - - setLength(result, length(result) + l); - - for j := high(tmp) downto 0 do - result[high(result) - j] := tmp[j]; - end; -end; - (* ** Moves files 'srcFiles' from 'srcPath' into 'targPath'. *) @@ -142,33 +105,46 @@ var PluginFiles, ExtensionFiles, Folders: TStringArray; begin SavePath := PluginPath + '.temp/'; // paths to save the tar.bz2 into - ExtensionPath := AppPath + 'Extensions\'; //dunno why Simba doesn't have this + ExtensionPath := AppPath + 'Extensions/'; //dunno why Simba doesn't have this WriteLn('Plugins Updater: Success Download entered'); - // gather files - PluginFiles := GetFilesEx(SavePath + 'plugins/', ['dll', 'so', 'jar']); - ExtensionFiles := GetFilesEx(SavePath + 'extensions/', ['sex', 'sei']); - Folders := GetDirectories(SavePath + 'folders/'); - - // backup previous files (so we can keep the current running and update) - BackupFiles(PluginPath, PluginFiles); - BackupFiles(ExtensionPath, ExtensionFiles); - BackupDirectorys(AppPath, Folders); - - // finally move our files into the target directories - MoveFiles(SavePath + 'plugins/', PluginFiles, PluginPath); - MoveFiles(SavePath + 'extensions/', ExtensionFiles, ExtensionPath); - MoveFiles(SavePath + 'folders/', Folders, AppPath); - - Writeln('Plugins Updater: Updated plugins, restart Simba to load the new ones'); - - Result := true; + try + // gather files + PluginFiles := GetFiles(SavePath + 'plugins/', '*'); + ExtensionFiles := GetFiles(SavePath + 'extensions/', '*'); + Folders := GetDirectories(SavePath + 'folders/'); + + // backup previous files (so we can keep the current running and update) + BackupFiles(PluginPath, PluginFiles); + BackupFiles(ExtensionPath, ExtensionFiles); + BackupDirectorys(AppPath, Folders); + + // finally move our files into the target directories + MoveFiles(SavePath + 'plugins/', PluginFiles, PluginPath); + MoveFiles(SavePath + 'extensions/', ExtensionFiles, ExtensionPath); + MoveFiles(SavePath + 'folders/', Folders, AppPath); + + Result := true; + Writeln('Succefully updated plugins, re-load Simba to load new ones'); + except + Result := false; + Writeln('Failed to update plugins, exception raised'); + finally + DeleteDirectory(SavePath, true); + end; end; procedure ClickRafiki(Sender: TObject); +var + RafikiPath: string; begin - RunRafikiPlayerManager; + RafikiPath := IncludePath + 'srl-6/lib/misc/playermanager.simba'; + + if (FileExists(RafikiPath)) then + OpenScriptEx(RafikiPath, True) + else + writeln('SRL: Failed to find Rafiki player manager, Make sure you''ve installed SRL-6!'); end; procedure ClickBugs(Sender: TObject);