PDA

View Full Version : TFile.simba



rj
04-24-2014, 10:22 PM
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
04-25-2014, 01:22 AM
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
04-25-2014, 02:46 AM
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','glo bals','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','integerarra ys','string',
'stringarrays','t2dstringarray','tbox','tpoint','t pointarrays',
'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
04-25-2014, 06:39 AM
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
04-25-2014, 09:42 AM
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
04-25-2014, 08:19 PM
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.
uii3VhELiuE

Be nice.

The Mayor
04-25-2014, 09:51 PM
It all seems useless (like the overwhelming majority of everything else you have posted).


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

RJJ vs. Xtrapsp round 2?

rj
04-25-2014, 11:10 PM
RJJ vs. Xtrapsp round 2?

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

Turpinator
04-27-2014, 04:47 AM
Eat a snickers turpinator.
uii3VhELiuE

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/