const char* Settings::get(const StringView& _name) const { ini_t* ini = INI_T(m_ini); FilePath uri(_name); const StringView path(strTrim(uri.getPath(), "/") ); const StringView& fileName(uri.getFileName() ); int32_t section = INI_GLOBAL_SECTION; if (!path.isEmpty() ) { section = ini_find_section(ini, path.getPtr(), path.getLength() ); if (INI_NOT_FOUND == section) { section = INI_GLOBAL_SECTION; } } int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() ); if (INI_NOT_FOUND == property) { return NULL; } return ini_property_value(ini, section, property); }
void Settings::remove(const StringView& _name) const { ini_t* ini = INI_T(m_ini); FilePath uri(_name); const StringView path = strTrim(uri.getPath(), "/"); const StringView& fileName = uri.getFileName(); int32_t section = INI_GLOBAL_SECTION; if (!path.isEmpty() ) { section = ini_find_section(ini, path.getPtr(), path.getLength() ); if (INI_NOT_FOUND == section) { section = INI_GLOBAL_SECTION; } } int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() ); if (INI_NOT_FOUND == property) { return; } ini_property_remove(ini, section, property); if (INI_GLOBAL_SECTION != section && 0 == ini_property_count(ini, section) ) { ini_section_remove(ini, section); } }
int32_t Settings::write(WriterI* _writer, Error* _err) const { ini_t* ini = INI_T(m_ini); int32_t size = ini_save(ini, NULL, 0); void* data = BX_ALLOC(m_allocator, size); ini_save(ini, (char*)data, size); int32_t total = bx::write(_writer, data, size-1, _err); BX_FREE(m_allocator, data); return total; }
void Settings::load(const void* _data, uint32_t _len) { if (NULL != m_ini) { ini_destroy(INI_T(m_ini) ); } if (NULL == _data) { m_ini = ini_create(m_allocator); } else { m_ini = ini_load( (const char*)_data, _len, m_allocator); } }
void Settings::set(const StringView& _name, const StringView& _value) { ini_t* ini = INI_T(m_ini); FilePath uri(_name); const StringView path(strTrim(uri.getPath(), "/") ); const StringView& fileName(uri.getFileName() ); int32_t section = INI_GLOBAL_SECTION; if (!path.isEmpty() ) { section = ini_find_section(ini, path.getPtr(), path.getLength() ); if (INI_NOT_FOUND == section) { section = ini_section_add(ini, path.getPtr(), path.getLength() ); } } int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() ); if (INI_NOT_FOUND == property) { ini_property_add( ini , section , fileName.getPtr() , fileName.getLength() , _value.getPtr() , _value.getLength() ); } else { ini_property_value_set( ini , section , property , _value.getPtr() , _value.getLength() ); } }
Settings::~Settings() { ini_destroy(INI_T(m_ini) ); }