From 4b9692bbd5f0cac4327fc77207bb7676d684e80c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 12 Nov 2018 14:34:44 +0100 Subject: [PATCH] Correctly run aria2c when packaged with kiwix-desktop in appimage. By default, we are searching in the PATH env var. However, with an appImage, the executable directory is not in the PATH, so we have to use an absolute path if we can. If we cannot find the aria2c executable in the executable directory let's try to use the system one. --- src/aria2.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/aria2.cpp b/src/aria2.cpp index 0195cccd..854a73b9 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -9,6 +9,13 @@ #include #include // For AriaError +#ifdef _WIN32 +# define ARIA2_CMD "aria2c.exe" +#else +# define ARIA2_CMD "aria2c" +#endif + + namespace kiwix { Aria2::Aria2(): @@ -36,11 +43,16 @@ Aria2::Aria2(): std::string rpc_secret = "--rpc-secret=" + m_secret; m_secret = "token:"+m_secret; -#ifdef _WIN32 - callCmd.push_back("aria2c.exe"); -#else - callCmd.push_back("aria2c"); -#endif + std::string aria2cmd = appendToDirectory( + removeLastPathElement(getExecutablePath()), + ARIA2_CMD); + if (fileExists(aria2cmd)) { + // A local aria2c exe exists (packaged with kiwix-desktop), use it. + callCmd.push_back(aria2cmd.c_str()); + } else { + // Try to use a potential installed aria2c. + callCmd.push_back(ARIA2_CMD); + } callCmd.push_back("--enable-rpc"); callCmd.push_back(rpc_secret.c_str()); callCmd.push_back(rpc_port.c_str());