delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
497 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (4)


How to really make a resource fileComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Games
Skill Level:
Scoring:
Last Update:
12/28/2001
Search Keys:
delphi delphi3000 article borland vcl code-snippet game resource file uncompressed offset header record
Times Scored:
3
Visits:
5131
Uploader: Martin Ellis
Company: DowN Industries
Reference: http://www.themodplace.co.uk
Component Download: http://www.themodplace.co.uk/modkit
 
Question/Problem/Abstract:
Creating a sort of uncompressed Zip file to store all the files required for a game or any other program that requires additional files.
Answer:



Instead of having loads of files for your games distributed all over the place, you can stick all your files into a single package, you find these used in almost every game out.

To make these files requires a header which can be a set length then all the files, followed by each files information in equal segments:

[HEADER]
[FILE1]
[FILE2]
...
[FILEN]
[FILE1INFO]
[FILE2INFO]
...
[FILENINFO]

this can easily be achieved and you can have lots of other 'addins' such as putting files in sub directories, special properties being set for each file etc....

first off you need a header, this usually consists of 4 things

type
  header = record
  Signature: array [1..4] of char;
  Version: LongInt;
  fileoffset: LongInt;
  fileentries: LongInt;
end;


The signiture could be anything that you wish, but it is used for checking if the file is a valid package file for your program. next is the version, you may wish to improve the package file over time or have an increment system for your application so that a file in an newer package, determined by the version number would overide that of a file in an older package.

Next is the fileoffset, this points to the begining of the file info section after the last file in the package.

FILEENTRIES is used for counting how many file info entries there are, so u can have a loop running reading off the entries if you so wished.


so create ur file then write in the header

wfile.Write(head, SizeOf(head));

next comes the adding of the actual files this can be done by using TFileStream then

rfile.create('filename',fmopenread);

wfile.copyfrom(rfile,rfile.size);

continue writing the files next comes writing the file info, this must be done either after adding all the files or while adding one file to the final file you create a temporary file and add the file info to the file then, then when finished 'stick' the temp file onto the end of the final file. There is other options available, but they are upto you to discover.

The File Info entries MUST be all of the same size for this example i have used 44 bytes but you could use anything aslong as it is the same, having large file info entries will dramatically increase your file size so i would sujest someting around 44 bytes.

type
tfilenametype = array [0..29] of char;
direntry = record
offset: longint;
size: longint;
filename: tfilenametype;
timestamp: longint;
end;

offset = the position from the begining of the package file. and the size value = the size of that file it refrences. so that you can seek and read the file out of the package. Filename is obvious and the timestamp would be fileage('filename');

add this all into a file and then u have your package, reading it is just of case of reading instead of writing the file, but using this as a guide you could take this far

--------------------
Hope it helps

Martin






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Is it still loading?
    Dan (Dec 29 2001 3:57PM)

Check this GDC article if this is not enought for you.
Respond

RE: Is it still loading?
Dan (Dec 29 2001 3:58PM)

I kan't splee.. :)
Respond

RE: RE: Is it still loading?
Martin Ellis (Dec 29 2001 7:32PM)

except that that is in C/C++ this is a delphi version :)
Respond

RE: RE: RE: Is it still loading?
anonymus (Jan 2 2002 6:29PM)

Yes, you can download sample c++ source for that article. but it's still an excellent article showing how to make a good file system.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Shkolnik
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)