From 5d2993858946a4aecb172395daee47d8810e34a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Marchal?= Date: Mon, 16 Aug 2021 13:49:19 +0200 Subject: [PATCH] Fix exception and SaveSettings function --- MPDCtrl/Classes/Song.cs | 3 ++- Views/Settings.xaml.cs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MPDCtrl/Classes/Song.cs b/MPDCtrl/Classes/Song.cs index 5e1c447..d85d65e 100644 --- a/MPDCtrl/Classes/Song.cs +++ b/MPDCtrl/Classes/Song.cs @@ -87,7 +87,8 @@ namespace MPDCtrl.Models double dtime = double.NaN; try { - dtime = double.Parse(Time); + if (Time != "") + dtime = double.Parse(Time); } catch { } return dtime; diff --git a/Views/Settings.xaml.cs b/Views/Settings.xaml.cs index c3fc413..f8b1883 100644 --- a/Views/Settings.xaml.cs +++ b/Views/Settings.xaml.cs @@ -68,12 +68,8 @@ namespace unison private void MPDConnect_Clicked(object sender, RoutedEventArgs e) { - Properties.Settings.Default.mpd_host = MpdHost.Text; - Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text, CultureInfo.InvariantCulture); - Properties.Settings.Default.mpd_password = MpdPassword.Text; - Properties.Settings.Default.Save(); - - var mpd = (MPDHandler)Application.Current.Properties["mpd"]; + SaveSettings(); + MPDHandler mpd = (MPDHandler)Application.Current.Properties["mpd"]; mpd.Connect(); } @@ -83,10 +79,8 @@ namespace unison SnapcastPort.Text = defaultSnapcastPort; } - private void Window_Closing(object sender, CancelEventArgs e) + public void SaveSettings() { - e.Cancel = true; - Properties.Settings.Default.mpd_host = MpdHost.Text; Properties.Settings.Default.mpd_port = int.Parse(MpdPort.Text, CultureInfo.InvariantCulture); Properties.Settings.Default.mpd_password = MpdPassword.Text; @@ -94,7 +88,12 @@ namespace unison Properties.Settings.Default.snapcast_path = SnapcastPath.Text; Properties.Settings.Default.snapcast_port = int.Parse(SnapcastPort.Text, CultureInfo.InvariantCulture); Properties.Settings.Default.Save(); + } + private void Window_Closing(object sender, CancelEventArgs e) + { + e.Cancel = true; + SaveSettings(); WindowState = WindowState.Minimized; Hide(); }