From 4c5c345b66a0ef6e91843460e580f6698edca0a2 Mon Sep 17 00:00:00 2001 From: SeleDreams Date: Tue, 7 Jul 2020 16:35:42 +0200 Subject: [PATCH 1/2] Added portable mode by creating a file named portable_mode.txt next to lmms and fixed a typo in the name of the function availableVstEmbedMethods --- .gitignore | 2 + include/ConfigManager.h | 10 ++- src/core/ConfigManager.cpp | 128 +++++++++++++++++++++---------------- src/gui/SetupDialog.cpp | 2 +- 4 files changed, 85 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index 771eba60762..642b5663b7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /build /target +/.idea +/cmake-build-debug .*.sw? .DS_Store *~ diff --git a/include/ConfigManager.h b/include/ConfigManager.h index 556c455a0c7..de22d22af11 100644 --- a/include/ConfigManager.h +++ b/include/ConfigManager.h @@ -50,7 +50,7 @@ const QString LADSPA_PATH ="plugins/ladspa/"; const QString DEFAULT_THEME_PATH = "themes/default/"; const QString TRACK_ICON_PATH = "track_icons/"; const QString LOCALE_PATH = "locale/"; - +const QString PORTABLE_MODE_FILE = "/portable_mode.txt"; class LMMS_EXPORT ConfigManager : public QObject { @@ -71,6 +71,12 @@ class LMMS_EXPORT ConfigManager : public QObject return m_workingDir; } + void initPortableWorkingDir(); + + void initInstalledWorkingDir(); + + void initDevelopmentWorkingDir(); + const QString & dataDir() const { return m_dataDir; @@ -216,7 +222,7 @@ class LMMS_EXPORT ConfigManager : public QObject QString defaultVersion() const; - static QStringList availabeVstEmbedMethods(); + static QStringList availableVstEmbedMethods(); QString vstEmbedMethod() const; // Returns true if the working dir (e.g. ~/lmms) exists on disk. diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index b8e8cd4ae77..de3a88f8fbe 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -51,60 +51,24 @@ static inline QString ensureTrailingSlash(const QString & s ) ConfigManager * ConfigManager::s_instanceOfMe = NULL; -ConfigManager::ConfigManager() : - m_workingDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/lmms/"), - m_dataDir("data:/"), - m_vstDir(m_workingDir + "vst/"), - m_sf2Dir(m_workingDir + SF2_PATH), - m_gigDir(m_workingDir + GIG_PATH), - m_themeDir(defaultThemeDir()), - m_lmmsRcFile(QDir::home().absolutePath() +"/.lmmsrc.xml"), - m_version(defaultVersion()) +ConfigManager::ConfigManager() : m_version(defaultVersion()) { - // Detect < 1.2.0 working directory as a courtesy - if ( QFileInfo( QDir::home().absolutePath() + "/lmms/projects/" ).exists() ) - m_workingDir = QDir::home().absolutePath() + "/lmms/"; - - if (! qgetenv("LMMS_DATA_DIR").isEmpty()) - QDir::addSearchPath("data", QString::fromLocal8Bit(qgetenv("LMMS_DATA_DIR"))); - - // If we're in development (lmms is not installed) let's get the source and - // binary directories by reading the CMake Cache - QDir appPath = qApp->applicationDirPath(); - // If in tests, get parent directory - if (appPath.dirName() == "tests") { - appPath.cdUp(); + if (QFileInfo::exists(qApp->applicationDirPath() + PORTABLE_MODE_FILE)) + { + initPortableWorkingDir(); } - QFile cmakeCache(appPath.absoluteFilePath("CMakeCache.txt")); - if (cmakeCache.exists()) { - cmakeCache.open(QFile::ReadOnly); - QTextStream stream(&cmakeCache); - - // Find the lines containing something like lmms_SOURCE_DIR:static= - // and lmms_BINARY_DIR:static= - int done = 0; - while(! stream.atEnd()) - { - QString line = stream.readLine(); - - if (line.startsWith("lmms_SOURCE_DIR:")) { - QString srcDir = line.section('=', -1).trimmed(); - QDir::addSearchPath("data", srcDir + "/data/"); - done++; - } - if (line.startsWith("lmms_BINARY_DIR:")) { - m_lmmsRcFile = line.section('=', -1).trimmed() + QDir::separator() + - ".lmmsrc.xml"; - done++; - } - if (done == 2) - { - break; - } - } - - cmakeCache.close(); + else + { + initInstalledWorkingDir(); } + m_dataDir = "data:/"; + m_vstDir = m_workingDir + "vst/"; + m_sf2Dir = m_workingDir + SF2_PATH; + m_gigDir = m_workingDir + GIG_PATH; + m_themeDir = defaultThemeDir(); + if (! qgetenv("LMMS_DATA_DIR").isEmpty()) + QDir::addSearchPath("data", QString::fromLocal8Bit(qgetenv("LMMS_DATA_DIR"))); + initDevelopmentWorkingDir(); #ifdef LMMS_BUILD_WIN32 QDir::addSearchPath("data", qApp->applicationDirPath() + "/data/"); @@ -112,7 +76,6 @@ ConfigManager::ConfigManager() : QDir::addSearchPath("data", qApp->applicationDirPath().section('/', 0, -2) + "/share/lmms/"); #endif - } @@ -193,7 +156,7 @@ QString ConfigManager::defaultVersion() const return LMMS_VERSION; } -QStringList ConfigManager::availabeVstEmbedMethods() +QStringList ConfigManager::availableVstEmbedMethods() { QStringList methods; methods.append("none"); @@ -215,7 +178,7 @@ QStringList ConfigManager::availabeVstEmbedMethods() QString ConfigManager::vstEmbedMethod() const { - QStringList methods = availabeVstEmbedMethods(); + QStringList methods = availableVstEmbedMethods(); QString defaultMethod = *(methods.end() - 1); QString currentMethod = value( "ui", "vstembedmethod", defaultMethod ); return methods.contains(currentMethod) ? currentMethod : defaultMethod; @@ -651,3 +614,60 @@ void ConfigManager::saveConfigFile() outfile.write(xml.toUtf8()); outfile.close(); } + +void ConfigManager::initPortableWorkingDir() +{ + QString applicationPath = qApp->applicationDirPath(); + m_workingDir = applicationPath + "/lmms-workspace/"; + m_lmmsRcFile = applicationPath + "/.lmmsrc.xml"; +} + +void ConfigManager::initInstalledWorkingDir() +{ + m_workingDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/lmms/"; + m_lmmsRcFile = QDir::home().absolutePath() +"/.lmmsrc.xml"; + // Detect < 1.2.0 working directory as a courtesy + if ( QFileInfo( QDir::home().absolutePath() + "/lmms/projects/" ).exists() ) + m_workingDir = QDir::home().absolutePath() + "/lmms/"; +} + +void ConfigManager::initDevelopmentWorkingDir() +{ + // If we're in development (lmms is not installed) let's get the source and + // binary directories by reading the CMake Cache + QDir appPath = qApp->applicationDirPath(); + // If in tests, get parent directory + if (appPath.dirName() == "tests") { + appPath.cdUp(); + } + QFile cmakeCache(appPath.absoluteFilePath("CMakeCache.txt")); + if (cmakeCache.exists()) { + cmakeCache.open(QFile::ReadOnly); + QTextStream stream(&cmakeCache); + + // Find the lines containing something like lmms_SOURCE_DIR:static= + // and lmms_BINARY_DIR:static= + int done = 0; + while(! stream.atEnd()) + { + QString line = stream.readLine(); + + if (line.startsWith("lmms_SOURCE_DIR:")) { + QString srcDir = line.section('=', -1).trimmed(); + QDir::addSearchPath("data", srcDir + "/data/"); + done++; + } + if (line.startsWith("lmms_BINARY_DIR:")) { + m_lmmsRcFile = line.section('=', -1).trimmed() + QDir::separator() + + ".lmmsrc.xml"; + done++; + } + if (done == 2) + { + break; + } + } + + cmakeCache.close(); + } +} diff --git a/src/gui/SetupDialog.cpp b/src/gui/SetupDialog.cpp index 2a7aeba7294..b1d7e5aadb4 100644 --- a/src/gui/SetupDialog.cpp +++ b/src/gui/SetupDialog.cpp @@ -389,7 +389,7 @@ SetupDialog::SetupDialog(ConfigTabs tab_to_open) : m_vstEmbedComboBox = new QComboBox(plugins_tw); m_vstEmbedComboBox->move(XDelta, YDelta * ++counter); - QStringList embedMethods = ConfigManager::availabeVstEmbedMethods(); + QStringList embedMethods = ConfigManager::availableVstEmbedMethods(); m_vstEmbedComboBox->addItem(tr("No embedding"), "none"); if(embedMethods.contains("qt")) { From 3e3ed2a6b9a6dca1e5608dce8864742d4d731e8b Mon Sep 17 00:00:00 2001 From: SeleDreams Date: Fri, 10 Jul 2020 18:45:45 +0200 Subject: [PATCH 2/2] Fixed the condition using a tab instead of bracket --- .gitignore | 2 -- src/core/ConfigManager.cpp | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 642b5663b7d..771eba60762 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ /build /target -/.idea -/cmake-build-debug .*.sw? .DS_Store *~ diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index de3a88f8fbe..53262dac7df 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -66,8 +66,10 @@ ConfigManager::ConfigManager() : m_version(defaultVersion()) m_sf2Dir = m_workingDir + SF2_PATH; m_gigDir = m_workingDir + GIG_PATH; m_themeDir = defaultThemeDir(); - if (! qgetenv("LMMS_DATA_DIR").isEmpty()) + if (!qgetenv("LMMS_DATA_DIR").isEmpty()) + { QDir::addSearchPath("data", QString::fromLocal8Bit(qgetenv("LMMS_DATA_DIR"))); + } initDevelopmentWorkingDir(); #ifdef LMMS_BUILD_WIN32