Stop PhysFS from complaining when a random name .cfg file is missing
authorWuzzy <almikes@aol.com>
Sat, 23 Sep 2017 07:38:41 +0200
changeset 12504 d97050a7c074
parent 12503 9f135bd021fe
child 12505 2e7a32c44ab3
Stop PhysFS from complaining when a random name .cfg file is missing
QTfrontend/util/namegen.cpp
--- a/QTfrontend/util/namegen.cpp	Sat Sep 23 06:54:48 2017 +0200
+++ b/QTfrontend/util/namegen.cpp	Sat Sep 23 07:38:41 2017 +0200
@@ -18,6 +18,7 @@
  */
 
 #include <QFile>
+#include <QFileInfo>
 #include <QTextStream>
 #include <QStringList>
 #include <QLineEdit>
@@ -176,22 +177,32 @@
 {
     QStringList list;
 
-    // find .cfg to load the dicts from
-    QFile file(QString("physfs://Names/%1.cfg").arg(hatname));
+    // Find and check .cfg to load the dicts from
+    QString path = QString("physfs://Names/%1.cfg").arg(hatname);
+    QFileInfo check_file(path);
 
-    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
+    // Note: The .cfg file is optional; a fallback mechanism is in place (see below)
+
+    // Check if file exists to prevent PhysFS from complaining in console so much
+    if (check_file.exists() && check_file.isFile())
     {
-        QTextStream in(&file);
-        QString line;
-        do
+        QFile file(path);
+
+        if (file.open(QIODevice::ReadOnly | QIODevice::Text))
         {
-            line = in.readLine();
+            QTextStream in(&file);
+            QString line;
+            do
+            {
+                line = in.readLine();
 
-            if(!line.isEmpty())
-                list.append(line);
-        } while (!line.isNull());
+                if(!line.isEmpty())
+                    list.append(line);
+            } while (!line.isNull());
+        }
     }
 
+    // Use Data/Names/generic.cfg by default
     if (list.size() == 0)
         list.append(QString("generic"));