[ABI Break] Correctly detect the executable path in appimage. (#277)

[ABI Break] Correctly detect the executable path in appimage.
This commit is contained in:
Matthieu Gautier 2019-09-17 11:41:15 +02:00 committed by GitHub
commit 57a2b98e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 16 deletions

View File

@ -38,7 +38,7 @@ bool makeDirectory(const std::string& path);
std::string makeTmpDirectory();
bool copyFile(const std::string& sourcePath, const std::string& destPath);
std::string getLastPathElement(const std::string& path);
std::string getExecutablePath();
std::string getExecutablePath(bool realPathOnly = false);
std::string getCurrentDirectory();
std::string getDataDirectory();
bool writeTextFile(const std::string& path, const std::string& content);

View File

@ -49,7 +49,7 @@ Aria2::Aria2():
m_secret = "token:"+m_secret;
std::string aria2cmd = appendToDirectory(
removeLastPathElement(getExecutablePath(), true, true),
removeLastPathElement(getExecutablePath(true), true, true),
ARIA2_CMD);
if (fileExists(aria2cmd)) {
// A local aria2c exe exists (packaged with kiwix-desktop), use it.

View File

@ -36,7 +36,7 @@ void KiwixServe::run()
std::vector<const char*> callCmd;
std::string kiwixServeCmd = appendToDirectory(
removeLastPathElement(getExecutablePath(), true, true),
removeLastPathElement(getExecutablePath(true), true, true),
KIWIXSERVE_CMD);
if (fileExists(kiwixServeCmd)) {
// A local kiwix-serve exe exists (packaged with kiwix-desktop), use it.

View File

@ -279,24 +279,20 @@ bool copyFile(const std::string& sourcePath, const std::string& destPath)
return true;
}
std::string getExecutablePath()
std::string getExecutablePath(bool realPathOnly)
{
char binRootPath[PATH_MAX];
char* cAppImage = ::getenv("APPIMAGE");
if (cAppImage) {
char* cArgv0 = ::getenv("ARGV0");
char* cOwd = ::getenv("OWD");
if (!cArgv0 && !cOwd) {
// Nothing to clean, goto in the same function...
// This is silly but .. ok..
// And we should pass here, if APPIMAGE is set ARGV0 and OWD should also
// (except if there is a bug in appimage)
goto normal;
if (!realPathOnly) {
char* cAppImage = ::getenv("APPIMAGE");
if (cAppImage) {
char* cArgv0 = ::getenv("ARGV0");
char* cOwd = ::getenv("OWD");
if (cArgv0 && cOwd) {
return appendToDirectory(cOwd, cArgv0);
}
}
return appendToDirectory(cOwd, cArgv0);
}
normal:
#ifdef _WIN32
GetModuleFileName(NULL, binRootPath, PATH_MAX);