add validation for extra config files

This commit is contained in:
scatterflower 2020-09-02 08:23:23 -05:00
parent 857e36b835
commit 24dfc3cdb8
3 changed files with 36 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class ConfigManager {
private:
QSettings* config;
bool fileExists(QFileInfo *file);
};
#endif // CONFIG_MANAGER_H

View File

@ -31,12 +31,37 @@ bool ConfigManager::initConfig()
return false;
}
// Check that areas, characters, and music lists all exist
QFileInfo areas_info("config/areas.ini");
QFileInfo characters_info("config/characters.txt");
QFileInfo music_info("config/music.txt");
if (!fileExists(&areas_info)) {
qCritical() << "areas.ini doesn't exist!";
return false;
}
else {
QSettings areas_ini("config/areas.ini", QSettings::IniFormat);
if (areas_ini.childGroups().length() < 1) {
qCritical() << "areas.ini is invalid!";
return false;
}
}
if (!fileExists(&characters_info)) {
qCritical() << "characters.txt doesn't exist!";
return false;
}
if (!fileExists(&music_info)) {
qCritical() << "music.txt doesn't exist!";
return false;
}
config->beginGroup("Info");
QString config_version = config->value("version", "none").toString();
config->endGroup();
if (config_version == "none") {
QFileInfo check_file("config/config.ini");
if (!(check_file.exists() && check_file.isFile())) {
if (!fileExists(&check_file)) {
qCritical() << "config.ini doesn't exist!";
}
else {
@ -133,3 +158,8 @@ bool ConfigManager::loadServerSettings(server_settings* settings)
return true;
}
}
bool ConfigManager::fileExists(QFileInfo* file)
{
return (file->exists() && file->isFile());
}

View File

@ -65,6 +65,10 @@ void Server::start()
for (int i = 0; i < area_names.length(); i++) {
QString area_name = area_names[i];
areas.insert(i, new AreaData(characters, area_name, i));
areas_ini.beginGroup(area_name);
// TODO: more area config
areas[i]->background = areas_ini.value("background", "gs4").toString();
areas_ini.endGroup();
qDebug() << "Added area" << area_name;
}
}