SFML community forums

General => General discussions => Topic started by: nietaki on January 07, 2012, 03:20:54 pm

Title: cross-platform c++ resource container library?
Post by: nietaki on January 07, 2012, 03:20:54 pm
I spent a better part of today searching the web for a good library/way to store resource files in packages in my project. There were many nice leads, but none of them seemed right for me.

Here's what I mean by good:

- cross-platform (my team already develops on linux, windows and OSX)
- c++, not c - I've got enough problems as it is without linking my c++ code to c
- the compression isn't a priority, the main objective is to minimize the number of reads from hdd
- easy to use/build automatically with CMake (?)

and what I found:
- the hailed zlib doesn't seem to have cross platform c++ wrapper
- zipios++ is a long dead beta project
- http://icculus.org/physfs/ looks great, but also lacks the wrappers

...and so on and on.

Surely one of you guys knows/has used a good alternative. As I said, I don't specifically need zip, just a way to store multiple files in one file (preferably in a semi-structured way).
Title: cross-platform c++ resource container library?
Post by: Nexus on January 07, 2012, 04:15:39 pm
Currently I also search for such a library ;)

However I don't think C should be a big problem if the library follows a clean code style and is well documented. I'm probably having a look at PhysicsFS. There is also a code for sf::InputStream integration on the wiki, and it seems that there are other C++ wrappers on the internet...

Additionally I've heard about snappy (http://code.google.com/p/snappy/source/list), but it's rather a compression library. I would like further suggestions, too :)
Title: cross-platform c++ resource container library?
Post by: Elgan on January 07, 2012, 04:47:16 pm
just started playing with physfs/ , great so far. I didnt get static lib working just yet but I'm not bothered right now.

physfs I'm using as c right now, no problems for me.

I will be building it into the engine class and using it to manage all resources in the end , unless I find something better.

zlib is not cross platform, why?

the other option would be to just write a decompression thing similar, but why reinvent the wheel.....there is loads of c++ examples around though. - I would only be doing this to make the code smaller and dependencies less.
Title: cross-platform c++ resource container library?
Post by: caracal on January 07, 2012, 05:16:52 pm
Try googles snappy library http://code.google.com/p/snappy/ the readme is here http://code.google.com/p/snappy/source/browse/trunk/README

I am looking at packing my data into Googles protocol buffers and compressing that with snappy.

Personally I would use any decent zip library because zip is supported on every platform its fast with decent compression and it does both compression and archiving.
Title: cross-platform c++ resource container library?
Post by: nietaki on January 07, 2012, 10:32:11 pm
One more thing I found:
zlib is bundled with minizip (http://www.winimage.com/zLibDll/minizip.html) a c library which can perform .zip file operations. And on it's homepage I found a mention of Daniel Godson's C++ wrapper (with an already dead link). But searching for the code on Koders.com I found something else:
http://www.koders.com/cpp/fid111F28C8BEF7DCD0A18FD13F7108BAEC218ED74D.aspx?s=nanohive+unzipper#L38
The Unzipper class is part of a larger project (http://nanoengineer-1.com/nh1/index.php?option=com_content&task=view&id=34&Itemid=44) which should work both under Windows and Linux. The files interesting to us are free to use and they themselves use the zlib library.

I won't tamper with it just yet, but it looks pretty promising, I think I'll be trying to get it working some time soon...
Title: cross-platform c++ resource container library?
Post by: Tank on January 08, 2012, 08:42:03 am
If you really only want to pack multiple files into a container, why not do it yourself? It's quite simple to do (an index with offsets to the files and sizes and the data itself). You can even apply compression before you save and decompression before you load.
Title: cross-platform c++ resource container library?
Post by: Nexus on January 08, 2012, 04:17:19 pm
Does anybody know a proper wrapper around the 7z/LZMA API? PhysicsFS encapsulates that very nicely, but unfortunately it doesn't provide advanced features like password protection.

The LZMA SDK has one of the worst documented APIs I've ever seen... :|
Title: cross-platform c++ resource container library?
Post by: Oberon on January 08, 2012, 06:34:46 pm
It's not documented at all (apart from one or two comments). :x But you *can* understand the API. Start with <7z SDK dir>\CPP\7zip\UI\Client7z, which is an minimal example. It demonstrates opening, writing to and displaying the contents of an archive.
Title: cross-platform c++ resource container library?
Post by: asdatapel on January 10, 2012, 11:21:32 pm
Quote from: "Tank"
If you really only want to pack multiple files into a container, why not do it yourself? It's quite simple to do (an index with offsets to the files and sizes and the data itself). You can even apply compression before you save and decompression before you load.


Could you show a code sample or link me to a resource. It'd be very helpful
Title: cross-platform c++ resource container library?
Post by: Tau Sudan on January 11, 2012, 09:04:05 am
Quote from: "asdatapel"
Quote from: "Tank"
If you really only want to pack multiple files into a container, why not do it yourself? It's quite simple to do (an index with offsets to the files and sizes and the data itself). You can even apply compression before you save and decompression before you load.


Could you show a code sample or link me to a resource. It'd be very helpful


That is actually something that would be a good exercise in a 1st year course in programming.  Hell, if I teach again, I'll probably do it.

open file
read in "header bytes" as you've defined them
read in the number of bytes required for each file and store them as appropriate in variable
close file
do what you want with the data

Similarly for saving.


If you don't know how to do any one of those operations in your language of choice, then, in all seriousness, you need to buy a book, or take a class.

For books, I would recommend any of the O'Reilly Learning series for what ever programming language you are programming (should it exist), or the Dietel & Dietel How to Program series.  The selection of the D&D books is extensive.  So, I'd be surprised if they don't have the language that you're looking for.

When it comes to courses, for practical programming, you'd be better off finding a technical college than a University.  Any intro course should do… should.
Title: cross-platform c++ resource container library?
Post by: thePyro_13 on January 11, 2012, 10:39:13 am
Quote from: "asdatapel"
Quote from: "Tank"
If you really only want to pack multiple files into a container, why not do it yourself? It's quite simple to do (an index with offsets to the files and sizes and the data itself). You can even apply compression before you save and decompression before you load.


Could you show a code sample or link me to a resource. It'd be very helpful
This article (http://archive.gamedev.net/archive/reference/programming/features/pak/) on the Gamedev.net archive site may be of interest to you.