diff --git a/MPF/UserControls/LogOutput.xaml.cs b/MPF/UserControls/LogOutput.xaml.cs index 43f6027e..8f2fce4d 100644 --- a/MPF/UserControls/LogOutput.xaml.cs +++ b/MPF/UserControls/LogOutput.xaml.cs @@ -25,7 +25,7 @@ namespace MPF.UserControls /// /// List of Matchers for progress tracking /// - private readonly List _matchers; + private readonly List _matchers; /// /// Cached value of the last line written @@ -52,7 +52,7 @@ namespace MPF.UserControls _document.Blocks.Add(_paragraph); Output.Document = _document; - _matchers = new List(); + _matchers = new List(); AddAaruMatchers(); AddDiscImageCreatorMatchers(); } @@ -374,13 +374,11 @@ namespace MPF.UserControls } else { - // Get all matching Matchers - var matches = _matchers.Where(m => m.Matches(ref text)); - if (matches.Any()) + // Get the first matching Matcher + var firstMatcher = _matchers.FirstOrDefault(m => m.HasValue && m.Value.Matches(ref text)); + if (firstMatcher.HasValue) { - // Use the first Matcher - var firstMatcher = matches.First(); - if (firstMatcher.Matches(ref lastLineText)) + if (firstMatcher.Value.Matches(ref lastLineText)) ReplaceLastLine(text, brush); else if (string.IsNullOrWhiteSpace(lastLineText)) ReplaceLastLine(text, brush); @@ -400,7 +398,7 @@ namespace MPF.UserControls } // Update the bar if needed - ProcessStringForProgressBar(text); + ProcessStringForProgressBar(text, lastUsedMatcher); // Cache the current text as the last line lastLineText = text; @@ -416,21 +414,12 @@ namespace MPF.UserControls /// Process text if it should update the progress bar /// /// Text to check and update with - private void ProcessStringForProgressBar(string text) + private void ProcessStringForProgressBar(string text, Matcher? matcher) { if (Application.Current.Dispatcher.CheckAccess()) - { - var matcher = _matchers.FirstOrDefault(m => m.Matches(ref text)); - matcher.Apply(ref text); - } + matcher?.Apply(ref text); else - { - Dispatcher.Invoke(() => - { - var matcher = _matchers.FirstOrDefault(m => m.Matches(ref text)); - matcher.Apply(ref text); - }); - } + Dispatcher.Invoke(() => { matcher?.Apply(ref text); }); } ///