Game Development Community

How do I Zip my files from within Torque.exe

by Austin Whitlatch · in General Discussion · 05/30/2008 (9:13 am) · 8 replies

Alright... I have an odd request that I need to find a work around for (I am not asking for correctness or readability, just old-fashioned ghetto fab code and pray luck of the Irish) making Torque ZIP files into a package from a text file. For example, from a .BAT file (similar to the way TGE runs the examples) I would like to do
TorqueGame.exe -compress filesToCompress.txt
Any ideas on how to go about implementing this?

My Research:
1.) I have found main.cs (the main.cs in the same folder as the torqueGame.exe) has a list of '-' parameters (-game, -console, -help, etc.). I know I will need to make a '-compress' command.
2.) I need to make a ConsoleFunction(stuff here). ConsoleFunction() has been overloaded 202 times and it is how the torqueScript interfaces with the engine code.
3.) Torque HAS the ability to do it with Zlib, but I haven't figured that out.

Can you guys help me out?

#1
05/30/2008 (10:06 am)
Torque features the Zlib compression engine as you say.

I would suggest the 7zip command line version instead: why recreate the wheel? This is what I use. It can include a zip compatible/Torque+zip resource compatible password if desired.

If you really want to do it on a users machine for some reason, look harder at figuring out ZLib, or see if you can ship 7zip, etc.
#2
05/30/2008 (2:19 pm)
www.zlib.net/

May be of some use for you.
#3
05/30/2008 (3:28 pm)
Libzip, easy to port to windows, only a few lines need to be changed.
simply wrap it in a project configuration change a couple lines that dont conform to windows
and boom, simple easy to use zip capability.

directory.fsf.org/project/libzip/

edit: made it a hotlink.
edit2:

using zlib is alot of work, libzip does that for you, just to clarify why I left this post.
#4
06/02/2008 (7:40 am)
Torque has Zlib built in, but here is what I am trying to do:

* Zip a file from the command line: torqueDemo.exe -compress
* Use Torque's innate ability to use a zipped resource as a folder
* Torque when zipped externally (for example, zipping the data folder) will create copies of DSO files outside of the zip.

So, I NEED to implement using zlib. I'm not trying to reinvent the wheel and use other zip compression technologies. This one is built in, just need to make it work the way I want :)
#5
06/02/2008 (9:42 am)
Do you really need to use torque executable itself to zip your mods? They only reason I can think of that this ability would be useful is for doing the zipping on a clients machine, which seems odd.

Almost any compression program that implements the ZIP format (all of them?) can be used externally to torque to prepare a zipped mod from the command line as part of an automated build procedure.

For an automated build system, I use the Ruby scripting language to run torque in "compile all" mode, copy files from dev to build locations, delete all the .cs files, zip up the mods using 7zip standalone command line version, then NSIS to create the build and any patches. This takes about 2 minutes for everything where it used to take me several hours (especially if the separate guy that made the builds using Installshield was out to lunch ;) ) and a 30 step checklist to do a "quick" rebuild for a 5 minute multiplayer test.
#6
06/02/2008 (11:38 am)
Well, To be completely honest, our teacher is the one bringing this project on. He believes that making this would be an 'asset' for the artists so they could zip their artwork and models up before they give it to us... I recommended winzip but right-clicking is obviously too foreign for anyone with less than a bachelor's in Computer Science.... .... Anyways... the reason is to eliminate the need for a DATA folder and just have 1 DATA.PKG (or DATA.ZIP, it works with both). This way we can put it behind at least a rudimentary level of protection so end users cannot modify the game and it helps eliminate cheating (its a multiplayer game). That's the reason for it. He wants it to be able to be ran from a batch file torqueDemo.exe -compress txtFile.txt with a list of all the assets to compress. We are all drawing blanks and even he isn't finding any drag-and-drop way of getting it implemented. We've looked at zlib and it has a function compress() and compress2(). These are the key to getting it to work and on paper the idea sounds simple. In reality... its a major pain. So any help would be appreciative.
#7
06/02/2008 (12:44 pm)
Strange assignment indeed.

Think the easy way would be to distribute a zipper program with the Torque exe (there's a free zip.exe that will do fine--don't remember if it was GNU stuff) and simply use the shellExecute function from within Torque to invoke the zipper as a sub-program. Should take all of like three lines of TorqueScript including the "-compress" commandline option.
#8
06/02/2008 (1:49 pm)
I guess I did not provide enough clarity in my post.

zlib does not contain .zip file logic, it is a compression library.
libzip uses zlib to zip files, it is an open source library supported under Linux.

I have ported it to windows by changing very few lines of code, like 5.
wrap it in a project configuration, call the c api calls and you too can have .zip files.

take the time, download libzip, compile it write a simple class object with methods such as:
Zip(..)
Extract(..)

in your Zip(..) function for your new object, make use of the c api functions from libzip
Extract, do the opposite you did for Zip.

trivial, this should be doable inside of 1hr.

Sounds like a solid assignment, something to really test your mettle.
and the advantages to having an api inside the game for processing zips is unending.

external calls to another application is Weak.

Best of Luck.