1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 02:58:02 -06:00

Linux: Correct handling of documentation in case of AppImage. Code refactoring.

This commit is contained in:
Mounir IDRASSI
2025-05-10 19:09:31 +09:00
parent 01cfc169c6
commit 3edae48717
4 changed files with 56 additions and 20 deletions

View File

@@ -432,28 +432,14 @@ namespace VeraCrypt
#if defined(TC_LINUX) #if defined(TC_LINUX)
// AppImage specific handling: // AppImage specific handling:
// If running from an AppImage, and appPath is inside the AppImage's mount point (APPDIR), // If running from an AppImage, use the path to the AppImage file itself for sudo.
// and APPDIR has the expected prefix, then use the AppImage file path (APPIMAGE) for sudo.
const char* appImageEnv = getenv("APPIMAGE"); const char* appImageEnv = getenv("APPIMAGE");
const char* appDirEnv = getenv("APPDIR");
if (appImageEnv && appDirEnv) if (Process::IsRunningUnderAppImage(appPath) && appImageEnv != NULL)
{ {
string appDirString = appDirEnv; // The path to the AppImage file is stored in the APPIMAGE environment variable.
string appImageFileString = appImageEnv; // We need to use this path for sudo to work correctly.
const string appImageMountPrefix = "/tmp/.mount_Veracr"; // Based on observed "/tmp/.mount_VeracrXXXXXX" appPath = appImageEnv;
// Check: APPDIR is not empty,
// appPath starts with APPDIR,
// and APPDIR itself starts with the expected AppImage mount prefix
if (!appDirString.empty() &&
appPath.rfind(appDirString, 0) == 0 &&
appDirString.rfind(appImageMountPrefix, 0) == 0)
{
// All conditions met, this is the AppImage scenario.
// Use the path to the AppImage file itself for sudo.
appPath = appImageFileString;
}
} }
#endif #endif
throw_sys_if (dup2 (inPipe->GetReadFD(), STDIN_FILENO) == -1); throw_sys_if (dup2 (inPipe->GetReadFD(), STDIN_FILENO) == -1);

View File

@@ -1354,6 +1354,21 @@ namespace VeraCrypt
htmlPath += L"/../Resources/doc/HTML/"; htmlPath += L"/../Resources/doc/HTML/";
#elif defined (TC_UNIX) #elif defined (TC_UNIX)
htmlPath = L"/usr/share/doc/veracrypt/HTML/"; htmlPath = L"/usr/share/doc/veracrypt/HTML/";
#if defined(TC_LINUX)
// AppImage specific handling:
// if we are running from an AppImage, we need to use the path inside the AppImage
// instead of the path on the host system
std::string appPath= StringConverter::ToSingle (wstring(Application::GetExecutablePath()));
if (Process::IsRunningUnderAppImage(appPath))
{
const char* appDirEnv = getenv("APPDIR");
if (appDirEnv)
{
htmlPath = wxString::FromUTF8(appDirEnv);
htmlPath += "/usr/share/doc/veracrypt/HTML/";
}
}
#endif
#else #else
localFile = false; localFile = false;
#endif #endif

View File

@@ -263,4 +263,36 @@ namespace VeraCrypt
return strOutput; return strOutput;
} }
#if defined(TC_LINUX)
bool Process::IsRunningUnderAppImage (const string &executablePath)
{
if (executablePath.empty())
return false;
// AppImage detection logic:
// Check that APPIMAGE and APPDIR environment variables are set
// Check that the executable path starts with APPDIR
// Check that APPDIR itself starts with the expected AppImage mount prefix
const char* appImageEnv = getenv("APPIMAGE");
const char* appDirEnv = getenv("APPDIR");
if (appImageEnv && appDirEnv)
{
string appDirString = appDirEnv;
string appImageFileString = appImageEnv;
const string appImageMountPrefix1 = "/tmp/.mount_Veracr";
const string appImageMountPrefix2 = "/tmp/.mount_VeraCr";
if (!appDirString.empty() &&
executablePath.rfind(appDirString, 0) == 0 &&
(appDirString.rfind(appImageMountPrefix1, 0) == 0 || appDirString.rfind(appImageMountPrefix2, 0) == 0))
{
// All conditions met, this is the AppImage scenario.
return true;
}
}
return false;
}
#endif
} }

View File

@@ -34,6 +34,9 @@ namespace VeraCrypt
static bool IsExecutable(const std::string& path); static bool IsExecutable(const std::string& path);
static std::string FindSystemBinary(const char* name, std::string& errorMsg); static std::string FindSystemBinary(const char* name, std::string& errorMsg);
static string Execute (const string &processName, const list <string> &arguments, int timeOut = -1, ProcessExecFunctor *execFunctor = nullptr, const Buffer *inputData = nullptr); static string Execute (const string &processName, const list <string> &arguments, int timeOut = -1, ProcessExecFunctor *execFunctor = nullptr, const Buffer *inputData = nullptr);
#if defined(TC_LINUX)
static bool IsRunningUnderAppImage (const string &executablePath);
#endif
protected: protected: