summaryrefslogtreecommitdiff
path: root/settings.hpp
blob: e2374b525dbff7372b65c0ff707a3bac33a00246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <string>
#include <type_traits>
#include <SimpleIni.h>

class SettingsManager {
public:
    SettingsManager(std::string filename);
    void Reload();

    void Close();
    bool GetUseMemoryDB() const;
    std::string GetUserAgent() const;
    std::string GetDiscordToken() const;
    bool GetShowMemberListDiscriminators() const;
    bool GetShowStockEmojis() const;
    bool GetShowCustomEmojis() const;
    std::string GetLinkColor() const;
    int GetCacheHTTPConcurrency() const;
    bool GetPrefetch() const;
    std::string GetMainCSS() const;
    bool GetShowAnimations() const;
    bool GetShowOwnerCrown() const;

    bool IsValid() const;

    template<typename T>
    void SetSetting(std::string section, std::string key, T value) {
        m_ini.SetValue(section.c_str(), key.c_str(), std::to_string(value).c_str());
        m_ini.SaveFile(m_filename.c_str());
    }

    void SetSetting(std::string section, std::string key, std::string value) {
        m_ini.SetValue(section.c_str(), key.c_str(), value.c_str());
        m_ini.SaveFile(m_filename.c_str());
    }

private:
    std::string GetSettingString(const std::string &section, const std::string &key, std::string fallback = "") const;
    int GetSettingInt(const std::string &section, const std::string &key, int fallback) const;
    bool GetSettingBool(const std::string &section, const std::string &key, bool fallback) const;

private:
    bool m_ok;
    std::string m_filename;
    CSimpleIniA m_ini;
};