diff --git a/CHANGELIST.md b/CHANGELIST.md index 3d7f7e4f..b797cc20 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -21,6 +21,7 @@ - Remove EnableProgressProcessing - Remove EnableLogFormatting - Remove App references from LogViewModel +- Remove log formatting code ### 2.6.3 (2023-08-15) diff --git a/MPF/ViewModels/LogViewModel.cs b/MPF/ViewModels/LogViewModel.cs index d79947d7..f4038eca 100644 --- a/MPF/ViewModels/LogViewModel.cs +++ b/MPF/ViewModels/LogViewModel.cs @@ -40,21 +40,6 @@ namespace MPF.UI.ViewModels /// private readonly ProcessingQueue logQueue; - /// - /// List of Matchers for progress tracking - /// - private readonly List _matchers; - - /// - /// Cached value of the last matcher used - /// - private Matcher? lastUsedMatcher = null; - - /// - /// Regex pattern to find DiscImageCreator progress messages - /// - private const string DiscImageCreatorProgressPattern = @"\s*(\d+)\/\s*(\d+)$"; - #endregion /// @@ -79,183 +64,9 @@ namespace MPF.UI.ViewModels document.Blocks.Add(_paragraph); Parent.Output.Document = document; - // TODO: Can we dynamically add matchers *only* during dumping? - _matchers = new List(); - AddAaruMatchers(); - AddDiscImageCreatorMatchers(); - logQueue = new ProcessingQueue(ProcessLogLine); } - #region Matching - - /// - /// Matching wrapper - /// - private struct Matcher - { - private readonly string prefix; - private readonly Regex regex; - private readonly int start; - private readonly string progressBarText; - private readonly Action lambda; - - public Matcher(string prefix, string regex, string progressBarText, Action lambda) - { - this.prefix = prefix; - this.regex = new Regex(regex); - this.start = prefix.Length; - this.progressBarText = progressBarText; - this.lambda = lambda; - } - - /// - /// Check if the text matches the prefix - /// - /// Text to check - /// True if the line starts with the prefix, false otherwise - public bool Matches(string text) => text.StartsWith(prefix); - - /// - /// Generate a Match and apply the lambda - /// - /// Text to match and apply from - public void Apply(string text) - { - Match match = regex?.Match(text, start); - lambda?.Invoke(match, progressBarText); - } - } - - /// - /// Add all Matchers for Aaru - /// - private void AddAaruMatchers() - { - // TODO: Determine matchers that can be added - } - - /// - /// Add all Matchers for DiscImageCreator - /// - private void AddDiscImageCreatorMatchers() - { - #region Pre-dump Checking - - _matchers.Add(new Matcher( - "Checking EXE", - DiscImageCreatorProgressPattern, - "Checking executables...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Checking Pregap sync, msf, mode (LBA)", - @"\s*-(\d+)$", - "Checking Pregap sync, msf, mode", - (match, text) => - { - Parent.ProgressBar.Value = 0; - Parent.ProgressLabel.Text = text; - })); - - _matchers.Add(new Matcher( - "Checking SubQ adr (Track)", - DiscImageCreatorProgressPattern, - "Checking SubQ adr...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Checking SubQ ctl (Track)", - DiscImageCreatorProgressPattern, - "Checking SubQ ctl...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Checking SubRtoW (Track)", - DiscImageCreatorProgressPattern, - "Checking SubRtoW...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Reading DirectoryRecord", - DiscImageCreatorProgressPattern, - "Reading directory records...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Scanning sector for anti-mod string (LBA)", - DiscImageCreatorProgressPattern, - "Scanning sectors for anti-mod string...", - StandardDiscImageCreatorProgress - )); - - #endregion - - #region Dumping - - _matchers.Add(new Matcher( - @"Creating iso(LBA)", - DiscImageCreatorProgressPattern, - "Creating ISO...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - @"Creating .scm (LBA)", - DiscImageCreatorProgressPattern, - "Creating scrambled image...", - StandardDiscImageCreatorProgress - )); - - #endregion - - #region Post-Dump Processing - - _matchers.Add(new Matcher( - "Checking sectors:", - DiscImageCreatorProgressPattern, - "Checking for errors...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Creating bin (Track)", - DiscImageCreatorProgressPattern, - "Creating BIN(s)...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Creating cue and ccd (Track)", - DiscImageCreatorProgressPattern, - "Creating CUE and CCD...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Descrambling data sector of img:", - DiscImageCreatorProgressPattern, - "Descrambling image...", - StandardDiscImageCreatorProgress - )); - - _matchers.Add(new Matcher( - "Scanning sector (LBA)", - DiscImageCreatorProgressPattern, - "Scanning sectors for protection...", - StandardDiscImageCreatorProgress - )); - - #endregion - } - - #endregion - #region Logging /// @@ -427,29 +238,6 @@ namespace MPF.UI.ViewModels }); } - /// - /// Get the last line written to the log text box - /// - private Run GetLastLine() - { - return Parent.Dispatcher.Invoke(() => - { - if (!_paragraph.Inlines.Any()) - return null; - - return _paragraph.Inlines.LastInline as Run; - }); - } - - /// - /// Process text if it should update the progress bar - /// - /// Text to check and update with - private void ProcessStringForProgressBar(string text, Matcher? matcher) - { - Parent.Dispatcher.Invoke(() => { matcher?.Apply(text); }); - } - /// /// Replace the last line written to the log text box /// @@ -503,16 +291,6 @@ namespace MPF.UI.ViewModels private void OutputViewerSizeChanged(object sender, SizeChangedEventArgs e) => ScrollToBottom(); - private void StandardDiscImageCreatorProgress(Match match, string text) - { - if (uint.TryParse(match.Groups[1].Value, out uint current) && uint.TryParse(match.Groups[2].Value, out uint total)) - { - float percentProgress = (current / (float)total) * 100; - Parent.ProgressBar.Value = percentProgress; - Parent.ProgressLabel.Text = string.Format($"{text} ({percentProgress:N2}%)"); - } - } - #endregion } }