|
|
@@ -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();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|