Results 1 to 9 of 9

Thread: TFile.simba

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default TFile.simba

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

    Simba Code:
    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

  2. #2
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    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.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    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

    Simba Code:
    {$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)

  4. #4
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    FYI,
    Simba Code:
    function TFile.readString():string; overload;
    begin
      result := self.readString(50000);
    end
    should really just be
    Simba Code:
    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...)

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    FYI,
    Simba Code:
    function TFile.readString():string; overload;
    begin
      result := self.readString(50000);
    end
    should really just be
    Simba Code:
    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)

  6. #6
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    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.


    Be nice.
    Working on: Tithe Farmer

  7. #7
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    Quote Originally Posted by Turpinator View Post
    It all seems useless (like the overwhelming majority of everything else you have posted).
    Quote Originally Posted by Robert View Post
    Can't be anymore useless then sending a email through simba straight to junk
    RJJ vs. Xtrapsp round 2?

  8. #8
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    RJJ vs. Xtrapsp round 2?
    I'm just saying there's literately no point is posting discouraging stuff like that...

  9. #9
    Join Date
    Jan 2012
    Posts
    1,596
    Mentioned
    78 Post(s)
    Quoted
    826 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Eat a snickers turpinator.


    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/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •