aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop/qmpsettings.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2020-04-19 23:58:11 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2020-04-19 23:58:11 +0800
commit3e3a5e7ba353a02ac29c86eb94214d98a6c17bb7 (patch)
tree6dd321b65952ba147479bffaa59d063b92891693 /qmidiplayer-desktop/qmpsettings.cpp
parent6d568d07b31ba2ae39703cfd272d3003ea542018 (diff)
downloadQMidiPlayer-3e3a5e7ba353a02ac29c86eb94214d98a6c17bb7.tar.xz
Add configuration file revision checking.
Upgrading should be less dangerous now.
Diffstat (limited to 'qmidiplayer-desktop/qmpsettings.cpp')
-rw-r--r--qmidiplayer-desktop/qmpsettings.cpp17
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()