From a32363e6a277df71bec38e0c4efed591d7fac583 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 9 Sep 2019 18:27:36 +0200 Subject: [PATCH] Correctly detect the executable path if we use a AppImage. AppImage works by decompressing the "program" in a temporary directory. So the executable path is not the path of the AppImage file. By using the environment variables set by appimage we can find the correct "path" of the executable. Fix kiwix/kiwix-desktop#46 --- src/tools/pathTools.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tools/pathTools.cpp b/src/tools/pathTools.cpp index 65873123c..b72657e99 100644 --- a/src/tools/pathTools.cpp +++ b/src/tools/pathTools.cpp @@ -283,6 +283,21 @@ std::string getExecutablePath() { 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; + } + return appendToDirectory(cOwd, cArgv0); + } +normal: + #ifdef _WIN32 GetModuleFileName(NULL, binRootPath, PATH_MAX); return std::string(binRootPath);