diff options
| author | 2023-11-21 20:46:27 -0500 | |
|---|---|---|
| committer | 2023-11-21 21:01:46 -0500 | |
| commit | d8f380961e2c7165ba296c246e002d16598942d4 (patch) | |
| tree | dc89bc0bdf1fd0b11c5b90f9f9033039210a8d1d /src/frontend_common/config.cpp | |
| parent | frontend_common: Set config array size to 0 if the array is ended without cha... (diff) | |
| download | yuzu-d8f380961e2c7165ba296c246e002d16598942d4.tar.gz yuzu-d8f380961e2c7165ba296c246e002d16598942d4.tar.xz yuzu-d8f380961e2c7165ba296c246e002d16598942d4.zip | |
frontend_common: Add option to read unsigned integers
Diffstat (limited to 'src/frontend_common/config.cpp')
| -rw-r--r-- | src/frontend_common/config.cpp | 29 |
1 files changed, 28 insertions, 1 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() { | |||
| 284 | const int size = BeginArray(std::string("")); | 284 | const int size = BeginArray(std::string("")); |
| 285 | for (int i = 0; i < size; ++i) { | 285 | for (int i = 0; i < size; ++i) { |
| 286 | SetArrayIndex(i); | 286 | SetArrayIndex(i); |
| 287 | const auto title_id = ReadIntegerSetting(std::string("title_id"), 0); | 287 | const auto title_id = ReadUnsignedIntegerSetting(std::string("title_id"), 0); |
| 288 | std::vector<std::string> out; | 288 | std::vector<std::string> out; |
| 289 | const int d_size = BeginArray("disabled"); | 289 | const int d_size = BeginArray("disabled"); |
| 290 | for (int j = 0; j < d_size; ++j) { | 290 | for (int j = 0; j < d_size; ++j) { |
| @@ -664,6 +664,33 @@ s64 Config::ReadIntegerSetting(const std::string& key, const std::optional<s64> | |||
| 664 | return result; | 664 | return result; |
| 665 | } | 665 | } |
| 666 | 666 | ||
| 667 | u64 Config::ReadUnsignedIntegerSetting(const std::string& key, | ||
| 668 | const std::optional<u64> default_value) { | ||
| 669 | std::string full_key = GetFullKey(key, false); | ||
| 670 | if (!default_value.has_value()) { | ||
| 671 | try { | ||
| 672 | return std::stoull( | ||
| 673 | std::string(config->GetValue(GetSection().c_str(), full_key.c_str(), "0"))); | ||
| 674 | } catch (...) { | ||
| 675 | return 0; | ||
| 676 | } | ||
| 677 | } | ||
| 678 | |||
| 679 | u64 result = 0; | ||
| 680 | if (config->GetBoolValue(GetSection().c_str(), | ||
| 681 | std::string(full_key).append("\\default").c_str(), true)) { | ||
| 682 | result = default_value.value(); | ||
| 683 | } else { | ||
| 684 | try { | ||
| 685 | result = std::stoull(std::string(config->GetValue( | ||
| 686 | GetSection().c_str(), full_key.c_str(), ToString(default_value.value()).c_str()))); | ||
| 687 | } catch (...) { | ||
| 688 | result = default_value.value(); | ||
| 689 | } | ||
| 690 | } | ||
| 691 | return result; | ||
| 692 | } | ||
| 693 | |||
| 667 | double Config::ReadDoubleSetting(const std::string& key, | 694 | double Config::ReadDoubleSetting(const std::string& key, |
| 668 | const std::optional<double> default_value) { | 695 | const std::optional<double> default_value) { |
| 669 | std::string full_key = GetFullKey(key, false); | 696 | std::string full_key = GetFullKey(key, false); |