mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
add -o options
This commit is contained in:
parent
e19232aa88
commit
bcef4b24de
@ -53,8 +53,10 @@ do_decrypt(istream &read_stream, ostream &write_stream) {
|
||||
void
|
||||
usage() {
|
||||
cerr
|
||||
<< "\nUsage:\n"
|
||||
<< " pdecrypt file.pe [file2.pe file3.pe ...]\n"
|
||||
<< " pdecrypt -o dest_file file.pe\n\n"
|
||||
<< "\n"
|
||||
<< "Usage: pdecrypt [opts] file [file2 file3 ...]\n\n"
|
||||
|
||||
<< "This program reverses the operation of a previous pencrypt command. It\n"
|
||||
<< "decrypts the contents of the named source file(s) and removes the .pe\n"
|
||||
@ -75,12 +77,20 @@ int
|
||||
main(int argc, char *argv[]) {
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
const char *optstr = "p:h";
|
||||
const char *optstr = "o:p:h";
|
||||
|
||||
Filename dest_filename;
|
||||
bool got_dest_filename = false;
|
||||
|
||||
int flag = getopt(argc, argv, optstr);
|
||||
|
||||
while (flag != EOF) {
|
||||
switch (flag) {
|
||||
case 'o':
|
||||
dest_filename = Filename::from_os_specific(optarg);
|
||||
got_dest_filename = true;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
password = optarg;
|
||||
got_password = true;
|
||||
@ -103,16 +113,24 @@ main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (got_dest_filename && argc > 2) {
|
||||
cerr << "Only one input file allowed in conjunction with -o.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool all_ok = true;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
Filename source_file = Filename::from_os_specific(argv[i]);
|
||||
if (source_file.get_extension() != "pe") {
|
||||
if (!got_dest_filename && source_file.get_extension() != "pe") {
|
||||
cerr << source_file
|
||||
<< " doesn't end in .pe; can't derive filename of output file.\n";
|
||||
all_ok = false;
|
||||
|
||||
} else {
|
||||
Filename dest_file = source_file.get_fullpath_wo_extension();
|
||||
Filename dest_file = dest_filename;
|
||||
if (!got_dest_filename) {
|
||||
dest_file = source_file.get_fullpath_wo_extension();
|
||||
}
|
||||
|
||||
// Open source file
|
||||
ifstream read_stream;
|
||||
@ -149,7 +167,9 @@ main(int argc, char *argv[]) {
|
||||
dest_file.unlink();
|
||||
|
||||
} else {
|
||||
source_file.unlink();
|
||||
if (!got_dest_filename) {
|
||||
source_file.unlink();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,13 +70,19 @@ do_encrypt(istream &read_stream, ostream &write_stream) {
|
||||
void
|
||||
usage() {
|
||||
cerr
|
||||
<< "\n"
|
||||
<< "Usage: pencrypt [opts] file [file2 file3 ...]\n\n"
|
||||
<< "\nUsage:\n"
|
||||
<< " pencrypt [opts] file [file2 file3 ...]\n"
|
||||
<< " pencrypt -o dest_file file\n\n"
|
||||
|
||||
<< "This program will apply an encryption algorithm to a file (or multiple files),\n"
|
||||
<< "creating an encrypted version of each file which can only be recovered using\n"
|
||||
<< "pdecrypt and the same password that was supplied to pencrypt. For each input\n"
|
||||
<< "file, an output name is generated by appending .pe to the input file name.\n\n"
|
||||
<< "pdecrypt and the same password that was supplied to pencrypt. The compressed\n"
|
||||
<< "versions are written to a file with the same name as the original, but the\n"
|
||||
<< "extension .pe added to the filename, and the original file is removed\n"
|
||||
<< "(unless the version with -o is used, in which case you can encrypt only one\n"
|
||||
<< "file, you specify the destination file name, and the original file is not\n"
|
||||
<< "removed).\n\n"
|
||||
|
||||
|
||||
<< "Note that if you are adding files to a Panda multifile (.mf file) with\n"
|
||||
<< "the multify command, it is not necessary to encrypt them separately;\n"
|
||||
@ -116,12 +122,20 @@ int
|
||||
main(int argc, char *argv[]) {
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
const char *optstr = "p:a:k:i:h";
|
||||
const char *optstr = "o:p:a:k:i:h";
|
||||
|
||||
Filename dest_filename;
|
||||
bool got_dest_filename = false;
|
||||
|
||||
int flag = getopt(argc, argv, optstr);
|
||||
|
||||
while (flag != EOF) {
|
||||
switch (flag) {
|
||||
case 'o':
|
||||
dest_filename = Filename::from_os_specific(optarg);
|
||||
got_dest_filename = true;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
password = optarg;
|
||||
got_password = true;
|
||||
@ -159,13 +173,21 @@ main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (got_dest_filename && argc > 2) {
|
||||
cerr << "Only one input file allowed in conjunction with -o.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool all_ok = true;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
Filename source_file = Filename::from_os_specific(argv[i]);
|
||||
if (source_file.get_extension() == "pe") {
|
||||
cerr << source_file << " already ends .pe; skipping.\n";
|
||||
} else {
|
||||
Filename dest_file = source_file.get_fullpath() + ".pe";
|
||||
Filename dest_file = dest_filename;
|
||||
if (!got_dest_filename) {
|
||||
dest_file = source_file.get_fullpath() + ".pe";
|
||||
}
|
||||
|
||||
// Open source file
|
||||
ifstream read_stream;
|
||||
@ -202,7 +224,9 @@ main(int argc, char *argv[]) {
|
||||
dest_file.unlink();
|
||||
|
||||
} else {
|
||||
bool ok = source_file.unlink();
|
||||
if (!got_dest_filename) {
|
||||
source_file.unlink();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,9 @@ do_decompress(istream &read_stream, ostream &write_stream) {
|
||||
void
|
||||
usage() {
|
||||
cerr
|
||||
<< "\nUsage: punzip file.pz [file2.pz file3.pz ...]\n\n"
|
||||
<< "\nUsage:\n"
|
||||
<< " punzip file.pz [file2.pz file3.pz ...]\n"
|
||||
<< " punzip -o dest_file file.pz\n\n"
|
||||
|
||||
<< "This program reverses the operation of a previous pzip command. It\n"
|
||||
<< "uncompresses the contents of the named source file(s) and removes the .pz\n"
|
||||
@ -61,12 +63,20 @@ int
|
||||
main(int argc, char *argv[]) {
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
const char *optstr = "h";
|
||||
const char *optstr = "o:h";
|
||||
|
||||
Filename dest_filename;
|
||||
bool got_dest_filename = false;
|
||||
|
||||
int flag = getopt(argc, argv, optstr);
|
||||
|
||||
while (flag != EOF) {
|
||||
switch (flag) {
|
||||
case 'o':
|
||||
dest_filename = Filename::from_os_specific(optarg);
|
||||
got_dest_filename = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
@ -84,16 +94,24 @@ main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (got_dest_filename && argc > 2) {
|
||||
cerr << "Only one input file allowed in conjunction with -o.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool all_ok = true;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
Filename source_file = Filename::from_os_specific(argv[i]);
|
||||
if (source_file.get_extension() != "pz") {
|
||||
if (!got_dest_filename && source_file.get_extension() != "pz") {
|
||||
cerr << source_file
|
||||
<< " doesn't end in .pz; can't derive filename of output file.\n";
|
||||
all_ok = false;
|
||||
|
||||
} else {
|
||||
Filename dest_file = source_file.get_fullpath_wo_extension();
|
||||
Filename dest_file = dest_filename;
|
||||
if (!got_dest_filename) {
|
||||
dest_file = source_file.get_fullpath_wo_extension();
|
||||
}
|
||||
|
||||
// Open source file
|
||||
ifstream read_stream;
|
||||
@ -123,7 +141,9 @@ main(int argc, char *argv[]) {
|
||||
dest_file.unlink();
|
||||
|
||||
} else {
|
||||
source_file.unlink();
|
||||
if (!got_dest_filename) {
|
||||
source_file.unlink();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,13 +51,17 @@ do_compress(istream &read_stream, ostream &write_stream) {
|
||||
void
|
||||
usage() {
|
||||
cerr
|
||||
<< "\nUsage: pzip file [file2 file3 ...]\n\n"
|
||||
<< "\nUsage:\n"
|
||||
<< " pzip file [file2 file3 ...]\n"
|
||||
<< " pzip -o dest_file file\n\n"
|
||||
|
||||
<< "This program compresses the named file(s) using the Panda native\n"
|
||||
<< "compression algorithm (gzip in practice, but with a different file\n"
|
||||
<< "header). The compressed versions are written to a file with the\n"
|
||||
<< "same name as the original, but the extension .pz added to the\n"
|
||||
<< "filename, and the original file is removed.\n\n"
|
||||
<< "filename, and the original file is removed (unless the version with\n"
|
||||
<< "-o is used, in which case you can compress only one file, you specify\n"
|
||||
<< "the destination file name, and the original file is not removed).\n\n"
|
||||
|
||||
<< "In many cases, Panda can read the resulting .pz file directly,\n"
|
||||
<< "exactly as if it were still in its uncompressed original form.\n"
|
||||
@ -77,12 +81,20 @@ int
|
||||
main(int argc, char *argv[]) {
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
const char *optstr = "h";
|
||||
const char *optstr = "o:h";
|
||||
|
||||
Filename dest_filename;
|
||||
bool got_dest_filename = false;
|
||||
|
||||
int flag = getopt(argc, argv, optstr);
|
||||
|
||||
while (flag != EOF) {
|
||||
switch (flag) {
|
||||
case 'o':
|
||||
dest_filename = Filename::from_os_specific(optarg);
|
||||
got_dest_filename = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case '?':
|
||||
default:
|
||||
@ -100,13 +112,21 @@ main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (got_dest_filename && argc > 2) {
|
||||
cerr << "Only one input file allowed in conjunction with -o.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool all_ok = true;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
Filename source_file = Filename::from_os_specific(argv[i]);
|
||||
if (source_file.get_extension() == "pz") {
|
||||
cerr << source_file << " already ends .pz; skipping.\n";
|
||||
} else {
|
||||
Filename dest_file = source_file.get_fullpath() + ".pz";
|
||||
Filename dest_file = dest_filename;
|
||||
if (!got_dest_filename) {
|
||||
dest_file = source_file.get_fullpath() + ".pz";
|
||||
}
|
||||
|
||||
// Open source file
|
||||
ifstream read_stream;
|
||||
@ -136,7 +156,9 @@ main(int argc, char *argv[]) {
|
||||
dest_file.unlink();
|
||||
|
||||
} else {
|
||||
source_file.unlink();
|
||||
if (!got_dest_filename) {
|
||||
source_file.unlink();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user