From 342b96da224a38428f484bc6cc35c7e7bc23c97f Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 2 Jan 2018 20:28:30 +0400 Subject: [PATCH] (PlayFile): merged nested try blocks. --- GUI/MainWindow.xaml.cs | 66 ++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/GUI/MainWindow.xaml.cs b/GUI/MainWindow.xaml.cs index aae12bce..d2d17c06 100644 --- a/GUI/MainWindow.xaml.cs +++ b/GUI/MainWindow.xaml.cs @@ -965,48 +965,41 @@ namespace GARbro.GUI private void PlayFile (Entry entry) { + IBinaryStream input = null; SoundInput sound = null; try { SetBusyState(); - var input = VFS.OpenBinaryStream (entry); - try + input = VFS.OpenBinaryStream (entry); + FormatCatalog.Instance.LastError = null; + sound = AudioFormat.Read (input); + if (null == sound) { - FormatCatalog.Instance.LastError = null; - sound = AudioFormat.Read (input); - if (null == sound) - { - if (null != FormatCatalog.Instance.LastError) - throw FormatCatalog.Instance.LastError; - return; - } + if (null != FormatCatalog.Instance.LastError) + throw FormatCatalog.Instance.LastError; + return; + } - if (AudioDevice != null) - { - AudioDevice.PlaybackStopped -= OnPlaybackStopped; - AudioDevice = null; - } - CurrentAudio = new WaveStreamImpl (sound); - AudioDevice = new WaveOutEvent(); - // conversion to sample provider somehow removes crackling at the end of WAV sound clips. - if ("wav" == sound.SourceFormat || 8 == sound.Format.BitsPerSample) - AudioDevice.Init (CurrentAudio.ToSampleProvider()); - else - AudioDevice.Init (CurrentAudio); - AudioDevice.PlaybackStopped += OnPlaybackStopped; - AudioDevice.Play(); - appPlaybackControl.Visibility = Visibility.Visible; - var fmt = CurrentAudio.WaveFormat; - SetResourceText (string.Format (guiStrings.MsgPlaying, entry.Name, - fmt.SampleRate, sound.SourceBitrate / 1000, - CurrentAudio.TotalTime.ToString ("m':'ss"))); - input = null; - } - finally + if (AudioDevice != null) { - if (input != null) - input.Dispose(); + AudioDevice.PlaybackStopped -= OnPlaybackStopped; + AudioDevice = null; } + CurrentAudio = new WaveStreamImpl (sound); + AudioDevice = new WaveOutEvent(); + // conversion to sample provider somehow removes crackling at the end of WAV sound clips. + if ("wav" == sound.SourceFormat || 8 == sound.Format.BitsPerSample) + AudioDevice.Init (CurrentAudio.ToSampleProvider()); + else + AudioDevice.Init (CurrentAudio); + AudioDevice.PlaybackStopped += OnPlaybackStopped; + AudioDevice.Play(); + appPlaybackControl.Visibility = Visibility.Visible; + var fmt = CurrentAudio.WaveFormat; + SetResourceText (string.Format (guiStrings.MsgPlaying, entry.Name, + fmt.SampleRate, sound.SourceBitrate / 1000, + CurrentAudio.TotalTime.ToString ("m':'ss"))); + input = null; } catch (Exception X) { @@ -1014,6 +1007,11 @@ namespace GARbro.GUI if (null != sound) sound.Dispose(); } + finally + { + if (input != null) + input.Dispose(); + } } private void StopPlaybackExec (object sender, ExecutedRoutedEventArgs e)