From d8f380961e2c7165ba296c246e002d16598942d4 Mon Sep 17 00:00:00 2001 From: t895 Date: Tue, 21 Nov 2023 20:46:27 -0500 Subject: frontend_common: Add option to read unsigned integers --- src/frontend_common/config.cpp | 29 ++++++++++++++++++++++++++++- src/frontend_common/config.h | 4 ++++ src/yuzu/configuration/qt_config.cpp | 3 ++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp index 40a44ae12..a68a9cb4b 100644 --- a/src/frontend_common/config.cpp +++ b/src/frontend_common/config.cpp @@ -284,7 +284,7 @@ void Config::ReadDisabledAddOnValues() { const int size = BeginArray(std::string("")); for (int i = 0; i < size; ++i) { SetArrayIndex(i); - const auto title_id = ReadIntegerSetting(std::string("title_id"), 0); + const auto title_id = ReadUnsignedIntegerSetting(std::string("title_id"), 0); std::vector out; const int d_size = BeginArray("disabled"); for (int j = 0; j < d_size; ++j) { @@ -664,6 +664,33 @@ s64 Config::ReadIntegerSetting(const std::string& key, const std::optional return result; } +u64 Config::ReadUnsignedIntegerSetting(const std::string& key, + const std::optional default_value) { + std::string full_key = GetFullKey(key, false); + if (!default_value.has_value()) { + try { + return std::stoull( + std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), "0"))); + } catch (...) { + return 0; + } + } + + u64 result = 0; + if (config->GetBoolValue(GetSection().c_str(), + std::string(full_key).append("\\default").c_str(), true)) { + result = default_value.value(); + } else { + try { + result = std::stoull(std::string(config->GetValue( + GetSection().c_str(), full_key.c_str(), ToString(default_value.value()).c_str()))); + } catch (...) { + result = default_value.value(); + } + } + return result; +} + double Config::ReadDoubleSetting(const std::string& key, const std::optional default_value) { std::string full_key = GetFullKey(key, false); diff --git a/src/frontend_common/config.h b/src/frontend_common/config.h index f741aa8bb..20a1a8056 100644 --- a/src/frontend_common/config.h +++ b/src/frontend_common/config.h @@ -137,6 +137,8 @@ protected: bool ReadBooleanSetting(const std::string& key, std::optional default_value = std::nullopt); s64 ReadIntegerSetting(const std::string& key, std::optional default_value = std::nullopt); + u64 ReadUnsignedIntegerSetting(const std::string& key, + std::optional default_value = std::nullopt); double ReadDoubleSetting(const std::string& key, std::optional default_value = std::nullopt); std::string ReadStringSetting(const std::string& key, @@ -170,6 +172,8 @@ protected: return value_.has_value() ? std::to_string(*value_) : "none"; } else if constexpr (std::is_same_v) { return value_ ? "true" : "false"; + } else if constexpr (std::is_same_v) { + return std::to_string(static_cast(value_)); } else { return std::to_string(static_cast(value_)); } diff --git a/src/yuzu/configuration/qt_config.cpp b/src/yuzu/configuration/qt_config.cpp index 82402ec70..5a8e69aa9 100644 --- a/src/yuzu/configuration/qt_config.cpp +++ b/src/yuzu/configuration/qt_config.cpp @@ -283,7 +283,8 @@ void QtConfig::ReadUIGamelistValues() { const int favorites_size = BeginArray("favorites"); for (int i = 0; i < favorites_size; i++) { SetArrayIndex(i); - UISettings::values.favorited_ids.append(ReadIntegerSetting(std::string("program_id"))); + UISettings::values.favorited_ids.append( + ReadUnsignedIntegerSetting(std::string("program_id"))); } EndArray(); -- cgit v1.2.3