add more info boxes to options, merge option.cpp changes from totalsms.
This commit is contained in:
@@ -34,16 +34,21 @@ bool getbool(const char* LocalBuffer, bool def) {
|
||||
template<typename T>
|
||||
auto OptionBase<T>::GetInternal(const char* name) -> T {
|
||||
if (!m_value.has_value()) {
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
m_value = ini_getbool(m_section.c_str(), name, m_default_value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
m_value = ini_getl(m_section.c_str(), name, m_default_value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, std::string>) {
|
||||
char buf[FS_MAX_PATH];
|
||||
ini_gets(m_section.c_str(), name, m_default_value.c_str(), buf, sizeof(buf), App::CONFIG_PATH);
|
||||
m_value = buf;
|
||||
if (m_file) {
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
m_value = ini_getbool(m_section.c_str(), name, m_default_value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
m_value = ini_getl(m_section.c_str(), name, m_default_value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, std::string>) {
|
||||
char buf[FS_MAX_PATH];
|
||||
ini_gets(m_section.c_str(), name, m_default_value.c_str(), buf, sizeof(buf), App::CONFIG_PATH);
|
||||
m_value = buf;
|
||||
}
|
||||
} else {
|
||||
m_value = m_default_value;
|
||||
}
|
||||
}
|
||||
|
||||
return m_value.value();
|
||||
}
|
||||
|
||||
@@ -54,7 +59,7 @@ auto OptionBase<T>::Get() -> T {
|
||||
|
||||
template<typename T>
|
||||
auto OptionBase<T>::GetOr(const char* name) -> T {
|
||||
if (ini_haskey(m_section.c_str(), m_name.c_str(), App::CONFIG_PATH)) {
|
||||
if (m_file && ini_haskey(m_section.c_str(), m_name.c_str(), App::CONFIG_PATH)) {
|
||||
return Get();
|
||||
} else {
|
||||
return GetInternal(name);
|
||||
@@ -64,12 +69,14 @@ auto OptionBase<T>::GetOr(const char* name) -> T {
|
||||
template<typename T>
|
||||
void OptionBase<T>::Set(T value) {
|
||||
m_value = value;
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
ini_putl(m_section.c_str(), m_name.c_str(), value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
ini_putl(m_section.c_str(), m_name.c_str(), value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, std::string>) {
|
||||
ini_puts(m_section.c_str(), m_name.c_str(), value.c_str(), App::CONFIG_PATH);
|
||||
if (m_file) {
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
ini_putl(m_section.c_str(), m_name.c_str(), value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
ini_putl(m_section.c_str(), m_name.c_str(), value, App::CONFIG_PATH);
|
||||
} else if constexpr(std::is_same_v<T, std::string>) {
|
||||
ini_puts(m_section.c_str(), m_name.c_str(), value.c_str(), App::CONFIG_PATH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +88,14 @@ auto OptionBase<T>::LoadFrom(const char* section, const char* name, const char*
|
||||
template<typename T>
|
||||
auto OptionBase<T>::LoadFrom(const char* name, const char* value) -> bool {
|
||||
if (m_name == name) {
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
m_value = getbool(value, m_default_value);
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
m_value = getl(value, m_default_value);
|
||||
} else if constexpr(std::is_same_v<T, std::string>) {
|
||||
m_value = value;
|
||||
if (m_file) {
|
||||
if constexpr(std::is_same_v<T, bool>) {
|
||||
m_value = getbool(value, m_default_value);
|
||||
} else if constexpr(std::is_same_v<T, long>) {
|
||||
m_value = getl(value, m_default_value);
|
||||
} else if constexpr(std::is_same_v<T, std::string>) {
|
||||
m_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user