Simba Code:
(*******************************************************************************
SIMBA FILE CHECKER v3
- BY ZYT3X
03 Jan 2013
*******************************************************************************)
{$DEFINE ssTest}
{$IFDEF ssTest}
const
DEFAULTDIR = 'C:\SkyDrive\Private\Programming\Scripting\';
{$ENDIF}
{$IFDEF LAPE}
{$IFNDEF SRL}
// From SRL-6
procedure TStringArray.append(const str : String; const index : Integer);
var
I : Integer;
begin
setLength(self, length(self)+1);
for I := high(self)-1 downto index do
self[I+1] := self[I];
self[index] := str;
end;
// From SRL-6
procedure TStringArray.append(const str : String); overload;
begin
self.append(str, length(self));
end;
// From SRL-6
function TStringArray.returnInArray(const str : String) : Integer;
var
I : Integer;
begin
result := -1;
for I := 0 to high(self) do
if self[I] = str then
begin
result := I;
exit;
end;
end;
// From SRL-6
function TStringArray.isInArray(const str : String) : Boolean;
begin
result := returnInArray(str) > -1;
end;
// From SRL-6
procedure TStringArray.clearSame();
var
I : Integer;
arr : TStringArray;
begin
for I := 0 to high(self) do
if not arr.isInArray(self[I]) then
arr.append(self[I]);
self := arr;
end;
{$ENDIF}
function getAllDirectoriesFromPath(const path : String) : TStringArray;
var
I, J, H : Integer;
dirs : TStringArray;
begin
result := getDirectories(path);
for I := 0 to high(result) do
result[I] := path + result[I] + '\';
while (high(result) <> H) do
begin
H := high(result);
for J := 0 to H do
begin
dirs := getDirectories(result[J]);
for I := 0 to high(dirs) do
result.append(result[J] + dirs[I] + '\');
end;
result.clearSame();
end;
result.append(path);
end;
function getAllFilesFromPaths(const paths : TStringArray;
const extType : String) : TStringArray;
var
I, J : Integer;
files : TStringArray;
begin
for J := 0 to high(paths) do
begin
files := getFiles(paths[J], extType);
for I := 0 to high(files) do
result.append(paths[J] + files[I]);
end;
result.clearSame();
end;
function getAllFilesFromPath(const path, extType : String) : TStringArray;
begin
result := getAllFilesFromPaths(getAllDirectoriesFromPath(path), extType);
end;
function searchAllFilesFromPaths(const searchString : String;
const paths : TStringArray; const extension : String;
const regexSearch, caseSensitive : Boolean = False): TStringArray;
var
allFiles := getAllFilesFromPaths(paths, extension);
F, I : Integer;
S, searchStr : String;
found : Boolean;
begin
searchStr := searchString;
if not caseSensitive then
searchStr := lowerCase(searchString);
for I := 0 to high(allFiles) do
begin
if not fileExists(allFiles[I]) then continue;
try
F := openFile(allFiles[I], False);
readFileString(F, S, fileSize(F));
closeFile(F);
except
continue;
end;
if not caseSensitive then
S := lowerCase(S);
case regexSearch of
True: found := execRegExpr(searchStr, S);
False: found := pos(searchStr, S) <> 0;
end;
if found then
result.append(allFiles[I]);
end;
end;
function searchAllFilesFromPath(const searchString, path, extension : String;
const regexSearch, caseSensitivity : Boolean = False): TStringArray;
begin
result := searchAllFilesFromPaths(searchString,
getAllDirectoriesFromPath(path), extension, regexSearch, caseSensitivity);
end;
{$IFDEF ssTest}
var
found : TStringArray;
I : Integer;
SEARCH, DIR, RES : String;
REGEX, CASESENS : Boolean;
begin
if not inputQuery('Script Searcher', 'Input search string:', SEARCH) then exit();
if SEARCH = '' then exit();
inputQuery('Script Searcher', 'Input search path start: (has to end with a \)', DIR);
if DIR = '' then DIR := DEFAULTDIR;
REGEX := messageDlg('Script Searcher', 'Use Regex search?', mtConfirmation, [mbYes, mbNo]) = 1;
CASESENS := messageDlg('Script Searcher', 'Use Case sensitivity?', mtConfirmation, [mbYes, mbNo]) = 1;
found := searchAllFilesFromPath(SEARCH, DIR, 'simba', REGEX, CASESENS);
if length(found) > 0 then
begin
messageBox(toStr(length(found)) + ' scripts found containing ' + SEARCH, 'Script Searcher', 0);
writeLn('Scripts containing '#39 + SEARCH + #39':');
end else
messageBox('No scripts found.', 'Script Searcher', 0);
for I := 0 to high(found) do
writeLn(' (' + toStr(I+1) + '): ' + between(DIR, #13, found[I]+#13));
end.
{$ENDIF}
{$ELSE}
begin
messageDlg('Script Searcher', 'Cannot run the Script Searcher when the interpeter is set to Pascal Script, to fix this go-to: (Script > Interepeter > Select Lape)', mtError, [mbOk]);
end;
{$ENDIF}