Initial commit

This commit is contained in:
Niklas080208
2026-02-11 20:33:01 +01:00
commit 617265f004
145 changed files with 45252 additions and 0 deletions

64
src/ini_handler.h Normal file
View File

@@ -0,0 +1,64 @@
/*
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 <string>
#include <vector>
#include <map>
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<std::string> getSections() const;
std::vector<std::pair<std::string, std::string>> 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<Line> 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;
};