diff options
author | Chris Xiong <chirs241097@gmail.com> | 2020-04-19 23:58:11 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2020-04-19 23:58:11 +0800 |
commit | 3e3a5e7ba353a02ac29c86eb94214d98a6c17bb7 (patch) | |
tree | 6dd321b65952ba147479bffaa59d063b92891693 | |
parent | 6d568d07b31ba2ae39703cfd272d3003ea542018 (diff) | |
download | QMidiPlayer-3e3a5e7ba353a02ac29c86eb94214d98a6c17bb7.tar.xz |
Add configuration file revision checking.
Upgrading should be less dangerous now.
-rw-r--r-- | qmidiplayer-desktop/qmpsettings.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/qmidiplayer-desktop/qmpsettings.cpp b/qmidiplayer-desktop/qmpsettings.cpp index 134b73b..cdc96b8 100644 --- a/qmidiplayer-desktop/qmpsettings.cpp +++ b/qmidiplayer-desktop/qmpsettings.cpp @@ -1,11 +1,26 @@ #include "qmpsettings.hpp" +#include <QFile> #include <QStandardPaths> +#define QMP_CONFIGURATION_FILE_REV 1 + QSettings* qmpSettings::settings=nullptr; qmpSettings::qmpSettings() { qRegisterMetaTypeStreamOperators<QPair<QString,QString>>(); - settings=new QSettings(QStandardPaths::writableLocation(QStandardPaths::StandardLocation::ConfigLocation)+QString("/qmprc"),QSettings::IniFormat); + QString confpath=QStandardPaths::writableLocation(QStandardPaths::StandardLocation::ConfigLocation)+QString("/qmprc"); + settings=new QSettings(confpath,QSettings::IniFormat); + if(settings->value("ConfigurationFileRevision").toInt()!=QMP_CONFIGURATION_FILE_REV&& + QFile::exists(confpath)) + { + qWarning("Your current configuration file is not compatible with this version of QMidiPlayer. " + "QMidiPlayer will start with its default configuration. A backup of the old configuration " + "is automatically saved as qmprc.old."); + QFile::remove(confpath+".old"); + QFile::copy(confpath,confpath+".old"); + settings->clear(); + settings->setValue("ConfigurationFileRevision",QMP_CONFIGURATION_FILE_REV); + } } qmpSettings::~qmpSettings() |