Implement portable mode (#5561)
Adds portable mode by creating a file named portable_mode.txt next to lmms and fixed a typo in the name of the function
This commit is contained in:
@@ -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 @@ public:
|
||||
return m_workingDir;
|
||||
}
|
||||
|
||||
void initPortableWorkingDir();
|
||||
|
||||
void initInstalledWorkingDir();
|
||||
|
||||
void initDevelopmentWorkingDir();
|
||||
|
||||
const QString & dataDir() const
|
||||
{
|
||||
return m_dataDir;
|
||||
@@ -216,7 +222,7 @@ public:
|
||||
QString defaultVersion() const;
|
||||
|
||||
|
||||
static QStringList availabeVstEmbedMethods();
|
||||
static QStringList availableVstEmbedMethods();
|
||||
QString vstEmbedMethod() const;
|
||||
|
||||
// Returns true if the working dir (e.g. ~/lmms) exists on disk.
|
||||
|
||||
@@ -51,60 +51,26 @@ 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())
|
||||
if (QFileInfo::exists(qApp->applicationDirPath() + PORTABLE_MODE_FILE))
|
||||
{
|
||||
initPortableWorkingDir();
|
||||
}
|
||||
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")));
|
||||
|
||||
// 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();
|
||||
}
|
||||
initDevelopmentWorkingDir();
|
||||
|
||||
#ifdef LMMS_BUILD_WIN32
|
||||
QDir::addSearchPath("data", qApp->applicationDirPath() + "/data/");
|
||||
@@ -112,7 +78,6 @@ ConfigManager::ConfigManager() :
|
||||
QDir::addSearchPath("data", qApp->applicationDirPath().section('/', 0, -2) + "/share/lmms/");
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +158,7 @@ QString ConfigManager::defaultVersion() const
|
||||
return LMMS_VERSION;
|
||||
}
|
||||
|
||||
QStringList ConfigManager::availabeVstEmbedMethods()
|
||||
QStringList ConfigManager::availableVstEmbedMethods()
|
||||
{
|
||||
QStringList methods;
|
||||
methods.append("none");
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user