From afad96a52a57370325e70c680c3e4c5fa589d399 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 24 Feb 2023 00:22:01 +0100 Subject: [PATCH] Qt: try to fix QString::toDouble locale nonsense --- Utilities/Config.cpp | 8 ++++---- rpcs3/rpcs3qt/emu_settings.cpp | 22 ++++++++++++++-------- rpcs3/rpcs3qt/game_list_frame.cpp | 7 ++++++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Utilities/Config.cpp b/Utilities/Config.cpp index 4f0b0e31be..a66007b076 100644 --- a/Utilities/Config.cpp +++ b/Utilities/Config.cpp @@ -97,7 +97,7 @@ bool try_to_int64(s64* out, std::string_view value, s64 min, s64 max) if (result < min || result > max) { - if (out) cfg_log.error("cfg::try_to_int64('%s'): out of bounds (%d..%d)", value, min, max); + if (out) cfg_log.error("cfg::try_to_int64('%s'): out of bounds (val=%d, min=%d, max=%d)", value, result, min, max); return false; } @@ -140,7 +140,7 @@ bool try_to_uint64(u64* out, std::string_view value, u64 min, u64 max) if (result < min || result > max) { - if (out) cfg_log.error("cfg::try_to_uint64('%s'): out of bounds (%u..%u)", value, min, max); + if (out) cfg_log.error("cfg::try_to_uint64('%s'): out of bounds (val=%u, min=%u, max=%u)", value, result, min, max); return false; } @@ -176,7 +176,7 @@ bool try_to_float(f64* out, std::string_view value, f64 min, f64 max) if (result < min || result > max) { - if (out) cfg_log.error("cfg::try_to_float('%s'): out of bounds (%f..%f)", value, min, max); + if (out) cfg_log.error("cfg::try_to_float('%s'): out of bounds (val=%f, min=%f, max=%f)", value, result, min, max); return false; } @@ -231,7 +231,7 @@ bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string::format) f if (result > max) { - if (out) cfg_log.error("cfg::try_to_enum_value('%s'): out of bounds(0..%u)", value, max); + if (out) cfg_log.error("cfg::try_to_enum_value('%s'): out of bounds(val=%u, min=0, max=%u)", value, result, max); return false; } diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index 45e9aa9af1..3ebc6fdda5 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -675,21 +675,27 @@ void emu_settings::EnhanceDoubleSpinBox(QDoubleSpinBox* spinbox, emu_settings_ty } const QStringList range = GetSettingOptions(type); - bool ok_def, ok_sel, ok_min, ok_max; + const std::string def_s = GetSettingDefault(type); + const std::string val_s = GetSetting(type); + const std::string min_s = sstr(range.first()); + const std::string max_s = sstr(range.last()); - const double def = qstr(GetSettingDefault(type)).toDouble(&ok_def); - const double min = range.first().toDouble(&ok_min); - const double max = range.last().toDouble(&ok_max); + // cfg::_float range is in s32 + constexpr s32 min_value = ::std::numeric_limits::min(); + constexpr s32 max_value = ::std::numeric_limits::max(); + + f64 val, def, min, max; + const bool ok_sel = try_to_float(&val, val_s, min_value, max_value); + const bool ok_def = try_to_float(&def, def_s, min_value, max_value); + const bool ok_min = try_to_float(&min, min_s, min_value, max_value); + const bool ok_max = try_to_float(&max, max_s, min_value, max_value); if (!ok_def || !ok_min || !ok_max) { - cfg_log.fatal("EnhanceDoubleSpinBox '%s' was used with an invalid type", cfg_adapter::get_setting_name(type)); + cfg_log.fatal("EnhanceDoubleSpinBox '%s' was used with an invalid type. (val='%s', def='%s', min_s='%s', max_s='%s')", cfg_adapter::get_setting_name(type), val_s, def_s, min_s, max_s); return; } - const std::string selected = GetSetting(type); - double val = qstr(selected).toDouble(&ok_sel); - if (!ok_sel || val < min || val > max) { cfg_log.error("EnhanceDoubleSpinBox '%s' tried to set an invalid value: %f. Setting to default: %f. Allowed range: [%f, %f]", cfg_adapter::get_setting_name(type), val, def, min, max); diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index e7a6b7d2d7..b825367639 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -2646,9 +2646,14 @@ void game_list_frame::PopulateGameList() if (game->info.bootable && !game->compat.latest_version.isEmpty()) { + f64 top_ver = 0.0, app_ver = 0.0; + const bool unknown = app_version == localized.category.unknown; + const bool ok_app = !unknown && try_to_float(&app_ver, sstr(app_version), ::std::numeric_limits::min(), ::std::numeric_limits::max()); + const bool ok_top = !unknown && try_to_float(&top_ver, sstr(game->compat.latest_version), ::std::numeric_limits::min(), ::std::numeric_limits::max()); + // If the app is bootable and the compat database contains info about the latest patch version: // add a hint for available software updates if the app version is unknown or lower than the latest version. - if (app_version == localized.category.unknown || game->compat.latest_version.toDouble() > app_version.toDouble()) + if (unknown || (ok_top && ok_app && top_ver > app_ver)) { app_version = tr("%0 (Update available: %1)").arg(app_version, game->compat.latest_version); }