Skip to content

Commit

Permalink
force double parsing to parse using english format
Browse files Browse the repository at this point in the history
the database is pre-configured and can't use the culture of the user's pc
  • Loading branch information
nstlaurent committed Aug 2, 2023
1 parent f9e3735 commit 2ba03a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 16 additions & 4 deletions DoomLauncher/Config/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -173,6 +176,15 @@ private void Refresh(bool throwErrors)
VerifyPaths(throwErrors);
}

private static double TryGetDouble(IEnumerable<IConfigurationData> 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<EventHandler> events, EventHandler eventAdd)
{
if (eventAdd != null)
Expand Down Expand Up @@ -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<string> VisibleViews { get; set; }
public HashSet<string> VisibleViews { get; set; } = new HashSet<string>();
public ColorThemeType ColorTheme { get; set; }
}
}
7 changes: 3 additions & 4 deletions DoomLauncher/Forms/MainForm_Config.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using DoomLauncher.Interfaces;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;

Expand All @@ -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());
Expand Down

0 comments on commit 2ba03a9

Please sign in to comment.