From 2ba03a972479743ad77972ef9490d110d0a9199a Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 2 Aug 2023 05:25:16 -0400 Subject: [PATCH] force double parsing to parse using english format the database is pre-configured and can't use the culture of the user's pc --- DoomLauncher/Config/AppConfiguration.cs | 20 ++++++++++++++++---- DoomLauncher/Forms/MainForm_Config.cs | 7 +++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/DoomLauncher/Config/AppConfiguration.cs b/DoomLauncher/Config/AppConfiguration.cs index 97ae4984..b32bec76 100644 --- a/DoomLauncher/Config/AppConfiguration.cs +++ b/DoomLauncher/Config/AppConfiguration.cs @@ -2,6 +2,7 @@ using DoomLauncher.Interfaces; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Windows.Forms; @@ -10,6 +11,8 @@ namespace DoomLauncher { public class AppConfiguration { + public static readonly CultureInfo Culture = new CultureInfo("en-US"); + public event EventHandler GameFileViewTypeChanged; public event EventHandler VisibleViewsChanged; public event EventHandler ColorThemeChanged; @@ -114,9 +117,9 @@ private void Refresh(bool throwErrors) CleanTemp = Convert.ToBoolean(GetValue(config, "CleanTemp", "true")); SetChildDirectories(config); - SplitTopBottom = Convert.ToDouble(GetValue(config, SplitTopBottomName, "475")); - SplitLeftRight = Convert.ToDouble(GetValue(config, SplitLeftRightName, "680")); - SplitTagSelect = Convert.ToDouble(GetValue(config, SplitTagSelectName, "300")); + SplitTopBottom = TryGetDouble(config, SplitTopBottomName, 475); + SplitLeftRight = TryGetDouble(config, SplitLeftRightName, 680); + SplitTagSelect = TryGetDouble(config, SplitTagSelectName, 300); AppWidth = Convert.ToInt32(GetValue(config, AppWidthName, "1024")); AppHeight = Convert.ToInt32(GetValue(config, AppHeightName, "768")); AppX = Convert.ToInt32(GetValue(config, AppXName, "0")); @@ -173,6 +176,15 @@ private void Refresh(bool throwErrors) VerifyPaths(throwErrors); } + private static double TryGetDouble(IEnumerable config, string name, double defaultValue) + { + string value = GetValue(config, name, defaultValue.ToString(Culture)); + if (double.TryParse(value, NumberStyles.AllowDecimalPoint, Culture, out var doubleValue)) + return doubleValue; + + return defaultValue; + } + private static void AddEvent(List events, EventHandler eventAdd) { if (eventAdd != null) @@ -298,7 +310,7 @@ private void VerifyPath(LauncherPath path, bool throwErrors) public bool AutomaticallyPullTitlpic { get; set; } public bool ShowPlayDialog { get; set; } public bool ImportScreenshots { get; set; } - public HashSet VisibleViews { get; set; } + public HashSet VisibleViews { get; set; } = new HashSet(); public ColorThemeType ColorTheme { get; set; } } } diff --git a/DoomLauncher/Forms/MainForm_Config.cs b/DoomLauncher/Forms/MainForm_Config.cs index acc31957..1e68bf51 100644 --- a/DoomLauncher/Forms/MainForm_Config.cs +++ b/DoomLauncher/Forms/MainForm_Config.cs @@ -1,7 +1,6 @@ using DoomLauncher.Interfaces; using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Windows.Forms; @@ -19,11 +18,11 @@ private void HandleFormClosing() { // Too many problems when the form is minimized, not supported if (splitTopBottom.SplitterDistance > 0) - DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTopBottomName, GetSplitterPercent(splitTopBottom, Height).ToString(CultureInfo.InvariantCulture)); + DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTopBottomName, GetSplitterPercent(splitTopBottom, Height).ToString(AppConfiguration.Culture)); if (splitLeftRight.SplitterDistance > 0) - DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitLeftRightName, GetSplitterPercent(splitLeftRight, Width).ToString(CultureInfo.InvariantCulture)); + DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitLeftRightName, GetSplitterPercent(splitLeftRight, Width).ToString(AppConfiguration.Culture)); if (splitTagSelect.SplitterDistance > 0) - DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTagSelectName, GetSplitterPercent(splitTagSelect, Width).ToString(CultureInfo.InvariantCulture)); + DataCache.Instance.UpdateConfig(config, AppConfiguration.SplitTagSelectName, GetSplitterPercent(splitTagSelect, Width).ToString(AppConfiguration.Culture)); DataCache.Instance.UpdateConfig(config, AppConfiguration.AppWidthName, Size.Width.ToString()); DataCache.Instance.UpdateConfig(config, AppConfiguration.AppHeightName, Size.Height.ToString());