17 #include "compress_string.h"
19 #include "panda_getopt.h"
20 #include "preprocess_argv.h"
26 <<
" pzip file [file2 file3 ...]\n"
27 <<
" pzip -c <file >dest_file\n"
28 <<
" pzip -o dest_file file\n\n"
30 <<
"This program compresses the named file(s) using the Panda native\n"
31 <<
"compression algorithm (gzip in practice, but with a different file\n"
32 <<
"header). The compressed versions are written to a file with the\n"
33 <<
"same name as the original, but the extension .pz added to the\n"
34 <<
"filename, and the original file is removed (unless the version with\n"
35 <<
"-o is used, in which case you can compress only one file, you specify\n"
36 <<
"the destination file name, and the original file is not removed).\n\n"
38 <<
"In many cases, Panda can read the resulting .pz file directly,\n"
39 <<
"exactly as if it were still in its uncompressed original form.\n"
40 <<
"In fact, unless vfs-implicit-pz is set to false in your Config.prc\n"
41 <<
"file, you can also load the file by referencing it with its original\n"
42 <<
"filename (without the .pz extension), even though it no longer exists\n"
43 <<
"under that filename, and Panda will find the .pz file and transparently\n"
44 <<
"decompress it on the fly, as if the original, uncompressed file still\n"
47 <<
"Note that if you are adding files to a Panda multifile (.mf file) with\n"
48 <<
"the multify command, it is not necessary to compress them separately;\n"
49 <<
"multify has an inline compression option.\n\n"
53 <<
" -1 compress faster\n"
54 <<
" -6 compress default\n"
55 <<
" -9 compress better (intermediate compression levels supported also)\n\n";
60 main(
int argc,
char **argv) {
66 const char *optstr =
"o:c123456789h";
69 bool got_dest_filename =
false;
70 bool use_stdout =
false;
71 int compression_level = 6;
73 preprocess_argv(argc, argv);
74 int flag = getopt(argc, argv, optstr);
80 got_dest_filename =
true;
88 compression_level = 1;
92 compression_level = 2;
96 compression_level = 3;
100 compression_level = 4;
104 compression_level = 5;
108 compression_level = 6;
112 compression_level = 7;
116 compression_level = 8;
120 compression_level = 9;
129 flag = getopt(argc, argv, optstr);
137 cerr <<
"No filenames allowed in conjunction with -c.\n";
141 bool success = compress_stream(cin, cout, compression_level);
143 cerr <<
"Failure compressing standard input\n";
154 if (got_dest_filename && argc > 2) {
155 cerr <<
"Only one input file allowed in conjunction with -o.\n";
160 for (
int i = 1; i < argc; i++) {
163 cerr << source_file <<
" already ends .pz; skipping.\n";
166 if (!got_dest_filename) {
171 pifstream read_stream;
173 if (!source_file.
open_read(read_stream)) {
174 cerr <<
"Couldn't read: " << source_file << endl;
179 pofstream write_stream;
181 if (!dest_file.
open_write(write_stream,
true)) {
182 cerr <<
"Failed to open: " << dest_file << endl;
186 cerr << dest_file <<
"\n";
187 bool success = compress_stream(read_stream, write_stream, compression_level);
190 write_stream.close();
193 cerr <<
"Failure writing " << dest_file <<
"\n";
198 if (!got_dest_filename) {
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
void set_binary()
Indicates that the filename represents a binary file.
bool open_read(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
The name of a file, such as a texture file or an Egg file.
bool open_write(ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
string get_extension() const
Returns the file extension.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).