Fix how scheme files behave
authorKoBeWi
Thu, 08 Feb 2018 09:14:20 +0100
changeset 12923 305f3667af20
parent 12922 c0320d66310d
child 12924 48b9f15859b0
Fix how scheme files behave
QTfrontend/model/ammoSchemeModel.cpp
QTfrontend/ui/widget/selectWeapon.cpp
--- a/QTfrontend/model/ammoSchemeModel.cpp	Thu Feb 08 08:50:45 2018 +0100
+++ b/QTfrontend/model/ammoSchemeModel.cpp	Thu Feb 08 09:14:20 2018 +0100
@@ -680,7 +680,7 @@
     schemes.append(construction);
     schemes.append(hedgeeditor);
 
-
+    if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
     if (!QDir(directory).exists()) {
         QDir().mkdir(directory);
 
@@ -692,7 +692,7 @@
             if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString()))
             {
                 QList<QVariant> scheme;
-                QSettings file(directory + "/" + fileConfig.value(spNames[0]).toString() + ".ini", QSettings::IniFormat);
+                QSettings file(directory + "/" + fileConfig.value(spNames[0]).toString() + ".hwg", QSettings::IniFormat);
 
                 for (int k = 0; k < spNames.size(); ++k) {
                     scheme << fileConfig.value(spNames[k], defaultScheme[k]);
@@ -833,7 +833,7 @@
 
     QList<QVariant> scheme = schemes[row];
     int j = spNames.indexOf("name");
-    QFile(cfgdir->absolutePath() + "/Game Settings/" + scheme[j].toString() + ".ini").remove();
+    QFile(cfgdir->absolutePath() + "/Schemes/Game/" + scheme[j].toString() + ".hwg").remove();
     schemes.removeAt(row);
 
     endRemoveRows();
@@ -859,7 +859,7 @@
     {
         QList<QVariant> scheme = schemes[i + numberOfDefaultSchemes];
         int j = spNames.indexOf("name");
-        QSettings file(cfgdir->absolutePath() + "/Game Settings/" + scheme[j].toString() + ".ini", QSettings::IniFormat);
+        QSettings file(cfgdir->absolutePath() + "/Schemes/Game/" + scheme[j].toString() + ".hwg", QSettings::IniFormat);
 
         for (int k = 0; k < scheme.size(); ++k)
             file.setValue(spNames[k], scheme[k]);
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Thu Feb 08 08:50:45 2018 +0100
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Thu Feb 08 09:14:20 2018 +0100
@@ -85,36 +85,46 @@
     QFrame(parent),
     m_numItems(numItems)
 {
-    if (!QDir(cfgdir->absolutePath() + "/Weapon Settings").exists()) {
-        QDir().mkdir(cfgdir->absolutePath() + "/Weapon Settings");
-        wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this);
+    if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
+    if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
+        QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
+        wconf = new QSettings("Hedgewars", "Hedgewars");
+        wconf->clear();
+        QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
 
-        for(int i = 0; i < cDefaultAmmos.size(); ++i)
+        QList<QVariant> defaultAmmos;
+        for(int i = 0; i < cDefaultAmmos.size(); ++i) {
             wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
+            defaultAmmos.append(cDefaultAmmos[i].first);
+        }
 
-        QStringList keys = wconf->allKeys();
+        QStringList keys = old_wconf.allKeys();
         for(int i = 0; i < keys.size(); i++)
         {
-            if (wconf->value(keys[i]).toString().size() != cDefaultAmmoStore->size())
-                wconf->setValue(keys[i], fixWeaponSet(wconf->value(keys[i]).toString()));
+            wconf->setValue(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
 
-            QFile file(cfgdir->absolutePath() + "/Weapon Settings/" + keys[i] + ".hww");
-            if (file.open(QIODevice::WriteOnly)) {
-                QTextStream stream( &file );
-                stream << wconf->value(keys[i]).toString() << endl;
+            if (!defaultAmmos.contains(keys[i])) {
+                QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa");
+                if (file.open(QIODevice::WriteOnly)) {
+                    QTextStream stream( &file );
+                    stream << old_wconf.value(keys[i]).toString() << endl;
+                }
             }
         }
     } else {
         wconf = new QSettings("Hedgewars", "Hedgewars");
         wconf->clear();
 
-        QStringList schemes = QDir(cfgdir->absolutePath() + "/Weapon Settings").entryList();
+        for(int i = 0; i < cDefaultAmmos.size(); ++i)
+            wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
+
+        QStringList schemes = QDir(cfgdir->absolutePath() + "/Schemes/Ammo").entryList();
 
         for(int i = 0; i < schemes.size(); i++)
         {
             if (schemes[i] == "." || schemes[i] == "..") continue;
 
-            QFile file(cfgdir->absolutePath() + "/Weapon Settings/" + schemes[i]);
+            QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + schemes[i]);
             QString config;
 
             if (file.open(QIODevice::ReadOnly)) {
@@ -122,7 +132,7 @@
                 stream >> config;
             }
 
-            wconf->setValue(schemes[i].remove(".hww"), fixWeaponSet(config));
+            wconf->setValue(schemes[i].remove(".hwa"), fixWeaponSet(config));
         }
     }
 
@@ -281,7 +291,7 @@
         wconf->remove(curWeaponsName);
     }
     wconf->setValue(m_name->text(), stateFull);
-    QFile file(cfgdir->absolutePath() + "/Weapon Settings/" + m_name->text()+ ".hww");
+    QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + m_name->text()+ ".hwa");
     if (file.open(QIODevice::WriteOnly)) {
         QTextStream stream( &file );
         stream << stateFull << endl;
@@ -328,7 +338,7 @@
     {
         isDeleting = true;
         wconf->remove(delWeaponsName);
-        QFile(cfgdir->absolutePath() + "/Weapon Settings/" + curWeaponsName + ".hww").remove();
+        QFile(cfgdir->absolutePath() + "/Schemes/Ammo/" + curWeaponsName + ".hwa").remove();
         emit weaponsDeleted(delWeaponsName);
     }
 }