Lion Kortlepel ad414ec5c9
call onInit on hot-reload, cleanup, remove warnings
onInit is now called on hot-reload, for the whole plugin. Arguably, this
is not expected behavior, since only one file is being reloaded, but
this is the easiest way to do it, and the entire hot-reload process is
only for development purposes. Open an issue if this breaks your stuff
:^)
2022-07-14 00:37:47 +02:00

34 lines
959 B
C++

#pragma once
#include "Common.h"
#include <atomic>
#include <filesystem>
#define TOML11_PRESERVE_COMMENTS_BY_DEFAULT
#include <toml11/toml.hpp> // header-only version of TOML++
namespace fs = std::filesystem;
class TConfig {
public:
explicit TConfig(const std::string& ConfigFileName);
[[nodiscard]] bool Failed() const { return mFailed; }
void FlushToFile();
private:
void CreateConfigFile();
void ParseFromFile(std::string_view name);
void PrintDebug();
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, std::string& OutValue);
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, bool& OutValue);
void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, int& OutValue);
void ParseOldFormat();
bool IsDefault();
bool mFailed { false };
std::string mConfigFileName;
};