From 7f5b787cb98a4ded5586b4ab189f7ec43c5d0192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 15 Aug 2022 09:54:13 +0200 Subject: [PATCH] Add launcher util for AppImage --- utils/Makefile | 13 ++----------- utils/acsmdownloader.cpp | 2 +- utils/adept_activate.cpp | 2 +- utils/adept_loan_mgt.cpp | 2 +- utils/adept_remove.cpp | 2 +- utils/launcher.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 utils/launcher.cpp diff --git a/utils/Makefile b/utils/Makefile index 4d7b9e4..4827a94 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,5 +1,5 @@ -TARGETS=acsmdownloader adept_activate adept_remove adept_loan_mgt +TARGETS=acsmdownloader adept_activate adept_remove adept_loan_mgt launcher CXXFLAGS=-Wall -fPIC -I$(ROOT)/include -I$(ROOT)/lib/pugixml/src/ @@ -29,16 +29,7 @@ ${COMMON_LIB}: ${COMMON_DEPS} ${STATIC_DEP} $(CXX) $(CXXFLAGS) ${COMMON_DEPS} $(LDFLAGS) -c $(AR) crs $@ ${COMMON_OBJECTS} $(STATIC_DEP) -acsmdownloader: acsmdownloader.cpp ${COMMON_LIB} - $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ - -adept_activate: adept_activate.cpp ${COMMON_LIB} - $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ - -adept_remove: adept_remove.cpp ${COMMON_LIB} - $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ - -adept_loan_mgt: adept_loan_mgt.cpp ${COMMON_LIB} +%: %.cpp ${COMMON_LIB} $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ clean: diff --git a/utils/acsmdownloader.cpp b/utils/acsmdownloader.cpp index dbe551f..48ab0f2 100644 --- a/utils/acsmdownloader.cpp +++ b/utils/acsmdownloader.cpp @@ -184,7 +184,7 @@ static void usage(const char* cmd) { std::cout << "Download EPUB file from ACSM request file" << std::endl; - std::cout << "Usage: " << 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|--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|--device-file" << "\t" << "device.xml file from eReader" << std::endl; std::cout << " " << "-a|--activation-file" << "\t" << "activation.xml file from eReader" << std::endl; diff --git a/utils/adept_activate.cpp b/utils/adept_activate.cpp index 3937939..bee58d3 100644 --- a/utils/adept_activate.cpp +++ b/utils/adept_activate.cpp @@ -126,7 +126,7 @@ static void usage(const char* cmd) { std::cout << "Create new device files used by ADEPT DRM" << std::endl; - std::cout << "Usage: " << cmd << " (-a|--anonymous) | ( (-u|--username) username [(-p|--password) password] ) [(-O|--output-dir) dir] [(-r|--random-serial)] [(-v|--verbose)] [(-h|--help)]" << std::endl << std::endl; + std::cout << "Usage: " << basename((char*)cmd) << " (-a|--anonymous) | ( (-u|--username) username [(-p|--password) password] ) [(-O|--output-dir) dir] [(-r|--random-serial)] [(-v|--verbose)] [(-h|--help)]" << std::endl << std::endl; std::cout << " " << "-a|--anonymous" << "\t" << "Anonymous account, no need for username/password (Use it only with a DRM removal software)" << std::endl; std::cout << " " << "-u|--username" << "\t\t" << "AdobeID username (ie adobe.com email account)" << std::endl; diff --git a/utils/adept_loan_mgt.cpp b/utils/adept_loan_mgt.cpp index a8ac487..791ab9e 100644 --- a/utils/adept_loan_mgt.cpp +++ b/utils/adept_loan_mgt.cpp @@ -336,7 +336,7 @@ static void usage(const char* cmd) { std::cout << "Manage loaned books" << std::endl; - std::cout << "Usage: " << 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|--activation-dir) dir] (-l|--list)|(-D|--delete loanID)|(-R|--delete 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 << " " << "-l|--list" << "\t\t" << "List all loaned books" << std::endl; diff --git a/utils/adept_remove.cpp b/utils/adept_remove.cpp index a56f6b0..1a16c6d 100644 --- a/utils/adept_remove.cpp +++ b/utils/adept_remove.cpp @@ -143,7 +143,7 @@ static void usage(const char* cmd) { std::cout << "Remove ADEPT DRM (from Adobe) of EPUB/PDF file" << std::endl; - std::cout << "Usage: " << 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|--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|--device-file" << "\t" << "device.xml file from eReader" << std::endl; std::cout << " " << "-a|--activation-file" << "\t" << "activation.xml file from eReader" << std::endl; diff --git a/utils/launcher.cpp b/utils/launcher.cpp new file mode 100644 index 0000000..99f8495 --- /dev/null +++ b/utils/launcher.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#include "utils_common.h" + +#ifndef DEFAULT_UTIL +#define DEFAULT_UTIL "acsmdownloader" +#endif + +/* Inspired from https://discourse.appimage.org/t/call-alternative-binary-from-appimage/93/10*/ + +int main(int argc, char** argv) +{ + char* util, *argv0; + char* mountPoint = getenv("APPDIR"); + std::string fullPath; + + /* Original command is in ARGV0 env variable*/ + argv0 = strdup(getenv("ARGV0")); + util = basename(argv0); + + fullPath = std::string(mountPoint) + util; + + if (std::string(util) == "launcher" || !fileExists(fullPath.c_str())) + fullPath = std::string(mountPoint) + DEFAULT_UTIL; + + free(argv0); + + argv[0] = strdup(fullPath.c_str()); + + if (execvp(argv[0], argv)) + std::cout << "Unable to launch '" << argv[0] << "'" << std::endl; + + /* Should not happens */ + free(argv[0]); + + return 0; +}