How to create a custom file container

Ok so i want to create a custom file container. For example, .jar and .zip are custom file containers, but .jar is the best example. You can put your files in them. I want to create my own but how would i do it? Is there a program that can do it for me? I'm not too interested in programming one myself as i probably would have to deal with ugly win api code. Unless it's simple of course. The only thing that will be in it is text files. Might seem like a waste, but my game can have hundreds of files so it will be needed.
Last edited on
Is there a program that can do it for me?
7-Zip. If you want to manipulate them through your program, use some library like zlib.

In case you did not know, jar is simply a zip file with changed extension.
oh, can i create a .zip with a changed extension? I dont want to write any code though. i'll look into zlib.
oh, can i create a .zip with a changed extension?

Yes.

You can change the extension of any file type to whatever you want (though it's best to avoid existing common extensions.)

Window uses the extension to work out what app to use when you double-click on it in Explorer, etc. If it's just for your games you could even just leave as .zip (or do you need to launch your app when you double-click on the file?)

I'm not too interested in programming one myself as i probably would have to deal with ugly win api code. Unless it's simple of course.

If it's just small text files, then I can think of simple solution that avoids the WinAPI. Create a binary file which is a table of offsets followed by the text files concatenated. You don't even need to use WinAPI calls to pack the file if you feed it the list of files (dir /b *.txt > list.txt)

Andy
Last edited on
"Yes.

You can change the extension of any file type to whatever you want (though it's best to avoid existing common extensions.)"

But the real question is, will it still be usable? Like if i give it the file extension .tfile will it still be a folder container?

"If it's just small text files, then I can think of simple solution that avoids the WinAPI. Create a binary file which is a table of offsets followed by the text files concatenated. You don't even need to use WinAPI calls to pack the file if you feed it the list of files (dir /b *.txt > list.txt)"

Yeah I really dont think they will be anywhere near 1 MB but idk, most will contain maps, and some will contain game data, but it's all just text, no graphics so I dont think that should be a problem.

Idk about writing one though, it seems complicated for me, but I can give it a try, is there any tutorials or anything?
But the real question is, will it still be usable? Like if i give it the file extension .tfile will it still be a folder container?
Extension is the part of the name. As nothing changes if you rename MyPhotos.zip to YOurPhotos.zip, nothing changes if you change MyPhotos.zip to MyPhotos.secret: it still can be opened with archiver; if you change extension in txt file, it still will be openable in notepad, etc.

Only reason extensions exist is to provide easy way to assign program to open file, so you won't have to open program first, then select open file, etc.
ok cool, so how would I create a zip file with a changed extension in C++? I created one on my desktop and changed the extension and was able to view it with 7-zip. But i cant figure out how to do it in C++.
As I said, use zlib. Or boost::iostreams if you use Boost, or write your own basic zip encoder.
I dont use boost, I really dont want to have to build the files. I think i'll just use a .zip file for now.
zlib only does compression (sort of. There is an archive format implemented in zlib, but it's different from ZIP; no one really uses it other than to compress tarballs. See http://www.zlib.net/zlib_faq.html#faq11 ). Use libarchive. Also, some game engine libraries, such as Irrlicht, support ZIP files.
Topic archived. No new replies allowed.