Switch to 'settings.ini'. Copies old ini file if necessary on startup.
authorunc0rr
Thu, 18 Apr 2013 00:41:27 +0400
changeset 8918 512753ea4b1b
parent 8917 263f2a8475bc
child 8919 67214340fa53
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
QTfrontend/hwform.cpp
QTfrontend/main.cpp
QTfrontend/ui/page/pagetraining.cpp
QTfrontend/util/DataManager.cpp
QTfrontend/util/DataManager.h
--- a/QTfrontend/hwform.cpp	Wed Apr 17 11:24:06 2013 -0400
+++ b/QTfrontend/hwform.cpp	Thu Apr 18 00:41:27 2013 +0400
@@ -151,7 +151,7 @@
 
     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
 
-    config = new GameUIConfig(this, "physfs://hedgewars.ini");
+    config = new GameUIConfig(this, DataManager::instance().settingsFileName());
     frontendEffects = config->value("frontend/effects", true).toBool();
     playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
 
--- a/QTfrontend/main.cpp	Wed Apr 17 11:24:06 2013 -0400
+++ b/QTfrontend/main.cpp	Thu Apr 18 00:41:27 2013 +0400
@@ -261,11 +261,11 @@
     engine->setWriteDir(cfgdir->absolutePath());
     engine->mountPacks();
 
-    DataManager::ensureFileExists("physfs://hedgewars.ini");
-
     QTranslator Translator;
     {
-        QSettings settings("physfs://hedgewars.ini", QSettings::IniFormat);
+        QSettings settings(DataManager::instance().settingsFileName(), QSettings::IniFormat);
+        settings.setIniCodec("UTF-8");
+
         QString cc = settings.value("misc/locale", QString()).toString();
         if (cc.isEmpty())
             cc = HWApplication::keyboardInputLocale().name();
--- a/QTfrontend/ui/page/pagetraining.cpp	Wed Apr 17 11:24:06 2013 -0400
+++ b/QTfrontend/ui/page/pagetraining.cpp	Thu Apr 18 00:41:27 2013 +0400
@@ -118,7 +118,7 @@
     DataManager & dataMgr = DataManager::instance();
 
     // get locale
-    QSettings settings("physfs://hedgewars.ini",
+    QSettings settings(dataMgr.settingsFileName(),
                        QSettings::IniFormat);
 
     QString loc = settings.value("misc/locale", "").toString();
--- a/QTfrontend/util/DataManager.cpp	Wed Apr 17 11:24:06 2013 -0400
+++ b/QTfrontend/util/DataManager.cpp	Thu Apr 18 00:41:27 2013 +0400
@@ -25,6 +25,7 @@
 #include <QStringList>
 #include <QStandardItemModel>
 #include <QFileInfo>
+#include <QSettings>
 
 #include "hwconsts.h"
 #include "HWApplication.h"
@@ -162,6 +163,36 @@
     return m_bindsModel;
 }
 
+QString DataManager::settingsFileName()
+{
+    if(m_settingsFileName.isEmpty())
+    {
+        QFile settingsFile("physfs://settings.ini");
+
+        if(!settingsFile.exists())
+        {
+            QFile oldSettingsFile("physfs://hedgewars.ini");
+
+            settingsFile.open(QFile::WriteOnly);
+            settingsFile.close();
+
+            if(oldSettingsFile.exists())
+            {
+                QSettings sOld(oldSettingsFile.fileName(), QSettings::IniFormat);
+                QSettings sNew(settingsFile.fileName(), QSettings::IniFormat);
+                sNew.setIniCodec("UTF-8");
+
+                foreach(const QString & key, sOld.allKeys())
+                    sNew.setValue(key, sOld.value(key));
+            }
+        }
+
+        m_settingsFileName = settingsFile.fileName();
+    }
+
+    return m_settingsFileName;
+}
+
 void DataManager::reload()
 {
     // removed for now (also code was a bit unclean, could lead to segfault if
--- a/QTfrontend/util/DataManager.h	Wed Apr 17 11:24:06 2013 -0400
+++ b/QTfrontend/util/DataManager.h	Thu Apr 18 00:41:27 2013 +0400
@@ -117,6 +117,8 @@
         QStandardItemModel * colorsModel();
         QStandardItemModel * bindsModel();
 
+        QString settingsFileName();
+
         static bool ensureFileExists(const QString & fileName);
 
     public slots:
@@ -148,6 +150,7 @@
         ThemeModel * m_themeModel; ///< theme model instance
         QStandardItemModel * m_colorsModel;
         QStandardItemModel * m_bindsModel;
+        QString m_settingsFileName;
 };
 
 #endif // HEDGEWARS_DATAMANAGER_H