From e4bd73c03db20e8c6dacb53b51eae2e5244a82f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Wed, 21 Dec 2022 21:23:42 +0100 Subject: [PATCH] Add global option -D to utils, allowing to specify .adept directory instead of every single files. WARNING : -D has been changed by -d in adept_loan_mgt ! --- include/libgourou.h | 2 +- utils/acsmdownloader.cpp | 15 ++++++++++++-- utils/adept_loan_mgt.cpp | 42 ++++++++++++++++++++-------------------- utils/adept_remove.cpp | 15 ++++++++++++-- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/include/libgourou.h b/include/libgourou.h index e2ee44c..1f82dd8 100644 --- a/include/libgourou.h +++ b/include/libgourou.h @@ -40,7 +40,7 @@ #define ACS_SERVER "http://adeactivate.adobe.com/adept" #endif -#define LIBGOUROU_VERSION "0.8" +#define LIBGOUROU_VERSION "0.8.1" namespace gourou { diff --git a/utils/acsmdownloader.cpp b/utils/acsmdownloader.cpp index 48ab0f2..1c66086 100644 --- a/utils/acsmdownloader.cpp +++ b/utils/acsmdownloader.cpp @@ -184,8 +184,9 @@ static void usage(const char* cmd) { std::cout << "Download EPUB file from ACSM request file" << std::endl; - std::cout << "Usage: " << basename((char*)cmd) << " [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-k|--device-key-file) devicesalt] [(-O|--output-dir) dir] [(-o|--output-file) output(.epub|.pdf|.der)] [(-r|--resume)] [(-v|--verbose)] [(-h|--help)] (-f|--acsm-file) file.acsm|(-e|--export-private-key)" << std::endl << std::endl; + std::cout << "Usage: " << basename((char*)cmd) << " [(-D|--adept-directory) dir] [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-k|--device-key-file) devicesalt] [(-O|--output-dir) dir] [(-o|--output-file) output(.epub|.pdf|.der)] [(-r|--resume)] [(-v|--verbose)] [(-h|--help)] (-f|--acsm-file) file.acsm|(-e|--export-private-key)" << std::endl << std::endl; + std::cout << " " << "-D|--adept-directory" << "\t" << ".adept directory that must contains device.xml, activation.xml and devicesalt" << std::endl; std::cout << " " << "-d|--device-file" << "\t" << "device.xml file from eReader" << std::endl; std::cout << " " << "-a|--activation-file" << "\t" << "activation.xml file from eReader" << std::endl; std::cout << " " << "-k|--device-key-file" << "\t" << "private device key file (eg devicesalt/devkey.bin) from eReader" << std::endl; @@ -209,6 +210,7 @@ static void usage(const char* cmd) int main(int argc, char** argv) { int c, ret = -1; + std::string _deviceFile, _activationFile, _devicekeyFile; const char** files[] = {&devicekeyFile, &deviceFile, &activationFile}; int verbose = gourou::DRMProcessor::getLogLevel(); @@ -216,6 +218,7 @@ int main(int argc, char** argv) while (1) { int option_index = 0; static struct option long_options[] = { + {"adept-directory", required_argument, 0, 'D' }, {"device-file", required_argument, 0, 'd' }, {"activation-file", required_argument, 0, 'a' }, {"device-key-file", required_argument, 0, 'k' }, @@ -230,12 +233,20 @@ int main(int argc, char** argv) {0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "d:a:k:O:o:f:ervVh", + c = getopt_long(argc, argv, "D:d:a:k:O:o:f:ervVh", long_options, &option_index); if (c == -1) break; switch (c) { + case 'D': + _deviceFile = std::string(optarg) + "/device.xml"; + _activationFile = std::string(optarg) + "/activation.xml"; + _devicekeyFile = std::string(optarg) + "/devicesalt"; + deviceFile = _deviceFile.c_str(); + activationFile = _activationFile.c_str(); + devicekeyFile = _devicekeyFile.c_str(); + break; case 'd': deviceFile = optarg; break; diff --git a/utils/adept_loan_mgt.cpp b/utils/adept_loan_mgt.cpp index 791ab9e..2bb7693 100644 --- a/utils/adept_loan_mgt.cpp +++ b/utils/adept_loan_mgt.cpp @@ -45,7 +45,7 @@ #define MAX_SIZE_BOOK_NAME 30 -static char* activationDir = 0; +static char* adeptDir = 0; static const char* deviceFile = "device.xml"; static const char* activationFile = "activation.xml"; static const char* devicekeyFile = "devicesalt"; @@ -106,7 +106,7 @@ private: struct Loan* loan; char * res; - std::string loanDir = std::string(activationDir) + std::string("/") + LOANS_DIR; + std::string loanDir = std::string(adeptDir) + std::string("/") + LOANS_DIR; if (!fileExists(loanDir.c_str())) return; @@ -336,18 +336,18 @@ static void usage(const char* cmd) { std::cout << "Manage loaned books" << std::endl; - std::cout << "Usage: " << basename((char*)cmd) << " [(-d|--activation-dir) dir] (-l|--list)|(-D|--delete loanID)|(-R|--delete loanID) [(-v|--verbose)] [(-h|--help)]" << std::endl << std::endl; + std::cout << "Usage: " << basename((char*)cmd) << " [(-D|--adept-directory) dir] (-l|--list)|(-d|--delete loanID)|(-R|--return loanID) [(-v|--verbose)] [(-h|--help)]" << std::endl << std::endl; - std::cout << " " << "-d|--activation-dir" << "\t" << "Directory of device.xml/activation.xml and device key" << std::endl; + std::cout << " " << "-D|--adept-directory" << "\t" << ".adept directory that must contains device.xml, activation.xml and devicesalt" << std::endl; std::cout << " " << "-l|--list" << "\t\t" << "List all loaned books" << std::endl; std::cout << " " << "-r|--return" << "\t\t" << "Return a loaned book" << std::endl; - std::cout << " " << "-D|--delete" << "\t\t" << "Delete a loan entry without returning it" << std::endl; + std::cout << " " << "-d|--delete" << "\t\t" << "Delete a loan entry without returning it" << std::endl; std::cout << " " << "-v|--verbose" << "\t\t" << "Increase verbosity, can be set multiple times" << std::endl; std::cout << " " << "-V|--version" << "\t\t" << "Display libgourou version" << std::endl; std::cout << " " << "-h|--help" << "\t\t" << "This help" << std::endl; std::cout << std::endl; - std::cout << "Activation directory is optional. If not set, it's looked into :" << std::endl; + std::cout << "ADEPT directory is optional. If not set, it's looked into :" << std::endl; std::cout << " * Current directory" << std::endl; std::cout << " * .adept" << std::endl; std::cout << " * adobe-digital-editions directory" << std::endl; @@ -365,10 +365,10 @@ int main(int argc, char** argv) while (1) { int option_index = 0; static struct option long_options[] = { - {"activation-dir", required_argument, 0, 'd' }, + {"adept-directory", required_argument, 0, 'D' }, {"list", no_argument, 0, 'l' }, {"return", no_argument, 0, 'r' }, - {"delete", no_argument, 0, 'D' }, + {"delete", no_argument, 0, 'd' }, {"verbose", no_argument, 0, 'v' }, {"version", no_argument, 0, 'V' }, {"help", no_argument, 0, 'h' }, @@ -381,8 +381,8 @@ int main(int argc, char** argv) break; switch (c) { - case 'd': - activationDir = optarg; + case 'D': + adeptDir = optarg; break; case 'l': list = true; @@ -392,7 +392,7 @@ int main(int argc, char** argv) returnID = optarg; actions++; break; - case 'D': + case 'd': deleteID = optarg; actions++; break; @@ -432,9 +432,9 @@ int main(int argc, char** argv) { orig = *files[i]; - if (activationDir) + if (adeptDir) { - std::string path = std::string(activationDir) + std::string("/") + orig; + std::string path = std::string(adeptDir) + std::string("/") + orig; filename = strdup(path.c_str()); } else @@ -450,17 +450,17 @@ int main(int argc, char** argv) if (hasErrors) { - // In case of activation dir was provided by user - activationDir = 0; + // In case of adept dir was provided by user + adeptDir = 0; goto end; } - if (activationDir) - activationDir = strdup(activationDir); // For below free + if (adeptDir) + adeptDir = strdup(adeptDir); // For below free else { - activationDir = strdup(deviceFile); - activationDir = dirname(activationDir); + adeptDir = strdup(deviceFile); + adeptDir = dirname(adeptDir); } ret = loanMGT.run(); @@ -472,8 +472,8 @@ end: free((void*)*files[i]); } - if (activationDir) - free(activationDir); + if (adeptDir) + free(adeptDir); return ret; } diff --git a/utils/adept_remove.cpp b/utils/adept_remove.cpp index 1a16c6d..6baeb53 100644 --- a/utils/adept_remove.cpp +++ b/utils/adept_remove.cpp @@ -143,8 +143,9 @@ static void usage(const char* cmd) { std::cout << "Remove ADEPT DRM (from Adobe) of EPUB/PDF file" << std::endl; - std::cout << "Usage: " << basename((char*)cmd) << " [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-k|--device-key-file) devicesalt] [(-O|--output-dir) dir] [(-o|--output-file) output(.epub|.pdf|.der)] [(-v|--verbose)] [(-h|--help)] (-f|--input-file) file(.epub|pdf)" << std::endl << std::endl; + std::cout << "Usage: " << basename((char*)cmd) << " [(-D|--adept-directory) dir] [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-k|--device-key-file) devicesalt] [(-O|--output-dir) dir] [(-o|--output-file) output(.epub|.pdf|.der)] [(-v|--verbose)] [(-h|--help)] (-f|--input-file) file(.epub|pdf)" << std::endl << std::endl; + std::cout << " " << "-D|--adept-directory" << "\t" << ".adept directory that must contains device.xml, activation.xml and devicesalt" << std::endl; std::cout << " " << "-d|--device-file" << "\t" << "device.xml file from eReader" << std::endl; std::cout << " " << "-a|--activation-file" << "\t" << "activation.xml file from eReader" << std::endl; std::cout << " " << "-k|--device-key-file" << "\t" << "private device key file (eg devicesalt/devkey.bin) from eReader" << std::endl; @@ -169,10 +170,12 @@ int main(int argc, char** argv) const char** files[] = {&devicekeyFile, &deviceFile, &activationFile}; int verbose = gourou::DRMProcessor::getLogLevel(); + std::string _deviceFile, _activationFile, _devicekeyFile; while (1) { int option_index = 0; static struct option long_options[] = { + {"adept-directory", required_argument, 0, 'D' }, {"device-file", required_argument, 0, 'd' }, {"activation-file", required_argument, 0, 'a' }, {"device-key-file", required_argument, 0, 'k' }, @@ -186,12 +189,20 @@ int main(int argc, char** argv) {0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "d:a:k:O:o:f:K:vVh", + c = getopt_long(argc, argv, "D:d:a:k:O:o:f:K:vVh", long_options, &option_index); if (c == -1) break; switch (c) { + case 'D': + _deviceFile = std::string(optarg) + "/device.xml"; + _activationFile = std::string(optarg) + "/activation.xml"; + _devicekeyFile = std::string(optarg) + "/devicesalt"; + deviceFile = _deviceFile.c_str(); + activationFile = _activationFile.c_str(); + devicekeyFile = _devicekeyFile.c_str(); + break; case 'd': deviceFile = optarg; break;