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
12 changes: 11 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 All @@ -55,6 +54,9 @@ const QString PORTABLE_MODE_FILE = "/portable_mode.txt";
class LMMS_EXPORT ConfigManager : public QObject
{
Q_OBJECT

using UpgradeMethod = void(ConfigManager::*)();

public:
static inline ConfigManager * inst()
{
Expand Down Expand Up @@ -219,6 +221,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.
unsigned int legacyConfigVersion();

QString defaultVersion() const;


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

// List of all upgrade methods
static const std::vector<UpgradeMethod> UPGRADE_METHODS;

QString m_workingDir;
QString m_dataDir;
QString m_vstDir;
Expand All @@ -286,6 +295,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
18 changes: 12 additions & 6 deletions include/DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@

#include "lmms_export.h"
#include "MemoryManager.h"
#include "ProjectVersion.h"

class QTextStream;

class LMMS_EXPORT DataFile : public QDomDocument
{
MM_OPERATORS

using UpgradeMethod = void(DataFile::*)();

public:
enum Types
{
Expand Down Expand Up @@ -84,6 +88,8 @@ class LMMS_EXPORT DataFile : public QDomDocument
return m_type;
}

unsigned int legacyFileVersion();

private:
static Type type( const QString& typeName );
static QString typeName( Type type );
Expand All @@ -107,9 +113,13 @@ 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<UpgradeMethod> UPGRADE_METHODS;
// List of ProjectVersions for the legacyFileVersion method
static const std::vector<ProjectVersion> UPGRADE_VERSIONS;

void upgrade();

void loadData( const QByteArray & _data, const QString & _sourceFile );
Expand All @@ -125,14 +135,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

67 changes: 54 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<ConfigManager::UpgradeMethod> ConfigManager::UPGRADE_METHODS = {
&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( UPGRADE_METHODS.size() )
{
if (QFileInfo::exists(qApp->applicationDirPath() + PORTABLE_MODE_FILE))
{
Expand Down Expand Up @@ -114,7 +121,7 @@ void ConfigManager::upgrade_1_1_90()


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

ProjectVersion createdWith = m_version;

if (createdWith.setCompareType(ProjectVersion::Build) < "1.1.90")
{
upgrade_1_1_90();
}
// Runs all necessary upgrade methods
std::for_each( UPGRADE_METHODS.begin() + m_configVersion, UPGRADE_METHODS.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 +156,7 @@ void ConfigManager::upgrade()

// Bump the version, now that we are upgraded
m_version = LMMS_VERSION;
m_configVersion = UPGRADE_METHODS.size();
}

QString ConfigManager::defaultVersion() const
Expand Down Expand Up @@ -400,11 +406,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 +583,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 +692,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.
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;
}
}
Loading