QTfrontend/util/namegen.cpp
changeset 12499 d97050a7c074
parent 12295 ac57d564efce
child 12501 92c597704e57
--- 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"));