From 97b1995de0d87441879d22efd1bc6464f5025091 Mon Sep 17 00:00:00 2001 From: NotAFreak Date: Sat, 30 May 2026 10:19:33 +1000 Subject: [PATCH 1/2] Allow optionally overwriting to an ini file --- ini/ini.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ini/ini.h b/ini/ini.h index e3ccdaf..2c353b1 100644 --- a/ini/ini.h +++ b/ini/ini.h @@ -598,13 +598,18 @@ class INIWriter { * @brief Write the contents of an INI file to a new file * @param filepath The path of the output file * @param reader The INIReader object to write to the file + * @param overwrite Whether to just overwrite an existing file * @throws std::runtime_error if the output file already exists or cannot be * opened */ - inline static void write(const std::string& filepath, - const INIReader& reader) { - if (struct stat buf; stat(filepath.c_str(), &buf) == 0) { - throw std::runtime_error("file: " + filepath + " already exist."); + inline static void write(const std::string& filepath, const INIReader& reader, + const bool& overwrite = false) { + if (overwrite) { + std::remove(filepath.c_str()); + } else { + if (struct stat buf; stat(filepath.c_str(), &buf) == 0) { + throw std::runtime_error("file: " + filepath + " already exists."); + } } std::ofstream out; out.open(filepath); From fa0a51506e36857579f1f4e5db7b663b3bc98848 Mon Sep 17 00:00:00 2001 From: NotAFreak Date: Sat, 30 May 2026 17:15:12 +1000 Subject: [PATCH 2/2] fixed for linting --- ini/ini.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ini/ini.h b/ini/ini.h index 2c353b1..3fbafc9 100644 --- a/ini/ini.h +++ b/ini/ini.h @@ -200,7 +200,7 @@ inline int ini_parse(const char* filename, ini_handler handler, void* user) { class INIReader { public: // Empty Constructor - INIReader(){}; + INIReader() {}; // Construct INIReader and parse given filename. See ini.h for more info // about the parsing. @@ -593,7 +593,7 @@ inline int INIReader::ValueHandler(void* user, const char* section, class INIWriter { public: - INIWriter(){}; + INIWriter() {}; /** * @brief Write the contents of an INI file to a new file * @param filepath The path of the output file @@ -602,13 +602,15 @@ class INIWriter { * @throws std::runtime_error if the output file already exists or cannot be * opened */ - inline static void write(const std::string& filepath, const INIReader& reader, + inline static void write(const std::string& filepath, + const INIReader& reader, const bool& overwrite = false) { if (overwrite) { std::remove(filepath.c_str()); } else { if (struct stat buf; stat(filepath.c_str(), &buf) == 0) { - throw std::runtime_error("file: " + filepath + " already exists."); + throw std::runtime_error("file: " + filepath + + " already exists."); } } std::ofstream out;