OpenToonz - An open-source full-featured 2D animation creation software
C
Allow All Windows Builds to be Portable (#1381)
Jeremy Bullock46512f5f12f0
diff --git a/toonz/sources/common/tapptools/tenv.cpp b/toonz/sources/common/tapptools/tenv.cppindex d7b326876..90a981c6b 100644--- a/toonz/sources/common/tapptools/tenv.cpp+++ b/toonz/sources/common/tapptools/tenv.cpp@@ -5,9 +5,7 @@#include "tconvert.h"#include "tfilepath_io.h"-#ifdef LINUX#include <QDir>-#endif#include <QSettings>#ifdef LEVO_MACOSX@@ -44,12 +42,16 @@ class EnvGlobals { // singletonstd::string m_moduleName;std::string m_rootVarName;std::string m_systemVarPrefix;+ std::string m_workingDirectory;TFilePath m_registryRoot;TFilePath m_envFile;TFilePath *m_stuffDir;TFilePath *m_dllRelativeDir;+ bool m_isPortable = false;- EnvGlobals() : m_stuffDir(0) {}+ EnvGlobals() : m_stuffDir(0) {+ setWorkingDirectory();+ }public:~EnvGlobals() { delete m_stuffDir; }@@ -125,6 +127,9 @@ public:TFilePath getStuffDir() {if (m_stuffDir) return *m_stuffDir;+ if (m_isPortable)+ return TFilePath((getWorkingDirectory() + "\\portablestuff\\"));+return TFilePath(getSystemVarValue(m_rootVarName));}void setStuffDir(const TFilePath &stuffDir) {@@ -184,7 +189,26 @@ public:std::string getRootVarName() { return m_rootVarName; }void setSystemVarPrefix(std::string prefix) { m_systemVarPrefix = prefix; }- std::string getSystemVarPrefix() { return m_systemVarPrefix; }+ std::string getSystemVarPrefix() {+ if (getIsPortable()) return "";+ return m_systemVarPrefix;+ }++ void setWorkingDirectory() {+ QString workingDirectoryTmp = QDir::currentPath();+ QByteArray ba = workingDirectoryTmp.toLatin1();+ const char *workingDirectory = ba.data();+ m_workingDirectory = workingDirectory;++ // check if portable+ TFilePath portableCheck =+ TFilePath(m_workingDirectory + "\\portablestuff\\");+ TFileStatus portableStatus(portableCheck);+ m_isPortable = portableStatus.doesExist();+ }+ std::string getWorkingDirectory() { return m_workingDirectory; }++ bool getIsPortable() { return m_isPortable; }void setDllRelativeDir(const TFilePath &dllRelativeDir) {delete m_dllRelativeDir;@@ -507,6 +531,8 @@ TFilePath TEnv::getStuffDir() {//#endif}+bool TEnv::getIsPortable() { return EnvGlobals::instance()->getIsPortable(); }+TFilePath TEnv::getConfigDir() {TFilePath configDir = getSystemVarPathValue(getSystemVarPrefix() + "CONFIG");if (configDir == TFilePath()) configDir = getStuffDir() + "config";diff --git a/toonz/sources/include/tenv.h b/toonz/sources/include/tenv.hindex b0ab78e42..5c97cf3f4 100644--- a/toonz/sources/include/tenv.h+++ b/toonz/sources/include/tenv.h@@ -95,6 +95,8 @@ DVAPI void setApplication(std::string applicationName, std::string version,DVAPI std::string getApplicationName();DVAPI std::string getApplicationVersion();+DVAPI bool getIsPortable();+// es.: TEnv::setModuleFullName("Toonz 5.0.1 Harlequin");// (default: "<applicationName> <applicationVersion>")DVAPI void setApplicationFullName(std::string applicationFullName);diff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cppindex 43e1010ae..d124aaea9 100644--- a/toonz/sources/toonz/main.cpp+++ b/toonz/sources/toonz/main.cpp@@ -528,7 +528,7 @@ int main(int argc, char *argv[]) {loadShaderInterfaces(ToonzFolder::getLibraryFolder() + TFilePath("shaders"));- splash.showMessage(offsetStr + "Initializing Toonz application ...",+ splash.showMessage(offsetStr + "Initializing OpenToonz ...",Qt::AlignCenter, Qt::white);a.processEvents();@@ -591,9 +591,13 @@ int main(int argc, char *argv[]) {TApp::instance()->setMainWindow(&w);w.setWindowTitle(applicationFullName);-- splash.showMessage(offsetStr + "Starting main window ...", Qt::AlignCenter,- Qt::white);+ if (TEnv::getIsPortable()) {+ splash.showMessage(offsetStr + "Starting OpenToonz Portable ...",+ Qt::AlignCenter, Qt::white);+ } else {+ splash.showMessage(offsetStr + "Starting main window ...", Qt::AlignCenter,+ Qt::white);+ }a.processEvents();TFilePath fp = ToonzFolder::getModuleFile("mainwindow.ini");