24 bool got_password =
false;
30 <<
" pdecrypt file.pe [file2.pe file3.pe ...]\n" 31 <<
" pdecrypt -o dest_file file.pe\n\n" 34 <<
"This program reverses the operation of a previous pencrypt command. It\n" 35 <<
"decrypts the contents of the named source file(s) and removes the .pe\n" 36 <<
"extension. The encryption algorithm need not be specified; it can be\n" 37 <<
"determined by examining the header of each encrypted file. The password\n" 38 <<
"must match the encryption password exactly. If it does not, an error may\n" 39 <<
"or may not be reported; but the file will not be decrypted correctly even\n" 40 <<
"if no error is reported.\n\n" 44 <<
" -p \"password\"\n" 45 <<
" Specifies the password to use for decryption. If this is not specified,\n" 46 <<
" the user is prompted from standard input.\n\n";
50 main(
int argc,
char **argv) {
53 const char *optstr =
"o:p:h";
56 bool got_dest_filename =
false;
59 int flag = getopt(argc, argv, optstr);
65 got_dest_filename =
true;
79 flag = getopt(argc, argv, optstr);
90 if (got_dest_filename && argc > 2) {
91 cerr <<
"Only one input file allowed in conjunction with -o.\n";
96 for (
int i = 1; i < argc; i++) {
98 if (!got_dest_filename && source_file.
get_extension() !=
"pe") {
100 <<
" doesn't end in .pe; can't derive filename of output file.\n";
105 if (!got_dest_filename) {
110 pifstream read_stream;
112 if (!source_file.
open_read(read_stream)) {
113 cerr <<
"Couldn't read: " << source_file << endl;
118 pofstream write_stream;
120 if (!dest_file.
open_write(write_stream,
true)) {
121 cerr <<
"Failed to open: " << dest_file << endl;
127 cerr <<
"Enter password: ";
128 std::getline(std::cin, password);
132 cerr << dest_file <<
"\n";
133 bool success = decrypt_stream(read_stream, write_stream, password);
136 write_stream.close();
139 cerr <<
"Failure decrypting " << source_file <<
"\n";
144 if (!got_dest_filename) {
145 source_file.unlink();
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
void set_binary()
Indicates that the filename represents a binary file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_extension() const
Returns the file extension.
void preprocess_argv(int &argc, char **&argv)
Processes the argc, argv pair as needed before passing it to getopt().
std::string get_fullpath_wo_extension() const
Returns the full filename–directory and basename parts–except for the extension.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...