Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

fix(tenv): try every portable candidate and require a directory (Linux)

Chan299a75b930dc
diff --git a/toonz/sources/common/tapptools/tenv.cpp b/toonz/sources/common/tapptools/tenv.cpp
index 4f8c0e9e3..4c09ba03c 100644
--- a/toonz/sources/common/tapptools/tenv.cpp
+++ b/toonz/sources/common/tapptools/tenv.cpp
@@ -10,6 +10,7 @@
#include <QFileInfo>
#include <QSettings>
#include <QStandardPaths>
+#include <QStringList>
#include <iostream>
@@ -244,11 +245,13 @@ public:
const char *workingDirectory = ba.data();
m_workingDirectory = workingDirectory;
- // check if portable
+ // check if portable. Startup requires the selected stuff path to be a
+ // directory and aborts otherwise, so a regular file named portablestuff
+ // must not qualify. Every candidate below applies the same rule.
TFilePath portableCheck =
TFilePath(m_workingDirectory + "\\portablestuff\\");
TFileStatus portableStatus(portableCheck);
- m_isPortable = portableStatus.doesExist();
+ m_isPortable = portableStatus.isDirectory();
#ifdef MACOSX
// macOS 10.12 (Sierra) translocates applications before running them
@@ -261,7 +264,7 @@ public:
TFilePath(m_workingDirectory + "\\" + getApplicationFileName() +
".app\\portablestuff\\");
portableStatus = TFileStatus(portableCheck);
- m_isPortable = portableStatus.doesExist();
+ m_isPortable = portableStatus.isDirectory();
if (m_isPortable)
m_workingDirectory =
portableCheck.getParentDir().getQString().toStdString();
@@ -276,18 +279,45 @@ public:
// directory is not where the user keeps portablestuff. APPIMAGE, set by
// the AppImage runtime, is the path of the bundle itself.
QString appImage = QString::fromLocal8Bit(qgetenv("APPIMAGE"));
- QString appDir = appImage.isEmpty()
- ? (QCoreApplication::instance()
- ? QCoreApplication::applicationDirPath()
- : QString())
- : QFileInfo(appImage).absolutePath();
- if (!appDir.isEmpty()) {
- portableCheck = TFilePath(appDir.toStdString() + "\\portablestuff\\");
+ QString exeDir = QCoreApplication::instance()
+ ? QCoreApplication::applicationDirPath()
+ : QString();
+
+ // A native build can inherit APPIMAGE from an unrelated AppImage parent,
+ // or pick up a stale export. APPDIR is that bundle's mount point, so
+ // containment tells us whether APPIMAGE describes this process.
+ // Companion executables such as tcomposer share the mount and still
+ // qualify.
+ QString appDirEnv = QString::fromLocal8Bit(qgetenv("APPDIR"));
+ bool inBundle = false;
+ if (!appDirEnv.isEmpty() && !exeDir.isEmpty()) {
+ QString mount = QFileInfo(appDirEnv).canonicalFilePath();
+ QString exe = QFileInfo(exeDir).canonicalFilePath();
+ inBundle = !mount.isEmpty() && !exe.isEmpty() &&
+ (exe == mount || exe.startsWith(mount + "/"));
+ }
+
+ // Try every candidate rather than committing to one, so a bundle without
+ // portablestuff cannot hide a valid tree beside the executable. An
+ // unverified APPIMAGE goes last: worth a look, but not ahead of our own
+ // directory.
+ QStringList candidates;
+ if (!appImage.isEmpty() && inBundle)
+ candidates << QFileInfo(appImage).absolutePath();
+ if (!exeDir.isEmpty()) candidates << exeDir;
+ if (!appImage.isEmpty() && !inBundle)
+ candidates << QFileInfo(appImage).absolutePath();
+
+ for (const QString &candidate : candidates) {
+ portableCheck =
+ TFilePath(candidate.toStdString() + "\\portablestuff\\");
portableStatus = TFileStatus(portableCheck);
- m_isPortable = portableStatus.doesExist();
- if (m_isPortable)
+ m_isPortable = portableStatus.isDirectory();
+ if (m_isPortable) {
m_workingDirectory =
portableCheck.getParentDir().getQString().toStdString();
+ break;
+ }
}
}
}