# HG changeset patch # User Wuzzy # Date 1506145121 -7200 # Node ID d97050a7c074c10859f31d2c3ecc6b713894f03d # Parent 9f135bd021fef0c6754a0b8350743fbcc5740e97 Stop PhysFS from complaining when a random name .cfg file is missing diff -r 9f135bd021fe -r d97050a7c074 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 +#include #include #include #include @@ -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"));