add validation for extra config files
This commit is contained in:
parent
857e36b835
commit
24dfc3cdb8
@ -46,6 +46,7 @@ class ConfigManager {
|
||||
|
||||
private:
|
||||
QSettings* config;
|
||||
bool fileExists(QFileInfo *file);
|
||||
};
|
||||
|
||||
#endif // CONFIG_MANAGER_H
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user