Skip to content

Commit

Permalink
Implement portable mode (LMMS#5561)
Browse files Browse the repository at this point in the history
Adds portable mode by creating a file named portable_mode.txt next to lmms
and fixed a typo in the name of the function
  • Loading branch information
SeleDreams authored Jul 20, 2020
1 parent acda31d commit 9bc9f68
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 57 deletions.
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
130 changes: 76 additions & 54 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,68 +51,33 @@ 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")));
}
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 +158,7 @@ QString ConfigManager::defaultVersion() const
return LMMS_VERSION;
}

QStringList ConfigManager::availabeVstEmbedMethods()
QStringList ConfigManager::availableVstEmbedMethods()
{
QStringList methods;
methods.append("none");
Expand All @@ -215,7 +180,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 +616,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

0 comments on commit 9bc9f68

Please sign in to comment.