I have a lot of small files I need to ship with an application I build and I want to put this files into an archive to make copying and redistributing more easy.
I also really like the idea of having them all in one place so I need to compare the md5 of one file only in case something goes wrong.
I'm thinking about a class which can load the archive and return a list of files within the archive and load a file into memory if I need to access it.
I already searched the Internet for different methods of achieving what I want and found out about zlib and the lzma sdk.
Both didn't really appeal to me because I don't really found out how portable zlib is and I didn't like the lzma sdk as it is just to much and I don't want to blow up the application because of this problem. Another downside with zlib is that I don't have the C/C++ experience (I'm really new to C++) to get everything explained in the manual.
I also have to add that this is a time critical problem. I though some time about implementing a simple format like tar in a way I can easy access the files within my application but I just didn't find the time to do that yet.
So what I'm searching for is a library that allows me to access the files within an archive. I'd be glad if anybody could point me in the right direction here.
Thanks in advance,
Robin.
Edit: I need the archive to be accessed under linux and windows. Sorry I didn't mention that in the beginning.
For zipping, I've always been partial to ZipUtils, which makes the process easy and is built on top of the zlib and info-zip libraries.
The answer depends on whether you plan to modify the archive via code after the archive is initially built.
If you don't need to modify it, you can use TAR - it's a handy and simple format. If you want compression, you can implement tar.gz reader or find some library that does this (I believe there are some available, including open-source ones).
If your application needs random access to the data or it needs to modify the archive, then regular TAR or ZIP archives are not good. Virtual file system such as our SolFS or CodeBase file system will fit much better: virtual file systems are suited for frequent modifications of the storage, while archives target mainly write-once-read-many usage scenarios.
zlib is highly portable and very widely used. if you can't make sense of the C++ interface, there are alternatives for many other languages - see 'Related External Links' here.
Take another look before you search for something different.
If you're using Qt or Windows you can also pack data into the executable's resource area. You would only have to distribute the executable file using this technique. There's a well defined API already written and tested to access that data.
The zlib API is the way to go. Simple and portable. Lookat unzip.h header for APIs that access archive files. It is in C and very easy.
If the files are small, you can dump them into string literals (search for bin2h utility) and include in your project. Then change the code that read the files. If all files are currently read using ifstream class, simply changing it to istringstream class and recompile the code.
Try using Quazip - it's quite simple to use. You can use it as a stream from which you read the compressed file on the fly.
Related
So, I recently came across the .unity3d file for a game a used to play, and unpacked it using a tool. (http://en.unity3d.netobf.com/) Now, I've made the tweaks the the game I needed to to make it run on a local server, and have come across the issue of how to compress the files back into a .unity3d file. I've reverse engineered the tool and determined that .unity3d files are LZMA compressed( just like a .7z archive ), but the header is "UnityWeb" instead of "7z". How might I achieve this?
7z is open source. If the only difference is indeed that header, then get the sources, find where the header is, change it and compile your own compression utility. Watch out for other constants describing the headers and signatures though (e.g. length of the signature). I'd suggest starting with line 9 of the file Xz.c (defining XZ_SIG and XZ_FOOTER_SIG).
I'm making a simple game with SFML 1.6 in C++. Of course, I have a lot of picture, level, and data files. Problem is, I don't want these files visible. Right now they're just plain picture files in a res/ subdirectory, and I want to either conceal them or encrypt them. Is it possible to put the raw data from the files into a resource file or something? Any solution is okay to me, I just don't want the files exposed to the user.
EDIT
Cross platform solutions best, but if they don't exist, that's okay, I'm working on windows. But I don't really want to use a library if it's not needed.
Most environments come with a resource compiler that converts images/icons/etc into string data and includes them in the source.
Another common technique is to copy them into the end of the final .exe as the last part of the build process. Then at run time, open the .exe as a file and read the data from some determined offset, see Embedding a filesystem in an executable?
The ideal way for this is to make your own archive format, which would contain all of your files' data along with some extra info needed to split files distinctly within it.
I want to create a single data file that holds all the data that my game will need, and I want it to be compressed. I looked into tar and gzip, but I downloaded their sources and I don't know where to begin. Can somebody give me some pointers to how I can use these?
Unless you will always load all files from the archive, TAR/GZ might not be a very good idea, because you cannot extract specific files as you need them. This is the reason many games use ZIP archives, which do allow you to extract individual files as required (a good example is Quake, whose PK3 files are nothing but ZIP files with a different extension).
A bit of searching brought up Minizip, which is a ZIP library built on top of zlib. I couldn't find any separate documentation for it, but the header files seem to include a lot of comments, and I believe you can get off with it.
If you mean that you want your game to read out of the archive at runtime, then I recommend decompressing each time the game is run into a temporary folder, and then using the files as required. This can be achieved through using a library for decompressing whatever archive format you use. Look into zlib.
I am thinking i might want to port a lib to read a DVD filesystem. I am not talking about movies but datadisc. Theres existing code for me to do raw reads from the disc. I need code that request this data and allow me to browse files on the disc. What lib can i use for this?
-edit- NOTE: I am using an OSless hardware. Ppl seem to miss that but Alnitak caught it and gave me a great answer :)
You need libudf which is part of GNU libcdio.
If you want to browse files, why not let your operating system do the heavy lifting? Given that a modern OS will already have everything it needs to mount filesystems from DVDs -- and that there will be numerous people already using and debugging this code, as opposed to a smaller and more focused userbase for a userspace library such as libdvdread -- it seems silly not to leverage them.
Why not just use the same I/O libs you'd use to read files from a hard disk?
I want to place all my programs content in a compressed archive file as its starting to get quite large. I know theres a few libraries around like zlib but i dont know how to make them do what I want to do:
Be able to load textures/models etc from the file, curretly im using d3dx methods such as D3DXCreateTextureFromFileEx. I dont really want to have to write my own image loaders for the diffrent formats I want, so I need some way to be compatible with these d3d methods. I know they have a way to load from an in-memory file, would it be suitable to extract the file into memory somehow then load that?
Be able to use c++ streams with files in the compressed archive eg:
std::zipstream file("data.zip:sounds/beep.wav", std::ios::in | std::ios::binary);
I'd recommend looking at open source games (quake3 for example). Some of them are packing resources and have working implementations of "virtual file system", as Vilx noted. You might get some ideas.
There is an article entitled Programming a Virtual File System archived on flipcode that should provide what you need. If you have questions specific to that article, many former flipcode members now frequent the forums at DevMaster.net.
There are ready made libraries for this sort of thing. I'm afraid I don't know any names, but I suggest to google on the keywords "virtual file system".