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

Improvements to the upgrade routines #5660

Merged
merged 13 commits into from
Sep 17, 2020
9 changes: 8 additions & 1 deletion include/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

class LmmsCore;


const QString PROJECTS_PATH = "projects/";
const QString TEMPLATE_PATH = "templates/";
const QString PRESETS_PATH = "presets/";
Expand Down Expand Up @@ -219,6 +218,10 @@ class LMMS_EXPORT ConfigManager : public QObject
return m_version;
}

// Used when the configversion attribute is not present in a configuration file.
// Returns the appropriate config file version based on the LMMS version.
const unsigned int legacyConfigVersion();
IanCaio marked this conversation as resolved.
Show resolved Hide resolved

QString defaultVersion() const;


Expand Down Expand Up @@ -270,6 +273,9 @@ class LMMS_EXPORT ConfigManager : public QObject
void upgrade_1_1_91();
void upgrade();

// List of all upgrade methods
static const std::vector<void(ConfigManager::*)()> m_upgradeMethods;

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

typedef QVector<QPair<QString, QString> > stringPairVector;
Expand Down
12 changes: 6 additions & 6 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class LMMS_EXPORT DataFile : public QDomDocument
return m_type;
}

const unsigned int legacyFileVersion();

private:
static Type type( const QString& typeName );
static QString typeName( Type type );
Expand All @@ -107,9 +109,11 @@ class LMMS_EXPORT DataFile : public QDomDocument
void upgrade_1_1_0();
void upgrade_1_1_91();
void upgrade_1_2_0_rc3();
void upgrade_1_2_0_rc2_42();
void upgrade_1_3_0();

// List of all upgrade methods
static const std::vector<void(DataFile::*)()> m_upgradeMethods;

void upgrade();

void loadData( const QByteArray & _data, const QString & _sourceFile );
Expand All @@ -125,14 +129,10 @@ class LMMS_EXPORT DataFile : public QDomDocument
QDomElement m_content;
QDomElement m_head;
Type m_type;
unsigned int m_fileVersion;

} ;


const int LDF_MAJOR_VERSION = 1;
const int LDF_MINOR_VERSION = 0;
const QString LDF_VERSION_STRING = QString::number( LDF_MAJOR_VERSION ) + "." + QString::number( LDF_MINOR_VERSION );


#endif

72 changes: 59 additions & 13 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
#include "lmmsversion.h"


// Vector with all the upgrade methods
const std::vector<void(ConfigManager::*)()> ConfigManager::m_upgradeMethods = {
&ConfigManager::upgrade_1_1_90 , &ConfigManager::upgrade_1_1_91
};

static inline QString ensureTrailingSlash(const QString & s )
{
if(! s.isEmpty() && !s.endsWith('/') && !s.endsWith('\\'))
Expand All @@ -51,7 +56,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( m_upgradeMethods.size() )
{
if (QFileInfo::exists(qApp->applicationDirPath() + PORTABLE_MODE_FILE))
{
Expand Down Expand Up @@ -91,6 +98,7 @@ ConfigManager::~ConfigManager()

void ConfigManager::upgrade_1_1_90()
{
qWarning("CONFIGMANAGER: upgrade_1_1_90");
// Remove trailing " (bad latency!)" string which was once saved with PulseAudio
if(value("mixer", "audiodev").startsWith("PulseAudio ("))
{
Expand All @@ -114,7 +122,8 @@ void ConfigManager::upgrade_1_1_90()


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

ProjectVersion createdWith = m_version;

if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.90")
{
upgrade_1_1_90();
}
using upgradeMethod = void(ConfigManager::*)();
IanCaio marked this conversation as resolved.
Show resolved Hide resolved

// Runs all necessary upgrade methods
std::for_each( m_upgradeMethods.begin() + m_configVersion, m_upgradeMethods.end(),
[this](upgradeMethod um)
{
(this->*um)();
}
);

if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.91")
{
upgrade_1_1_91();
}
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 +160,8 @@ void ConfigManager::upgrade()

// Bump the version, now that we are upgraded
m_version = LMMS_VERSION;
m_configVersion = m_upgradeMethods.size();
qWarning("CONFIGMANAGER: current configVersion = %u", m_configVersion);
}

QString ConfigManager::defaultVersion() const
Expand Down Expand Up @@ -400,11 +411,23 @@ 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 = legacyConfigVersion(); // No configversion attribute found
}
else
{
bool success;
m_configVersion = root.attribute("configversion").toUInt(&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 +588,7 @@ void ConfigManager::saveConfigFile()

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

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

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

createdWith.setCompareType(ProjectVersion::Build);

if( createdWith < "1.1.90" )
{
return 0;
}
else if( createdWith < "1.1.91" )
{
return 1;
}
else
{
return 2;
}
}
DomClark marked this conversation as resolved.
Show resolved Hide resolved
Loading