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:
@@ -432,28 +432,14 @@ namespace VeraCrypt
|
||||
|
||||
#if defined(TC_LINUX)
|
||||
// AppImage specific handling:
|
||||
// If running from an AppImage, and appPath is inside the AppImage's mount point (APPDIR),
|
||||
// and APPDIR has the expected prefix, then use the AppImage file path (APPIMAGE) for sudo.
|
||||
// If running from an AppImage, use the path to the AppImage file itself for sudo.
|
||||
const char* appImageEnv = getenv("APPIMAGE");
|
||||
const char* appDirEnv = getenv("APPDIR");
|
||||
|
||||
if (appImageEnv && appDirEnv)
|
||||
{
|
||||
string appDirString = appDirEnv;
|
||||
string appImageFileString = appImageEnv;
|
||||
const string appImageMountPrefix = "/tmp/.mount_Veracr"; // Based on observed "/tmp/.mount_VeracrXXXXXX"
|
||||
|
||||
// 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;
|
||||
}
|
||||
if (Process::IsRunningUnderAppImage(appPath) && appImageEnv != NULL)
|
||||
{
|
||||
// The path to the AppImage file is stored in the APPIMAGE environment variable.
|
||||
// We need to use this path for sudo to work correctly.
|
||||
appPath = appImageEnv;
|
||||
}
|
||||
#endif
|
||||
throw_sys_if (dup2 (inPipe->GetReadFD(), STDIN_FILENO) == -1);
|
||||
|
||||
@@ -1354,6 +1354,21 @@ namespace VeraCrypt
|
||||
htmlPath += L"/../Resources/doc/HTML/";
|
||||
#elif defined (TC_UNIX)
|
||||
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
|
||||
localFile = false;
|
||||
#endif
|
||||
|
||||
@@ -263,4 +263,36 @@ namespace VeraCrypt
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace VeraCrypt
|
||||
static bool IsExecutable(const std::string& path);
|
||||
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);
|
||||
#if defined(TC_LINUX)
|
||||
static bool IsRunningUnderAppImage (const string &executablePath);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user