mirror of
https://github.com/LMMS/lmms.git
synced 2026-01-29 08:43:18 -05:00
* First commit This commit starts the improvements on the upgrade methods. We are going to change both the DataFile and ConfigManager to use separate version values from LMMS release versions, so we can easily bump those versions for new upgrade routines. This first commit starts implementing a new version value for the ConfigManager. * Change code as per requested on review As requested, the "configVersion" method was replaced by "legacyConfigVersion" instead, which is only used to return a configuration version if none is present in the configuration file. The configuration version of the current build is stored in a local variable called CONFIG_VERSION, making version bumping easier. Uses a switch statement instead of if-else to be able to make use of case-cascading. TODO: - Change the CONFIG_VERSION variable to a unsigned int? - Start working on the DataFile.cpp. * Changes the upgrade logic on DataFile.cpp Starts refactoring the upgrade logic on DataFile.cpp. Now the "version" attribute is used to indicate which fileVersion we are loading. If the value of version is "1.0", we have a legacy file and use the legacyFileVersion method to retrieve the integer version using the LMMS version. If the value of version is an integer, we just read it. The integer indicates the position in a list of upgrade methods where we should start from and run the upgrade methods. The file version of the build is held in the FILE_VERSION const on DataFile.h. It HAS TO match the number of upgrade methods that we have on our list. One of the versions had 2 upgrade routines (upgrade_1_2_0_rc3 and upgrade_1_2_0_rc2_42). They were merged into a single one (upgrade_1_2_0_rc3) because they were both called from a single version check, meaning that they are both part of a single fileVersion. Two fatal errors were added (which can later be improved to show an error messagebox): One if the version attribute doesn't exist, and another one if we are using a FILE_VERSION that doesn't match the number of upgrade methods (to avoid mistakes while coding new upgrades later). The configVersion variables and methods were changed to use unsigned int instead of int. TODO: - Make the list of upgrade methods static. - Add debug messages for each upgrade routine for testing purposes. * Make method vector a static const variable On DataFile.cpp, we now use the vector list of upgrade methods as a static const variable, so it only has to be constructed once. * Reorganize vector lists Reorganize vector lists so they are more easily readable. Revert changes on upgrade method names from ConfigManager.cpp. * Makes the file version bumping automatic The file version bumping on DataFile.cpp is now automatic (using the size of the m_upgradeMethods vector as a reference). FILE_VERSION constant was removed, and with it the qFatal error when it doesn't match the size of the methods vector. * Improve formatting of version and upgrades lists Improves the formatting of the vector lists of upgrade routines and LMMS versions (2 upgrade routines per line and 3 LMMS versions per line). Adds a qWarning for every upgrade routine for testing purposes, plus a qWarning that tells the current fileVersion/configVersion when upgrade is called. Removes extra space characters after the opening bracket of ConfigManager::upgrade_1_1_91. * Changes ConfigManager to use a vector of methods Changes ConfigManager to use a vector of upgrade methods, just like DataFile. The new Config Version can be calculated automatically now, so the CONFIG_VERSION constant was removed. Corrects a small comment on Datafile.h. * Addresses Dom's review requests - Changes legacyConfigVersion and legacyFileVersion from const unsigned int to just unsigned int, since the const is irrelevant in this context. - Changes the type alias for upgrade methods to start with an uppercase as per the code style guidelines. Moves the aliasing of the type to the class declaration so it can be used on both the method and on the vector list declaration. - Changes the vector list names from m_upgradeMethods to UPGRADE_METHODS, so it's more visible they are a static constant. - Move the upgradeVersions list from the legacyFileVersion method to the DataFile class, as an static const called UPGRADE_VERSIONS. - Uses std::upper_bound instead of std::find_if for the legacyFileVersion method. * Uses type alias on vector assignment Uses the UpgradeMethod type alias when defining the upgrade methods vector from both ConfigManager and DataFile. * Removes debugging warnings Removes the qWarning() calls that were placed for debugging purposes.
309 lines
6.3 KiB
C++
309 lines
6.3 KiB
C++
/*
|
|
* ConfigManager.h - class ConfigManager, a class for managing LMMS-configuration
|
|
*
|
|
* Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
|
*
|
|
* This file is part of LMMS - https://lmms.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program (see COPYING); if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
|
|
#ifndef CONFIG_MGR_H
|
|
#define CONFIG_MGR_H
|
|
|
|
#include "lmmsconfig.h"
|
|
|
|
#include <QtCore/QMap>
|
|
#include <QtCore/QPair>
|
|
#include <QtCore/QStringList>
|
|
#include <QtCore/QVector>
|
|
#include <QtCore/QObject>
|
|
|
|
#include "lmms_export.h"
|
|
|
|
|
|
class LmmsCore;
|
|
|
|
const QString PROJECTS_PATH = "projects/";
|
|
const QString TEMPLATE_PATH = "templates/";
|
|
const QString PRESETS_PATH = "presets/";
|
|
const QString SAMPLES_PATH = "samples/";
|
|
const QString GIG_PATH = "samples/gig/";
|
|
const QString SF2_PATH = "samples/soundfonts/";
|
|
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
|
|
{
|
|
Q_OBJECT
|
|
|
|
using UpgradeMethod = void(ConfigManager::*)();
|
|
|
|
public:
|
|
static inline ConfigManager * inst()
|
|
{
|
|
if(s_instanceOfMe == NULL )
|
|
{
|
|
s_instanceOfMe = new ConfigManager();
|
|
}
|
|
return s_instanceOfMe;
|
|
}
|
|
|
|
|
|
const QString & workingDir() const
|
|
{
|
|
return m_workingDir;
|
|
}
|
|
|
|
void initPortableWorkingDir();
|
|
|
|
void initInstalledWorkingDir();
|
|
|
|
void initDevelopmentWorkingDir();
|
|
|
|
const QString & dataDir() const
|
|
{
|
|
return m_dataDir;
|
|
}
|
|
|
|
QString factoryProjectsDir() const
|
|
{
|
|
return dataDir() + PROJECTS_PATH;
|
|
}
|
|
|
|
QString factoryTemplatesDir() const
|
|
{
|
|
return factoryProjectsDir() + TEMPLATE_PATH;
|
|
}
|
|
|
|
QString factoryPresetsDir() const
|
|
{
|
|
return dataDir() + PRESETS_PATH;
|
|
}
|
|
|
|
QString factorySamplesDir() const
|
|
{
|
|
return dataDir() + SAMPLES_PATH;
|
|
}
|
|
|
|
|
|
QString userProjectsDir() const
|
|
{
|
|
return workingDir() + PROJECTS_PATH;
|
|
}
|
|
|
|
QString userTemplateDir() const
|
|
{
|
|
return workingDir() + TEMPLATE_PATH;
|
|
}
|
|
|
|
QString userPresetsDir() const
|
|
{
|
|
return workingDir() + PRESETS_PATH;
|
|
}
|
|
|
|
QString userSamplesDir() const
|
|
{
|
|
return workingDir() + SAMPLES_PATH;
|
|
}
|
|
|
|
|
|
const QString & vstDir() const
|
|
{
|
|
return m_vstDir;
|
|
}
|
|
|
|
const QString & ladspaDir() const
|
|
{
|
|
return m_ladspaDir;
|
|
}
|
|
|
|
const QString & sf2Dir() const
|
|
{
|
|
return m_sf2Dir;
|
|
}
|
|
|
|
#ifdef LMMS_HAVE_FLUIDSYNTH
|
|
const QString & sf2File() const
|
|
{
|
|
return m_sf2File;
|
|
}
|
|
#endif
|
|
|
|
#ifdef LMMS_HAVE_STK
|
|
const QString & stkDir() const
|
|
{
|
|
return m_stkDir;
|
|
}
|
|
#endif
|
|
|
|
const QString & gigDir() const
|
|
{
|
|
return m_gigDir;
|
|
}
|
|
|
|
|
|
QString userVstDir() const
|
|
{
|
|
return m_vstDir;
|
|
}
|
|
|
|
QString userLadspaDir() const
|
|
{
|
|
return workingDir() + LADSPA_PATH;
|
|
}
|
|
|
|
QString userSf2Dir() const
|
|
{
|
|
return workingDir() + SF2_PATH;
|
|
}
|
|
|
|
QString userGigDir() const
|
|
{
|
|
return workingDir() + GIG_PATH;
|
|
}
|
|
|
|
QString defaultThemeDir() const
|
|
{
|
|
return m_dataDir + DEFAULT_THEME_PATH;
|
|
}
|
|
|
|
QString themeDir() const
|
|
{
|
|
return m_themeDir;
|
|
}
|
|
|
|
const QString & backgroundPicFile() const
|
|
{
|
|
return m_backgroundPicFile;
|
|
}
|
|
|
|
QString trackIconsDir() const
|
|
{
|
|
return m_dataDir + TRACK_ICON_PATH;
|
|
}
|
|
|
|
const QString recoveryFile() const
|
|
{
|
|
return m_workingDir + "recover.mmp";
|
|
}
|
|
|
|
inline const QStringList & recentlyOpenedProjects() const
|
|
{
|
|
return m_recentlyOpenedProjects;
|
|
}
|
|
|
|
QString localeDir() const
|
|
{
|
|
return m_dataDir + LOCALE_PATH;
|
|
}
|
|
|
|
const QString & version() const
|
|
{
|
|
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;
|
|
|
|
|
|
static QStringList availableVstEmbedMethods();
|
|
QString vstEmbedMethod() const;
|
|
|
|
// Returns true if the working dir (e.g. ~/lmms) exists on disk.
|
|
bool hasWorkingDir() const;
|
|
|
|
void addRecentlyOpenedProject(const QString & _file);
|
|
|
|
const QString & value(const QString & cls,
|
|
const QString & attribute) const;
|
|
const QString & value(const QString & cls,
|
|
const QString & attribute,
|
|
const QString & defaultVal) const;
|
|
void setValue(const QString & cls, const QString & attribute,
|
|
const QString & value);
|
|
void deleteValue(const QString & cls, const QString & attribute);
|
|
|
|
void loadConfigFile(const QString & configFile = "");
|
|
void saveConfigFile();
|
|
|
|
|
|
void setWorkingDir(const QString & workingDir);
|
|
void setVSTDir(const QString & vstDir);
|
|
void setLADSPADir(const QString & ladspaDir);
|
|
void setSF2Dir(const QString & sf2Dir);
|
|
void setSF2File(const QString & sf2File);
|
|
void setSTKDir(const QString & stkDir);
|
|
void setGIGDir(const QString & gigDir);
|
|
void setThemeDir(const QString & themeDir);
|
|
void setBackgroundPicFile(const QString & backgroundPicFile);
|
|
|
|
// Creates the working directory & subdirectories on disk.
|
|
void createWorkingDir();
|
|
|
|
signals:
|
|
void valueChanged( QString cls, QString attribute, QString value );
|
|
|
|
private:
|
|
static ConfigManager * s_instanceOfMe;
|
|
|
|
ConfigManager();
|
|
ConfigManager(const ConfigManager & _c);
|
|
~ConfigManager();
|
|
|
|
void upgrade_1_1_90();
|
|
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;
|
|
QString m_ladspaDir;
|
|
QString m_sf2Dir;
|
|
#ifdef LMMS_HAVE_FLUIDSYNTH
|
|
QString m_sf2File;
|
|
#endif
|
|
#ifdef LMMS_HAVE_STK
|
|
QString m_stkDir;
|
|
#endif
|
|
QString m_gigDir;
|
|
QString m_themeDir;
|
|
QString m_backgroundPicFile;
|
|
QString m_lmmsRcFile;
|
|
QString m_version;
|
|
unsigned int m_configVersion;
|
|
QStringList m_recentlyOpenedProjects;
|
|
|
|
typedef QVector<QPair<QString, QString> > stringPairVector;
|
|
typedef QMap<QString, stringPairVector> settingsMap;
|
|
settingsMap m_settings;
|
|
|
|
|
|
friend class LmmsCore;
|
|
};
|
|
#endif
|