Results 1 to 8 of 8

Thread: resource file support?

  1. #1

    resource file support?

    A game i'm working on uses a lot of small files and the waste of disk space is huge (2MB ocupy around 4MB on disk). I was wondering if there was some free component to support zip files. I don't really care about compresion, i just want to have one resource file with directory structure in it.

  2. #2

    resource file support?

    Have a look through Torry and The Delphi Super Page. A quick browse found heaps of zip components, many of which are freeware.

    Alternatively, simply pack the file yourself using lots of blockreads/blockwrites. You'd have a helper application that stored all the files you packed together in a table. You would do this:

    1) create a new file
    2) empty out the table
    3) for each file in dir...
    3.1) add file name, size to table
    3.2) blockwrite the file to the packed file
    4) write out the header once done to the end
    5) write out the size of the header

    Then, when reading in the file, you would see to the end of the file minus however-many-bits for the size of the header (e.g. four 4 bytes for an integer size). You'd then allocate that amount of space for a new header and would seek back to the header start in the file.

    Once you have the header, you can get the name/offset of any file in there.

    Uh, the above is from the top of my head and may not work correctly. I'll do a working demo of it when I get back home.

    There's also a tutorial over at describing how to use zip files to combine stuff but with no compression - what you want, but it's in C++.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    resource file support?

    Thanks for your reply Alimonster, but all free components i find simply extract files to disc. Can anyone give me the name of a component which whould extract files in the memory. Or i'll just wait for Alimonster's demo.

  4. #4

    resource file support?

    Quote Originally Posted by Paulius
    Can anyone give me the name of a component which whould extract files in the memory. Or i'll just wait for Alimonster's demo.
    This is simple to obtain.. just do what alimonster said: create a small utility that write all the file you need on a single file (with the appropriate headers). Than you can load single chunks of the file in memory, for example using the TMemoryStream (great class!). With this you can load all your objects with the LoadFromStream method that is implemented in lots of classes
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href=""></A>

  5. #5

    resource file support?

    I've hacked up an example program. Caveat emptor and all that stuff...

    Get it here (6K).

    Start it up and you should hopefully see the contents of the packed file. You can select one in the listbox and hit the "View entry" button to see that bitmap. Of course, you can pack any amount of any type of file, not just bitmaps, but I did it for .bmps simply for clarity.

    Don't push the interface too hard - I didn't design for stability, so it may explode. It's only for demo purposes here .

    I hardly ever use the stream classes now, mind you. Anyway, you might want to structure the code a bit better (make it into a class, for example). However, the main code is there and it works.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  6. #6

    resource file support?

    Thanks a lot Alimonster, the domo was very helpful. I get one error with your demo on my system, maybe it's because i'm using Delphi 5?
    procedure TfrmPackerMain.btnAddClick(Sender: TObject);
    if dlgOpen.Execute then

    btnSave.Enabled:= (lstFiles.Count > 0);// i get undeclared identifier: 'Count'
    This isn't realy a problem, i just wanted to let you know.

  7. #7

    resource file support?

    And i think it should have been
    nstead of
    in TfrmPackerMain.btnAddClick

  8. #8

    resource file support?

    Yeah, you're probably right on that last one w/ Assign vs AddStrings, btw . I didn't spend too long on the interface, which is why I gave a disclaimer or two during my last post . There are probably more bugs around there too! I may write an article on this for my site w/ proper o.o. (tested!) code - until then, I'm afraid, you'll have to treat the interface as "possibly buggy." I'm not going to fix any bugs in there ^_^.

    The other one about "lstFiles.Count" is obviously a new thing in Delphi 6 - it's a shortcut that simply maps to "lstFiles.Items.Count". I didn't realise that it wasn't in earlier Delphi versions (good to know for compatbility...). Ah well, you live, you learn. (The demo was made in Delphi 6.)

    If you plan on turning it into a class, remember to make the variables "FFileSize" and "LastPack" into class members.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle


Posting Permissions

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