diff --git a/src/base_media_base.h b/src/base_media_base.h index f38e130f10..4fc897acf2 100644 --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -95,7 +95,7 @@ struct BaseSet { return Tnum_files - this->valid_files; } - bool FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename = true); + bool FillSetDetails(IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename = true); /** * Get the description for the given ISO code. @@ -244,7 +244,7 @@ struct GraphicsSet : BaseSet { PaletteType palette; ///< Palette of this graphics set BlitterType blitter; ///< Blitter of this graphics set - bool FillSetDetails(struct IniFile *ini, const std::string &path, const std::string &full_filename); + bool FillSetDetails(IniFile &ini, const std::string &path, const std::string &full_filename); static MD5File::ChecksumResult CheckMD5(const MD5File *file, Subdirectory subdir); }; @@ -301,7 +301,7 @@ struct MusicSet : BaseSet { /** Number of valid songs in set. */ byte num_available; - bool FillSetDetails(struct IniFile *ini, const std::string &path, const std::string &full_filename); + bool FillSetDetails(IniFile &ini, const std::string &path, const std::string &full_filename); }; /** All data/functions related with replacing the base music */ diff --git a/src/base_media_func.h b/src/base_media_func.h index 9ea40f2de8..7098ebd985 100644 --- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -39,9 +39,9 @@ extern void CheckExternalFiles(); * @return true if loading was successful. */ template -bool BaseSet::FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename) +bool BaseSet::FillSetDetails(IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename) { - IniGroup *metadata = ini->GetGroup("metadata"); + IniGroup *metadata = ini.GetGroup("metadata"); IniItem *item; fetch_metadata("name"); @@ -69,9 +69,9 @@ bool BaseSet::FillSetDetails(IniFile *ini, const this->fallback = (item != nullptr && item->value && *item->value != "0" && *item->value != "false"); /* For each of the file types we want to find the file, MD5 checksums and warning messages. */ - IniGroup *files = ini->GetGroup("files"); - IniGroup *md5s = ini->GetGroup("md5s"); - IniGroup *origin = ini->GetGroup("origin"); + IniGroup *files = ini.GetGroup("files"); + IniGroup *md5s = ini.GetGroup("md5s"); + IniGroup *origin = ini.GetGroup("origin"); for (uint i = 0; i < Tnum_files; i++) { MD5File *file = &this->files[i]; /* Find the filename first. */ @@ -159,9 +159,9 @@ bool BaseMedia::AddFile(const std::string &filename, size_t basepath_ Debug(grf, 1, "Checking {} for base " SET_TYPE " set", filename); Tbase_set *set = new Tbase_set(); - IniFile *ini = new IniFile(); + IniFile ini{}; std::string path{ filename, basepath_length }; - ini->LoadFromDisk(path, BASESET_DIR); + ini.LoadFromDisk(path, BASESET_DIR); auto psep = path.rfind(PATHSEPCHAR); if (psep != std::string::npos) { @@ -218,7 +218,6 @@ bool BaseMedia::AddFile(const std::string &filename, size_t basepath_ delete set; } - delete ini; return ret; } diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index bc91ea0094..352c15fe99 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -347,11 +347,11 @@ void GfxLoadSprites() UpdateCursorSize(); } -bool GraphicsSet::FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename) +bool GraphicsSet::FillSetDetails(IniFile &ini, const std::string &path, const std::string &full_filename) { bool ret = this->BaseSet::FillSetDetails(ini, path, full_filename, false); if (ret) { - IniGroup *metadata = ini->GetGroup("metadata"); + IniGroup *metadata = ini.GetGroup("metadata"); IniItem *item; fetch_metadata("palette"); diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index 478d2ca233..8356f0810c 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -274,9 +274,9 @@ HotkeyList::~HotkeyList() * Load HotkeyList from IniFile. * @param ini IniFile to load from. */ -void HotkeyList::Load(IniFile *ini) +void HotkeyList::Load(IniFile &ini) { - IniGroup *group = ini->GetGroup(this->ini_group); + IniGroup *group = ini.GetGroup(this->ini_group); for (Hotkey &hotkey : this->items) { IniItem *item = group->GetItem(hotkey.name); if (item != nullptr) { @@ -290,9 +290,9 @@ void HotkeyList::Load(IniFile *ini) * Save HotkeyList to IniFile. * @param ini IniFile to save to. */ -void HotkeyList::Save(IniFile *ini) const +void HotkeyList::Save(IniFile &ini) const { - IniGroup *group = ini->GetGroup(this->ini_group); + IniGroup *group = ini.GetGroup(this->ini_group); for (const Hotkey &hotkey : this->items) { IniItem &item = group->GetOrCreateItem(hotkey.name); item.SetValue(SaveKeycodes(hotkey)); @@ -320,8 +320,8 @@ int HotkeyList::CheckMatch(uint16_t keycode, bool global_only) const static void SaveLoadHotkeys(bool save) { - IniFile *ini = new IniFile(); - ini->LoadFromDisk(_hotkeys_file, NO_DIRECTORY); + IniFile ini{}; + ini.LoadFromDisk(_hotkeys_file, NO_DIRECTORY); for (HotkeyList *list : *_hotkey_lists) { if (save) { @@ -331,8 +331,7 @@ static void SaveLoadHotkeys(bool save) } } - if (save) ini->SaveToDisk(_hotkeys_file); - delete ini; + if (save) ini.SaveToDisk(_hotkeys_file); } diff --git a/src/hotkeys.h b/src/hotkeys.h index 1d5360a84d..4508500268 100644 --- a/src/hotkeys.h +++ b/src/hotkeys.h @@ -40,8 +40,8 @@ struct HotkeyList { HotkeyList(const std::string &ini_group, const std::vector &items, GlobalHotkeyHandlerFunc global_hotkey_handler = nullptr); ~HotkeyList(); - void Load(IniFile *ini); - void Save(IniFile *ini) const; + void Load(IniFile &ini); + void Save(IniFile &ini) const; int CheckMatch(uint16_t keycode, bool global_only = false) const; diff --git a/src/music.cpp b/src/music.cpp index d642f9b4cc..570eedcf2a 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -116,14 +116,14 @@ template return BaseMedia::used_set != nullptr; } -bool MusicSet::FillSetDetails(IniFile *ini, const std::string &path, const std::string &full_filename) +bool MusicSet::FillSetDetails(IniFile &ini, const std::string &path, const std::string &full_filename) { bool ret = this->BaseSet::FillSetDetails(ini, path, full_filename); if (ret) { this->num_available = 0; - IniGroup *names = ini->GetGroup("names"); - IniGroup *catindex = ini->GetGroup("catindex"); - IniGroup *timingtrim = ini->GetGroup("timingtrim"); + IniGroup *names = ini.GetGroup("names"); + IniGroup *catindex = ini.GetGroup("catindex"); + IniGroup *timingtrim = ini.GetGroup("timingtrim"); uint tracknr = 1; for (uint i = 0; i < lengthof(this->songinfo); i++) { const std::string &filename = this->files[i].filename; diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index 246e06201a..3eb0789e82 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -188,28 +188,14 @@ static const char *TEMPLATES_GROUP_NAME = "templates"; ///< Name of the group co static const char *VALIDATION_GROUP_NAME = "validation"; ///< Name of the group containing the validation statements. static const char *DEFAULTS_GROUP_NAME = "defaults"; ///< Name of the group containing default values for the template variables. -/** - * Load the INI file. - * @param filename Name of the file to load. - * @return Loaded INI data. - */ -static IniLoadFile *LoadIniFile(const char *filename) -{ - static const char * const seq_groups[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, nullptr}; - - IniLoadFile *ini = new SettingsIniFile(nullptr, seq_groups); - ini->LoadFromDisk(filename, NO_DIRECTORY); - return ini; -} - /** * Dump a #IGT_SEQUENCE group into #_stored_output. * @param ifile Loaded INI data. * @param group_name Name of the group to copy. */ -static void DumpGroup(IniLoadFile *ifile, const char * const group_name) +static void DumpGroup(IniLoadFile &ifile, const char * const group_name) { - IniGroup *grp = ifile->GetGroup(group_name, false); + IniGroup *grp = ifile.GetGroup(group_name, false); if (grp != nullptr && grp->type == IGT_SEQUENCE) { for (IniItem *item = grp->item; item != nullptr; item = item->next) { if (!item->name.empty()) { @@ -306,17 +292,17 @@ static void DumpLine(IniItem *item, IniGroup *grp, IniGroup *default_grp, Output * Output all non-special sections through the template / template variable expansion system. * @param ifile Loaded INI data. */ -static void DumpSections(IniLoadFile *ifile) +static void DumpSections(IniLoadFile &ifile) { static const char * const special_group_names[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, DEFAULTS_GROUP_NAME, TEMPLATES_GROUP_NAME, VALIDATION_GROUP_NAME, nullptr}; - IniGroup *default_grp = ifile->GetGroup(DEFAULTS_GROUP_NAME, false); - IniGroup *templates_grp = ifile->GetGroup(TEMPLATES_GROUP_NAME, false); - IniGroup *validation_grp = ifile->GetGroup(VALIDATION_GROUP_NAME, false); + IniGroup *default_grp = ifile.GetGroup(DEFAULTS_GROUP_NAME, false); + IniGroup *templates_grp = ifile.GetGroup(TEMPLATES_GROUP_NAME, false); + IniGroup *validation_grp = ifile.GetGroup(VALIDATION_GROUP_NAME, false); if (templates_grp == nullptr) return; /* Output every group, using its name as template name. */ - for (IniGroup *grp = ifile->group; grp != nullptr; grp = grp->next) { + for (IniGroup *grp = ifile.group; grp != nullptr; grp = grp->next) { const char * const *sgn; for (sgn = special_group_names; *sgn != nullptr; sgn++) if (grp->name == *sgn) break; if (*sgn != nullptr) continue; @@ -430,11 +416,14 @@ static const OptionData _opts[] = { */ static void ProcessIniFile(const char *fname) { - IniLoadFile *ini_data = LoadIniFile(fname); - DumpGroup(ini_data, PREAMBLE_GROUP_NAME); - DumpSections(ini_data); - DumpGroup(ini_data, POSTAMBLE_GROUP_NAME); - delete ini_data; + static const char * const seq_groups[] = {PREAMBLE_GROUP_NAME, POSTAMBLE_GROUP_NAME, nullptr}; + + SettingsIniFile ini{nullptr, seq_groups}; + ini.LoadFromDisk(fname, NO_DIRECTORY); + + DumpGroup(ini, PREAMBLE_GROUP_NAME); + DumpSections(ini); + DumpGroup(ini, POSTAMBLE_GROUP_NAME); } /**