Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 47

Thread: Pak Files?

  1. #21

    Pak Files?

    Well, i've been messing with file handling trying to learn it real well, and im curious... When I write a string to the filestream like:

    Stream.Write('asd',66785);

    What's all those random characters it writes to the file after 'asd' since the buffer is 3 chars long, not 66785.?
    I have a 2005 CRF 250 so <^>(>&lt<^>
    <br />http://www.gtrpg.com/

  2. #22

    Pak Files?

    Write writes the number of bytes you tell it to, if you're variable is only 3 bytes long and you attempt to write 66785 bytes then if not causing an access violation you'll also write 66782 bytes of whatever is in memory after your variable.

  3. #23

    Pak Files?

    Thanks.

    Back onto my pak file question and from what alimonster wrote:

    How do i find the location of my file headers? Since every file is suppose to be put in the top of the package file one after another and I add all the file information at the end like you said, how do i locate those at the end?
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  4. #24
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Pak Files?

    Out of interest have you thought of using a Zip file to store the information. The dzlib components have a method to read the zipped file directly into a stream thereby not leaving anything on the hard disk.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  5. #25

    Pak Files?

    Store you're file header count at the end of the file, then when reading seek to the end of the stream ?¢_" sizeof(integer) and read the header count, seek back NumberOfHeaders * sizeof(THeader) and there you are.

  6. #26

    Pak Files?

    Thanks Paulius.

    Cairns, I have thought about it, but would just much rather learn this part my own.
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  7. #27

    Pak Files?

    Ok i think i have most this technique down. But 1 question left.

    When adding a file to a pack, I write the actual file data at the end of all the other file data, but above the headers. This position can be found by reading all the existing headers and just adding together the filesizes. After adding that data, you then add a header for that data at the very bottom of the file, leaving a few bytes to store how many headers there are at the very end of the file. Correct?

    My question is, more of a clarification.... To write a file to a certian spot in a file, i simple to Stream.SeekTo(0, AllOfHeaderSizesAdded); then Stream.WriteBuffer(NewFileStream, Length(NewFileStream); ?
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  8. #28

    Pak Files?

    Almost correct, the Seek method takes two parameters, the first one is the Position in the stream (so AllOfHeaderSizesAdded) and the second parameter tells the method where to start counting. The second parameter can for example be soFromBeginning or soFromEnd so
    Seek(23653, soFromBeginning) seeks to the 23653rd byte from the beginning of the file.

    Also, your package files consist of three individual parts: the file data at the beginning, a list of all files and a footer which stores the file count.

    When you want to append files to your package, you'll have to seek to the position right after the last file in the package and then write the new file there. You will then have to re-build the entire file index and the footer so it's a good idea to create a copy of the index list before appending a file.

    Here's an image that should clarify the structure of a package file for you
    Ask me about the xcess game development kit

  9. #29

    Pak Files?

    And how do i write a file in at an exact position? (Just so i dont mess this up)
    I have a 2005 CRF 250 so &lt;^&gt;(&gt;&lt&lt;^&gt;
    <br />http://www.gtrpg.com/

  10. #30

    Pak Files?

    [pascal]
    var
    PackageStream, FileStream: TFileStream;
    BehindLastFile: Int64;
    begin
    {...}
    FileStream.Create('C:\somefile.abc', fmOpenRead);
    FileStream.Seek(0, soFromBeginning);
    PackageStream.Seek(BehindLastFile, soFromBeginning);
    PackageStream.CopyFrom(FileStream, FileStream.Size);
    FileStream.Free;
    ReBuildFileIndex;
    ReBuildFooter;
    end;
    [/pascal]
    Ask me about the xcess game development kit

Page 3 of 5 FirstFirst 12345 LastLast

Bookmarks

Posting Permissions

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