VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2024-09-24 03:55:33 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2024-09-24 03:55:33 +0200
commit92ad97ef33c88ef15d4e267472bae447a2a0f09c (patch)
tree32663fc513ab850944f6cde5c91ce8314bc6c387 /src
parentba8dd5137af70d9c4ab653e1c567f6c2973f124c (diff)
downloadVeraCrypt-92ad97ef33c88ef15d4e267472bae447a2a0f09c.tar.gz
VeraCrypt-92ad97ef33c88ef15d4e267472bae447a2a0f09c.zip
Linux: Improve directory opening logic by prioritizing xdg-open and adding fallback mechanisms (#1420)
- Use xdg-open as the primary method for opening directories, ensuring compatibility with most Linux environments. - Implemented fallback logic to try other known file managers (e.g., nautilus, dolphin, caja, thunar) if xdg-open is unavailable or fails. Based on proposal by @bugtracker2019
Diffstat (limited to 'src')
-rw-r--r--src/Main/UserInterface.cpp98
1 files changed, 52 insertions, 46 deletions
diff --git a/src/Main/UserInterface.cpp b/src/Main/UserInterface.cpp
index ad2f22b8..b216101a 100644
--- a/src/Main/UserInterface.cpp
+++ b/src/Main/UserInterface.cpp
@@ -846,138 +846,144 @@ namespace VeraCrypt
catch (UserAbort&)
{
}
catch (exception &e)
{
ShowError (e);
}
catch (...)
{
ShowError (LangString["LINUX_UNKNOWN_EXC_OCCURRED"]);
}
Yield();
Application::SetExitCode (1);
}
void UserInterface::OnVolumeMounted (EventArgs &args)
{
shared_ptr <VolumeInfo> mountedVolume = (dynamic_cast <VolumeEventArgs &> (args)).mVolume;
if (Preferences.OpenExplorerWindowAfterMount && !mountedVolume->MountPoint.IsEmpty())
OpenExplorerWindow (mountedVolume->MountPoint);
}
void UserInterface::OnWarning (EventArgs &args)
{
ExceptionEventArgs &e = dynamic_cast <ExceptionEventArgs &> (args);
ShowWarning (e.mException);
}
+#if !defined(TC_WINDOWS) && !defined(TC_MACOSX)
+// Function to check if a given executable exists and is executable
+static bool IsExecutable(const string& exe) {
+ return wxFileName::IsFileExecutable("/usr/bin/" + exe) ||
+ wxFileName::IsFileExecutable("/usr/local/bin/" + exe);
+}
+#endif
+
void UserInterface::OpenExplorerWindow (const DirectoryPath &path)
{
if (path.IsEmpty())
return;
list <string> args;
#ifdef TC_WINDOWS
wstring p (Directory::AppendSeparator (path));
SHFILEINFO fInfo;
SHGetFileInfo (p.c_str(), 0, &fInfo, sizeof (fInfo), 0); // Force explorer to discover the drive
ShellExecute (GetTopWindow() ? static_cast <HWND> (GetTopWindow()->GetHandle()) : nullptr, L"open", p.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
#elif defined (TC_MACOSX)
args.push_back (string (path));
try
{
Process::Execute ("open", args);
}
catch (exception &e) { ShowError (e); }
#else
- // MIME handler for directory seems to be unavailable through wxWidgets
- wxString desktop = GetTraits()->GetDesktopEnvironment();
- bool xdgOpenPresent = wxFileName::IsFileExecutable (wxT("/usr/bin/xdg-open")) || wxFileName::IsFileExecutable (wxT("/usr/local/bin/xdg-open"));
- bool nautilusPresent = wxFileName::IsFileExecutable (wxT("/usr/bin/nautilus")) || wxFileName::IsFileExecutable (wxT("/usr/local/bin/nautilus"));
-
- if (desktop == L"GNOME" || (desktop.empty() && !xdgOpenPresent && nautilusPresent))
- {
- // args.push_back ("--no-default-window"); // This option causes nautilus not to launch under FreeBSD 11
- args.push_back ("--no-desktop");
- args.push_back (string (path));
- try
- {
- Process::Execute ("nautilus", args, 2000);
+ string directoryPath = string(path);
+ // Primary attempt: Use xdg-open
+ if (IsExecutable("xdg-open")) {
+ try {
+ args.push_back(directoryPath);
+ Process::Execute("xdg-open", args, 2000);
+ return;
}
catch (TimeOut&) { }
- catch (exception &e) { ShowError (e); }
+ catch (exception&) {}
}
- else if (desktop == L"KDE")
- {
- try
- {
- args.push_back (string (path));
- Process::Execute ("dolphin", args, 2000);
- }
- catch (TimeOut&) { }
- catch (exception&)
- {
+
+ // Fallback attempts: Try known file managers
+ const char* fallbackFileManagers[] = { "gio", "kioclient5", "kfmclient", "exo-open", "nautilus", "dolphin", "caja", "thunar", "pcmanfm" };
+ const size_t numFileManagers = sizeof(fallbackFileManagers) / sizeof(fallbackFileManagers[0]);
+
+ for (size_t i = 0; i < numFileManagers; ++i) {
+ const char* fm = fallbackFileManagers[i];
+ if (IsExecutable(fm)) {
args.clear();
- args.push_back ("openURL");
- args.push_back (string (path));
- try
- {
- Process::Execute ("kfmclient", args, 2000);
+ if (strcmp(fm, "gio") == 0) {
+ args.push_back("open");
+ args.push_back(directoryPath);
+ }
+ else if (strcmp(fm, "kioclient5") == 0) {
+ args.push_back("exec");
+ args.push_back(directoryPath);
+ }
+ else if (strcmp(fm, "kfmclient") == 0) {
+ args.push_back("openURL");
+ args.push_back(directoryPath);
+ }
+ else if (strcmp(fm, "exo-open") == 0) {
+ args.push_back("--launch");
+ args.push_back("FileManager");
+ args.push_back(directoryPath);
+ }
+ else {
+ args.push_back(directoryPath);
+ }
+
+ try {
+ Process::Execute(fm, args, 2000);
+ return; // Success
}
catch (TimeOut&) { }
- catch (exception &e) { ShowError (e); }
- }
- }
- else if (xdgOpenPresent)
- {
- // Fallback on the standard xdg-open command
- // which is not always available by default
- args.push_back (string (path));
- try
- {
- Process::Execute ("xdg-open", args, 2000);
+ catch (exception &) {}
}
- catch (TimeOut&) { }
- catch (exception &e) { ShowError (e); }
- }
- else
- {
- ShowWarning (wxT("Unable to find a file manager to open the mounted volume"));
}
+
+ ShowWarning(wxT("Unable to find a file manager to open the mounted volume.\n"
+ "Please install xdg-utils or set a default file manager."));
#endif
}
bool UserInterface::ProcessCommandLine ()
{
CommandLineInterface &cmdLine = *CmdLine;
if (cmdLine.ArgCommand == CommandId::None)
return false;
if (Preferences.UseStandardInput)
{
wstring pwdInput;
getline(wcin, pwdInput);
size_t maxUtf8Len = cmdLine.ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize;
cmdLine.ArgPassword = ToUTF8Password ( pwdInput.c_str (), pwdInput.size (), maxUtf8Len);
}
switch (cmdLine.ArgCommand)
{
case CommandId::AutoMountDevices:
case CommandId::AutoMountFavorites:
case CommandId::AutoMountDevicesFavorites:
case CommandId::MountVolume:
{
cmdLine.ArgMountOptions.Path = cmdLine.ArgVolumePath;
cmdLine.ArgMountOptions.MountPoint = cmdLine.ArgMountPoint;
cmdLine.ArgMountOptions.Password = cmdLine.ArgPassword;
cmdLine.ArgMountOptions.Pim = cmdLine.ArgPim;