/* SWR INI Tool - Switchroot INI Configuration Editor Copyright (C) 2026 Switchroot This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. */ #pragma once #include #include #include class IniHandler { public: IniHandler(); bool load(const std::string& path); bool save(); bool save(const std::string& path); std::string get(const std::string& section, const std::string& key, const std::string& defaultValue = "") const; int getInt(const std::string& section, const std::string& key, int defaultValue = 0) const; bool getBool(const std::string& section, const std::string& key, bool defaultValue = false) const; void set(const std::string& section, const std::string& key, const std::string& value); void setInt(const std::string& section, const std::string& key, int value); void setBool(const std::string& section, const std::string& key, bool value); bool hasSection(const std::string& section) const; bool hasKey(const std::string& section, const std::string& key) const; std::vector getSections() const; std::vector> getKeys(const std::string& section) const; // Find the first section that is not "config" (the OS-specific section) std::string findOsSection() const; const std::string& getFilePath() const { return filePath; } bool isLoaded() const { return loaded; } private: struct Line { enum Type { BLANK, COMMENT, SECTION, KEY_VALUE }; Type type; std::string raw; std::string section; std::string key; std::string value; }; std::vector lines; std::string filePath; bool loaded; std::string rebuildLine(const Line& line) const; int findLine(const std::string& section, const std::string& key) const; int findSectionEnd(const std::string& section) const; };