mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-11-02 07:08:31 +01:00
Make sure numerical settings parsing uses InvariantCulture
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace DesktopMagic.Api.Settings;
|
namespace DesktopMagic.Api.Settings;
|
||||||
|
|
||||||
@@ -64,12 +65,17 @@ public class IntegerUpDown : Setting
|
|||||||
|
|
||||||
internal override string GetJsonValue()
|
internal override string GetJsonValue()
|
||||||
{
|
{
|
||||||
return Value.ToString();
|
return Value.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetJsonValue(string value)
|
internal override void SetJsonValue(string value)
|
||||||
{
|
{
|
||||||
_ = int.TryParse(value, out int result);
|
// Values saved by older versions use the current culture (e.g. a culture specific minus sign), so fall back to it.
|
||||||
|
if (!int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int result))
|
||||||
|
{
|
||||||
|
_ = int.TryParse(value, NumberStyles.Integer, CultureInfo.CurrentCulture, out result);
|
||||||
|
}
|
||||||
|
|
||||||
Value = result;
|
Value = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace DesktopMagic.Api.Settings;
|
namespace DesktopMagic.Api.Settings;
|
||||||
|
|
||||||
@@ -65,12 +66,18 @@ public sealed class Slider : Setting
|
|||||||
|
|
||||||
internal override string GetJsonValue()
|
internal override string GetJsonValue()
|
||||||
{
|
{
|
||||||
return Value.ToString();
|
return Value.ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetJsonValue(string value)
|
internal override void SetJsonValue(string value)
|
||||||
{
|
{
|
||||||
_ = double.TryParse(value, out double result);
|
// Values saved by older versions use the current culture (e.g. "30,5"), so fall back to it.
|
||||||
|
// Thousands separators are not allowed, otherwise "30,5" would be read as 305 by the invariant culture.
|
||||||
|
if (!double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out double result))
|
||||||
|
{
|
||||||
|
_ = double.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out result);
|
||||||
|
}
|
||||||
|
|
||||||
Value = result;
|
Value = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user