Don't save default weapon scheme in file; don't load weapon scheme from file if name collides with default scheme
authorWuzzy <Wuzzy2@mail.ru>
Fri, 05 Oct 2018 19:25:14 +0200
changeset 13857 e7c69e849005
parent 13856 f01798038c2e
child 13858 46e1c1069ac2
Don't save default weapon scheme in file; don't load weapon scheme from file if name collides with default scheme
QTfrontend/ui/widget/selectWeapon.cpp
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Fri Oct 05 17:27:12 2018 +0200
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Fri Oct 05 19:25:14 2018 +0200
@@ -94,23 +94,22 @@
     if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
         QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
     }
+    QStringList defaultAmmos;
+    for(int i = 0; i < cDefaultAmmos.size(); ++i)
+    {
+        defaultAmmos.append(cDefaultAmmos[i].first.toLower());
+    }
     if (!QDir(cfgdir->absolutePath() + "/Schemes/Ammo").exists()) {
         qDebug("No /Schemes/Ammo directory found. Trying to import weapon schemes from weapons.ini.");
         QDir().mkdir(cfgdir->absolutePath() + "/Schemes/Ammo");
 
         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
 
-        QStringList defaultAmmos;
-        for(int i = 0; i < cDefaultAmmos.size(); ++i)
-        {
-            defaultAmmos.append(cDefaultAmmos[i].first);
-        }
-
         QStringList keys = old_wconf.allKeys();
         int imported = 0;
         for(int i = 0; i < keys.size(); i++)
         {
-            if (!defaultAmmos.contains(keys[i])) {
+            if (!defaultAmmos.contains(keys[i].toLower())) {
                 wconf->insert(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
                 QFile file(cfgdir->absolutePath() + "/Schemes/Ammo/" + keys[i] + ".hwa");
                 if (file.open(QIODevice::WriteOnly)) {
@@ -140,7 +139,11 @@
             if (schemeName.endsWith(".hwa", Qt::CaseInsensitive)) {
                 schemeName.chop(4);
             }
-            wconf->insert(schemeName, fixWeaponSet(config));
+            // Don't load weapon scheme if name collides with any default scheme
+            if (!defaultAmmos.contains(schemeName.toLower()))
+                wconf->insert(schemeName, fixWeaponSet(config));
+            else
+                qWarning("Weapon scheme \"%s\" not loaded from file, name collides with a default scheme!", qPrintable(schemeName));
         }
     }
 
@@ -254,6 +257,13 @@
     if (m_name->text() == "")
         return;
 
+    // Don't save an default ammo scheme
+    for(int i = 0; i < cDefaultAmmos.size(); ++i)
+    {
+        if(curWeaponsName == cDefaultAmmos[i].first)
+            return;
+    }
+
     QString state1;
     QString state2;
     QString state3;