Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a portable mode to lmms #5561

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/build
/target
/.idea
/cmake-build-debug
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
.*.sw?
.DS_Store
*~
Expand Down
10 changes: 8 additions & 2 deletions include/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
128 changes: 74 additions & 54 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,68 +51,31 @@ 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=<dir>
// and lmms_BINARY_DIR:static=<dir>
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")));
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
initDevelopmentWorkingDir();

#ifdef LMMS_BUILD_WIN32
QDir::addSearchPath("data", qApp->applicationDirPath() + "/data/");
#else
QDir::addSearchPath("data", qApp->applicationDirPath().section('/', 0, -2) + "/share/lmms/");
#endif


}


Expand Down Expand Up @@ -193,7 +156,7 @@ QString ConfigManager::defaultVersion() const
return LMMS_VERSION;
}

QStringList ConfigManager::availabeVstEmbedMethods()
QStringList ConfigManager::availableVstEmbedMethods()
{
QStringList methods;
methods.append("none");
Expand All @@ -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;
Expand Down Expand Up @@ -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=<dir>
// and lmms_BINARY_DIR:static=<dir>
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();
}
}
2 changes: 1 addition & 1 deletion src/gui/SetupDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down