2020-08-19 05:07:55 +00:00
|
|
|
#include "settings.hpp"
|
2020-08-19 05:13:36 +00:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
2020-08-19 05:07:55 +00:00
|
|
|
|
|
|
|
SettingsManager::SettingsManager(std::string filename)
|
|
|
|
: m_filename(filename) {
|
2020-08-19 05:13:36 +00:00
|
|
|
if (!std::filesystem::exists(filename)) {
|
|
|
|
std::fstream fs;
|
|
|
|
fs.open(filename, std::ios::out);
|
|
|
|
fs.close();
|
|
|
|
}
|
|
|
|
|
2020-08-19 05:07:55 +00:00
|
|
|
auto rc = m_ini.LoadFile(filename.c_str());
|
|
|
|
m_ok = rc == SI_OK;
|
|
|
|
}
|
|
|
|
|
2020-12-18 07:05:24 +00:00
|
|
|
void SettingsManager::Reload() {
|
|
|
|
m_ok = m_ini.LoadFile(m_filename.c_str()) == SI_OK;
|
|
|
|
}
|
|
|
|
|
2020-11-03 06:52:19 +00:00
|
|
|
std::string SettingsManager::GetSettingString(const std::string §ion, const std::string &key, std::string fallback) const {
|
2020-08-19 05:07:55 +00:00
|
|
|
return m_ini.GetValue(section.c_str(), key.c_str(), fallback.c_str());
|
|
|
|
}
|
|
|
|
|
2020-11-03 06:52:19 +00:00
|
|
|
int SettingsManager::GetSettingInt(const std::string §ion, const std::string &key, int fallback) const {
|
2020-10-04 06:28:48 +00:00
|
|
|
return std::stoul(GetSettingString(section, key, std::to_string(fallback)));
|
2020-08-19 05:07:55 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 06:52:19 +00:00
|
|
|
bool SettingsManager::GetSettingBool(const std::string §ion, const std::string &key, bool fallback) const {
|
2020-11-09 01:52:29 +00:00
|
|
|
return GetSettingString(section, key, fallback ? "true" : "false") != "false";
|
2020-11-03 06:52:19 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 05:07:55 +00:00
|
|
|
bool SettingsManager::IsValid() const {
|
|
|
|
return m_ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsManager::Close() {
|
|
|
|
m_ini.SaveFile(m_filename.c_str());
|
|
|
|
}
|
2020-11-03 06:52:19 +00:00
|
|
|
|
2020-12-17 06:40:02 +00:00
|
|
|
bool SettingsManager::GetUseMemoryDB() const {
|
|
|
|
return GetSettingBool("discord", "memory_db", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SettingsManager::GetUserAgent() const {
|
|
|
|
return GetSettingString("http", "user_agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SettingsManager::GetDiscordToken() const {
|
|
|
|
return GetSettingString("discord", "token");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsManager::GetShowMemberListDiscriminators() const {
|
|
|
|
return GetSettingBool("gui", "member_list_discriminator", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SettingsManager::GetShowEmojis() const {
|
|
|
|
return GetSettingBool("gui", "emojis", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SettingsManager::GetLinkColor() const {
|
|
|
|
return GetSettingString("misc", "linkcolor", "rgba(40, 200, 180, 255)");
|
|
|
|
}
|
|
|
|
|
|
|
|
int SettingsManager::GetCacheHTTPConcurrency() const {
|
2021-02-11 23:03:16 +00:00
|
|
|
return GetSettingInt("http", "concurrent", 20);
|
2020-12-17 06:40:02 +00:00
|
|
|
}
|
2020-12-18 06:13:31 +00:00
|
|
|
|
|
|
|
bool SettingsManager::GetPrefetch() const {
|
|
|
|
return GetSettingBool("discord", "prefetch", false);
|
|
|
|
}
|
2020-12-18 07:05:24 +00:00
|
|
|
|
|
|
|
std::string SettingsManager::GetMainCSS() const {
|
|
|
|
return GetSettingString("gui", "css", "./css/main.css");
|
|
|
|
}
|
2020-12-22 00:08:44 +00:00
|
|
|
|
|
|
|
bool SettingsManager::GetShowAnimations() const {
|
|
|
|
return GetSettingBool("gui", "animations", true);
|
|
|
|
}
|
2021-03-04 05:02:37 +00:00
|
|
|
|
|
|
|
bool SettingsManager::GetShowOwnerCrown() const {
|
|
|
|
return GetSettingBool("gui", "owner_crown", true);
|
|
|
|
}
|