Fix bad import of old ammo schemes, improve debug output when importing schemes from old .ini files
authorWuzzy <Wuzzy2@mail.ru>
Wed, 14 Mar 2018 12:17:11 +0100
changeset 13200 7d9462d49d4c
parent 13199 290815bbd4e1
child 13201 f93658732448
Fix bad import of old ammo schemes, improve debug output when importing schemes from old .ini files
QTfrontend/model/ammoSchemeModel.cpp
QTfrontend/ui/widget/selectWeapon.cpp
--- a/QTfrontend/model/ammoSchemeModel.cpp	Wed Mar 14 01:33:37 2018 +0100
+++ b/QTfrontend/model/ammoSchemeModel.cpp	Wed Mar 14 12:17:11 2018 +0100
@@ -732,29 +732,37 @@
     schemes.append(spaceinvasion);
     schemes.append(hedgeeditor);
 
-    if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
+    if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
+        QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
+    }
     if (!QDir(directory).exists()) {
         QDir().mkdir(directory);
 
+        qDebug("No /Schemes/Game directory found. Trying to import game schemes from schemes.ini.");
+
         int size = fileConfig.beginReadArray("schemes");
+        int imported = 0;
         for (int i = 0; i < size; ++i)
         {
             fileConfig.setArrayIndex(i);
 
-            if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString()))
+            QString schemeName = fileConfig.value(spNames[0]).toString();
+            if (!predefSchemesNames.contains(schemeName))
             {
                 QList<QVariant> scheme;
-                QSettings file(directory + "/" + fileConfig.value(spNames[0]).toString() + ".hwg", QSettings::IniFormat);
+                QSettings file(directory + "/" + schemeName + ".hwg", QSettings::IniFormat);
 
                 for (int k = 0; k < spNames.size(); ++k) {
                     scheme << fileConfig.value(spNames[k], defaultScheme[k]);
                     file.setValue(spNames[k], fileConfig.value(spNames[k], defaultScheme[k]));
                 }
                 file.sync();
+                imported++;
 
                 schemes.append(scheme);
             }
         }
+        qDebug("%d game scheme(s) imported.", imported);
         fileConfig.endArray();
     } else {
         QStringList scheme_dir = QDir(directory).entryList();
--- a/QTfrontend/ui/widget/selectWeapon.cpp	Wed Mar 14 01:33:37 2018 +0100
+++ b/QTfrontend/ui/widget/selectWeapon.cpp	Wed Mar 14 12:17:11 2018 +0100
@@ -85,32 +85,37 @@
     QFrame(parent),
     m_numItems(numItems)
 {
-    if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
+    if (!QDir(cfgdir->absolutePath() + "/Schemes").exists()) {
+        QDir().mkdir(cfgdir->absolutePath() + "/Schemes");
+    }
     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");
         wconf = new QSettings("Hedgewars", "Hedgewars");
         wconf->clear();
         QSettings old_wconf(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat);
 
-        QList<QVariant> defaultAmmos;
+        QStringList defaultAmmos;
         for(int i = 0; i < cDefaultAmmos.size(); ++i) {
             wconf->setValue(cDefaultAmmos[i].first, cDefaultAmmos[i].second);
             defaultAmmos.append(cDefaultAmmos[i].first);
         }
 
         QStringList keys = old_wconf.allKeys();
+        int imported = 0;
         for(int i = 0; i < keys.size(); i++)
         {
-            wconf->setValue(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
-
             if (!defaultAmmos.contains(keys[i])) {
+                wconf->setValue(keys[i], fixWeaponSet(old_wconf.value(keys[i]).toString()));
                 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;
                 }
+                imported++;
             }
         }
+        qDebug("%d weapon scheme(s) imported.", imported);
     } else {
         wconf = new QSettings("Hedgewars", "Hedgewars");
         wconf->clear();