Return some default db name if not present in the config file

This commit is contained in:
King_DuckZ 2020-08-11 01:04:53 +01:00
parent bc0de0cf8b
commit d0a41d916a
4 changed files with 5 additions and 2 deletions

View file

@ -1 +1,2 @@
option('base_url', type: 'string', value: 'https://api.originsro.org') option('base_url', type: 'string', value: 'https://api.originsro.org')
option('def_sqlite_db_name', type: 'string', value: 'originsro.db3')

View file

@ -41,11 +41,11 @@ std::string_view AppConfig::db_path() const {
const auto& map = m_ini.parsed(); const auto& map = m_ini.parsed();
auto it_section = map.find("main"); auto it_section = map.find("main");
if (map.end() == it_section) if (map.end() == it_section)
return ""; return g_def_sqlite_db_name;
auto it_setting = it_section->second.find("db_path"); auto it_setting = it_section->second.find("db_path");
if (it_section->second.end() == it_setting) if (it_section->second.end() == it_setting)
return ""; return g_def_sqlite_db_name;
return it_setting->second; return it_setting->second;
} }

View file

@ -21,5 +21,6 @@ namespace duck {
constexpr const char g_base_url[] = @BASE_URL@; constexpr const char g_base_url[] = @BASE_URL@;
constexpr const char g_config_file_path[] = @CONFIG_FILE_PATH@; constexpr const char g_config_file_path[] = @CONFIG_FILE_PATH@;
constexpr const char g_def_sqlite_db_name[] = @DEF_SQLITE_DB_NAME@;
} //namespace duck } //namespace duck

View file

@ -22,6 +22,7 @@ endif
conf = configuration_data() conf = configuration_data()
conf.set_quoted('BASE_URL', base_url) conf.set_quoted('BASE_URL', base_url)
conf.set_quoted('CONFIG_FILE_PATH', get_option('prefix') / get_option('sysconfdir') / meson.project_name() + '.conf') conf.set_quoted('CONFIG_FILE_PATH', get_option('prefix') / get_option('sysconfdir') / meson.project_name() + '.conf')
conf.set_quoted('DEF_SQLITE_DB_NAME', get_option('def_sqlite_db_name'))
project_config_file = configure_file( project_config_file = configure_file(
input: 'config.hpp.in', input: 'config.hpp.in',
output: meson.project_name() + '_config.hpp', output: meson.project_name() + '_config.hpp',