diff --git a/include/config_manager.h b/include/config_manager.h index e433e17..cd5b8ae 100644 --- a/include/config_manager.h +++ b/include/config_manager.h @@ -46,6 +46,7 @@ class ConfigManager { private: QSettings* config; + bool fileExists(QFileInfo *file); }; #endif // CONFIG_MANAGER_H diff --git a/src/config_manager.cpp b/src/config_manager.cpp index fbbd744..086ec90 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -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()); +} diff --git a/src/server.cpp b/src/server.cpp index c21c89e..33a98b4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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; } }