SRL Archive - SRL Snippets

TFile.simba


rj

2014-04-24 18:22:30

TFile.simba adding to my include to use for auto updating… pretty much lape version of all the find stuff

type
TFile = record
path, name, extension, data, realPath:string;
end;

function TFile.exists():boolean;
var
s:TStringArray;
i:Integer;
begin
s := GetFiles(self.path, self.extension);
for i := 0 to high(s) do
if (s[i] = (self.name +'.' + self.extension)) then
exit(true);
end;

procedure TFile.recall(const filePath, fileName, fileExtension:string);
begin
self.path := path;
self.name := name;
self.extension := fileExtension;
self.realPath := filePath + fileName + '.' + fileExtension;
end;

function TFile.open():integer;
begin
result := openFile(self.realPath, true);
end;

function TFile.readString(const strLength:integer):string;
var
tmpFile:integer;
str:string;
begin
tmpFile := self.open();
try
ReadFileString(tmpFile, str, strLength);
finally
result := str;
closeFile(tmpFile);
end;
end;

function TFile.readString():string; overload;
begin
result := self.readString(50000);
end;

function TFile.rewrite():integer;
begin
try
result := rewriteFile(self.realPath, true);
except
end;
end;

function TFile.setText(const str:string):boolean;
var
tmpFile:integer;
begin
if (not self.exists()) then
exit();
try
tmpFile := self.rewrite();
writeFileString(tmpFile, str);
closeFile(tmpFile);
except
end;
end;

function TFile.parseData(const str1, str2:string):string;
var
str:string;
begin
result := between(str1, str2, self.readString());
end;

function TFile.delete():boolean;
begin
result := deleteFile(self.realPath);
end;

procedure TFile.create(const filePath, fileName, fileExtension:string);
var
tmpFile:integer;
begin
if self.exists() then
begin
self.recall(filePath, fileName, fileExtension);
exit();
end;
try
self.path := filePath;
self.name := fileName;
self.extension := fileExtension;
self.realPath := filePath + fileName + '.' + fileExtension;
tmpFile := createFile(self.realPath);
closeFile(tmpFile);
except
end;
end;

var
settingsFile:TFile;

begin
settingsFile.create('C:\Simba\', 'test', 'txt');
settingsFile.setText(getPage('http://pastebin.com/raw.php?i=WFS9KJtK'));
writeln(settingsFile.parseData('<news>','</news>'));
settingsFile.delete();
end.

Planning on adding more functions (such as include updater) later

Flight

2014-04-24 21:22:38

This is pretty cool Robert, I'll be keeping an eye on this. I need a solid way to keep AL updated when I release it and make future changes, perhaps this could be an option.

rj

2014-04-24 22:46:38

From: Flight
This is pretty cool Robert, I'll be keeping an eye on this. I need a solid way to keep AL updated when I release it and make future changes, perhaps this could be an option.


Working on the include updater ATM

{$I Soulsplit/core/file.Simba}

type
TUpdateNode = record
link:string;
sourceFile:TFile;
end;

TUpdateSystem = array of TUpdateNode;

var
soulsplitUpdater:TUpdateSystem;

procedure TUpdateNode.create(f:Tfile;pageLink:string);
begin
self.sourceFile := f;
self.link := pageLink;
end;

procedure TUpdateSystem.addNode(f:Tfile;pageLink:string);
begin
setLength(self, length(self) + 1);
self[length(self) - 1].create(f, pageLink);
end;

procedure TUpdateSystem.init;
var
FNA, PA:TStringArray;
i:integer;
begin
self.addNode(newFile(appPath + 'Includes\Soulsplit\', 'Soulsplit', 'simba'), 'http://pastebin.com/raw.php?i=wbJqtXSY');

FNA := ['bank','chatbox','directory','file','gametab','globals','interface',
'inventory','login','mainscreen','math','minimap','mouse','prayer',
'text','timing']
for i := 0 to high(FNA) do
self.addNode(newFile(appPath + 'Includes\Soulsplit\core', FNA[i], 'simba'), PA[i]);

self.addNode(newFile(appPath + 'Includes\Soulsplit\misc', 'debug', 'simba'), PA[i]);
self.addNode(newFile(appPath + 'Includes\Soulsplit\misc', 'simba', 'simba'), PA[i]);

FNA := ['extended','extendedarrays','integer','integerarrays','string',
'stringarrays','t2dstringarray','tbox','tpoint','tpointarrays',
'tstringarrays','typemath','types']
for i := 0 to high(FNA) do
self.addNode(newFile(appPath + 'Includes\Soulsplit\misc\datatypes', FNA[i], 'simba'), PA[i]);
end;

procedure TUpdateSystem.update;
var
i:integer;
f:TFile;
p:string;
begin
for i := 0 to high(self) do
begin
p := getPage(self[i].link);
if (length(p) <> length(self[i].sourceFile.readString())) then
begin
writeln('Updating file ' , self[i].sourceFile.realPath);
f.create(self[i].sourceFile.Path, self[i].sourceFile.name, 'simba', p, true);
end;
end;
end;

begin
soulsplitUpdater.init();
soulsplitUpdater.update();
end.

http://pastebin.com/tgc0dwDf
So that the latest files are updated (because if a new file is added to the include the script wouldn't know)

Turpinator

2014-04-25 02:39:07

FYI,
function TFile.readString():string; overload;
begin
result := self.readString(50000);
end
should really just be
function TFile.readString():string; overload;
begin
result := self.readString(FileSize(self.open()));
end
yet still, the functions lack (the majority of them) any file closes/handle releases.

still, not really sure what im looking at here. it all seems useless. (like the overwhelming majority of everything else you have posted…)

rj

2014-04-25 05:42:43

From: Turpinator
FYI,
function TFile.readString():string; overload;
begin
result := self.readString(50000);
end
should really just be
function TFile.readString():string; overload;
begin
result := self.readString(FileSize(self.open()));
end
yet still, the functions lack (the majority of them) any file closes/handle releases.

still, not really sure what im looking at here. it all seems useless. (like the overwhelming majority of everything else you have posted…)


1 function without file release.


Explain to me how this is useless (Can't be anymore useless then sending a email through simba straight to junk)

masterBB

2014-04-25 16:19:00

From: Turpinator
still, not really sure what im looking at here. it all seems useless. (like the overwhelming majority of everything else you have posted…)


Eat a snickers turpinator.
[youtube]uii3VhELiuE[/youtube]

Be nice.

The Mayor

2014-04-25 17:51:14

From: Turpinator
It all seems useless (like the overwhelming majority of everything else you have posted).


From: Robert
Can't be anymore useless then sending a email through simba straight to junk


RJJ vs. Xtrapsp round 2?

rj

2014-04-25 19:10:04

From: The Mayor
RJJ vs. Xtrapsp round 2?


I'm just saying there's literately no point is posting discouraging stuff like that…

Turpinator

2014-04-27 00:47:48

From: masterBB
Eat a snickers turpinator.
[youtube]uii3VhELiuE[/youtube]

Be nice.

who are these people? clearly this one was never shown in the US.

side note bart, whenever i see a deBoer truck, i think of you. ;)
http://deboertrans.com/