Skip to content
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
9 changes: 7 additions & 2 deletions include/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class LMMS_EXPORT ConfigManager : public QObject
return m_version;
}

// Returns m_configVersion if present in the configuration file. If it's not present
// gets the right configVersion from a LMMS version for backwards compatibility.
const int configVersion();

QString defaultVersion() const;


Expand Down Expand Up @@ -266,8 +270,8 @@ class LMMS_EXPORT ConfigManager : public QObject
ConfigManager(const ConfigManager & _c);
~ConfigManager();

void upgrade_1_1_90();
void upgrade_1_1_91();
void upgrade_0();
void upgrade_1();
void upgrade();

QString m_workingDir;
Expand All @@ -286,6 +290,7 @@ class LMMS_EXPORT ConfigManager : public QObject
QString m_backgroundPicFile;
QString m_lmmsRcFile;
QString m_version;
int m_configVersion;
QStringList m_recentlyOpenedProjects;

typedef QVector<QPair<QString, QString> > stringPairVector;
Expand Down
59 changes: 49 additions & 10 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ static inline QString ensureTrailingSlash(const QString & s )
ConfigManager * ConfigManager::s_instanceOfMe = NULL;


ConfigManager::ConfigManager() : m_version(defaultVersion())
ConfigManager::ConfigManager() :
m_version(defaultVersion()),
m_configVersion( -1 )
{
if (QFileInfo::exists(qApp->applicationDirPath() + PORTABLE_MODE_FILE))
{
Expand Down Expand Up @@ -89,7 +91,7 @@ ConfigManager::~ConfigManager()
}


void ConfigManager::upgrade_1_1_90()
void ConfigManager::upgrade_0()
{
// Remove trailing " (bad latency!)" string which was once saved with PulseAudio
if(value("mixer", "audiodev").startsWith("PulseAudio ("))
Expand All @@ -113,7 +115,7 @@ void ConfigManager::upgrade_1_1_90()
}


void ConfigManager::upgrade_1_1_91()
void ConfigManager::upgrade_1()
{
// rename displaydbv to displaydbfs
if (!value("app", "displaydbv").isNull()) {
Expand All @@ -131,17 +133,17 @@ void ConfigManager::upgrade()
return;
}

ProjectVersion createdWith = m_version;

if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.90")
if( configVersion() < 1 )
{
upgrade_1_1_90();
upgrade_0();
}

if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.91")
if( configVersion() < 2 )
{
upgrade_1_1_91();
upgrade_1();
}

ProjectVersion createdWith = m_version;

// Don't use old themes as they break the UI (i.e. 0.4 != 1.0, etc)
if (createdWith.setCompareType(ProjectVersion::Minor) != LMMS_VERSION)
Expand All @@ -151,6 +153,7 @@ void ConfigManager::upgrade()

// Bump the version, now that we are upgraded
m_version = LMMS_VERSION;
// No need to bump the m_configVersion, because it gets bumped in the configVersion() method
}

QString ConfigManager::defaultVersion() const
Expand Down Expand Up @@ -400,11 +403,21 @@ void ConfigManager::loadConfigFile(const QString & configFile)

QDomNode node = root.firstChild();

// Cache the config version for upgrade()
// Cache LMMS version
if (!root.attribute("version").isNull()) {
m_version = root.attribute("version");
}

// Get the version of the configuration file (for upgrade purposes)
if( root.attribute("configversion").isNull() )
{
m_configVersion = -1; // No configversion attribute found
} else {
bool success;
m_configVersion = root.attribute("configversion").toInt(&success);
if( !success ) qWarning("Config Version conversion failure.");
}

// create the settings-map out of the DOM
while(!node.isNull())
{
Expand Down Expand Up @@ -565,6 +578,7 @@ void ConfigManager::saveConfigFile()

QDomElement lmms_config = doc.createElement("lmms");
lmms_config.setAttribute("version", m_version);
lmms_config.setAttribute("configversion", configVersion());
doc.appendChild(lmms_config);

for(settingsMap::iterator it = m_settings.begin();
Expand Down Expand Up @@ -673,3 +687,28 @@ void ConfigManager::initDevelopmentWorkingDir()
cmakeCache.close();
}
}

const int ConfigManager::configVersion()
{
if( m_configVersion < 0 )
{
// If configversion is not present, we will convert the LMMS version to the appropriate
// configuration file version for backwards compatibility.
ProjectVersion createdWith = m_version;

if( createdWith.setCompareType(ProjectVersion::Build) < "1.1.90" )
{
m_configVersion = 0;
}
else if( createdWith.setCompareType(ProjectVersion::Build) < "1.1.91" )
{
m_configVersion = 1;
}
else
{
m_configVersion = 2;
}
}

return m_configVersion;
}