From 39cced3fed90a4ca944b25674ef12001a3470713 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Sun, 10 Nov 2024 15:28:23 -0600 Subject: [PATCH 1/7] Instead of removing all DRV and MSG log lines, only redact sensitive information from them The debug file path, drive name, and .MakeMKV path are redacted from MSG 1004, 2003, and 3338. Additionally, the drive name and letter are redacted from DRV log entries, and the disc name is redacted from all unused drives. --- .../TheDiscDb.MakeMkv/MakeMkvHelper.cs | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs index 8e55352fb..d63b881d8 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs @@ -1,4 +1,6 @@ -namespace TheDiscDb.Tools.MakeMkv +using MakeMkv; + +namespace TheDiscDb.Tools.MakeMkv { using System; using System.Collections.Generic; @@ -42,7 +44,7 @@ public async Task WriteLogs(int driveIndex, string path, bool cleanLogs = true) await Task.Delay(200); // wait for file handle to be released try { - await CleanLogs(path); + await CleanLogs(driveIndex, path); } catch (IOException e) { @@ -51,19 +53,65 @@ public async Task WriteLogs(int driveIndex, string path, bool cleanLogs = true) } } - public async Task CleanLogs(string path, CancellationToken cancellationToken = default) + public async Task CleanLogs(int driveIndex, string path, CancellationToken cancellationToken = default) { var output = new List(); var lines = await this.fileSystem.File.ReadAllLines(path, cancellationToken); bool fileChanged = false; - foreach (var line in lines) + foreach (var originalLine in lines) { - if (string.IsNullOrWhiteSpace(line) || line.StartsWith("MSG") || line.StartsWith("DRV")) + // Remove empty lines from the output + if (originalLine == string.Empty) { fileChanged = true; continue; } + string? line = null; + if (originalLine.StartsWith("MSG")) + { + var msgLine = MessageLogLine.Parse(originalLine); + var (toRedact, replacement) = msgLine.Code switch + { + // The debug file path is usually in the user's home directory + "1004" => (msgLine.Params[0], "file::///redacted/by/ImportBuddy"), + // The drive name can sometimes contain a serial number + "2003" => (msgLine.Params[1], "redacted by ImportBuddy"), + // The .MakeMKV folder is usually in the user's home directory + "3338" => (msgLine.Params[1], "/redacted/by/ImportBuddy"), + // No other messages are known to contain sensitive information + _ => (null, ""), + }; + + if (toRedact is not null) + line = originalLine.Replace(toRedact, replacement); + } + else if (originalLine.StartsWith("DRV")) + { + // DRV:1,2,999,12,"BD-ROM HL-DT-ST BDDVDRW UH12NS30 1.03","42","E:" + // becomes + // DRV:1,2,999,12,"redacted by ImportBuddy","42","/redacted/by/ImportBuddy" + var driveLine = DriveScanLogLine.Parse(originalLine); + if (driveLine.DriveName is not null) + { + // Always redact the drive name, since it could contain a serial number + line = originalLine.Replace(driveLine.DriveName, "redacted by ImportBuddy"); + // Only keep the disc name for the active drive + if (driveLine.Index != driveIndex && !string.IsNullOrEmpty(driveLine.DiscName)) + line = line.Replace(driveLine.DiscName, "redacted by ImportBuddy"); + // Always redact the drive letter or path + if (!string.IsNullOrEmpty(driveLine.DriveLetter)) + line = line.Replace(driveLine.DriveLetter, "/redacted/by/ImportBuddy"); + } + } + + if (line is null) + // This line wasn't modified, use the original line + line = originalLine; + else + // Something was changed, ensure the file is overwritten + fileChanged = true; + output.Add(line); } From 76c358de3f3beffac929dd031328508f9e2a8c83 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Sun, 10 Nov 2024 18:27:38 -0600 Subject: [PATCH 2/7] Ensure the Linux appsettings file has the same case as the actual file Linux filesystems are typically case-sensitive, so having consistent case is necessary on most systems. --- tools/ImportBuddy/source/ImportBuddy/ImportBuddy/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ImportBuddy/source/ImportBuddy/ImportBuddy/Program.cs b/tools/ImportBuddy/source/ImportBuddy/ImportBuddy/Program.cs index 07e682249..be03c655c 100644 --- a/tools/ImportBuddy/source/ImportBuddy/ImportBuddy/Program.cs +++ b/tools/ImportBuddy/source/ImportBuddy/ImportBuddy/Program.cs @@ -48,7 +48,7 @@ static IHostBuilder CreateHostBuilder(string[] args) => config.AddJsonFile("appsettings.json", optional: false); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - config.AddJsonFile("appSettings.linux.json", optional: false); + config.AddJsonFile("appsettings.linux.json", optional: false); } }) .ConfigureLogging(logging => From 31d084a0dc81c947c3645ef3946a0e31b94b18c2 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Mon, 11 Nov 2024 00:52:49 -0600 Subject: [PATCH 3/7] Correctly parse MSG log entries containing a ',' (comma) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since previously MessageLogLine.Parse was doing a naïve string.Split on a comma, log entries that contained a comma in the template string or in an argument got broken down incorrectly. Borrowed from a similar project, CsvEnumerator correctly keeps quoted strings together, only splitting outside of such a string. This may also be helpful in other log parsers in ImportBuddy. --- .../LogParser/CsvEnumerator.cs | 77 +++++++++++++++++++ .../LogParser/LogLines/LogLine.cs | 62 ++++++++++++++- .../LogParser/LogLines/MessageLogLine.cs | 22 ++---- 3 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs new file mode 100644 index 000000000..79a816cb3 --- /dev/null +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs @@ -0,0 +1,77 @@ +namespace MakeMkv; + +/// +/// Iterates over comma separated values in a single line of text. +/// +public sealed class CsvEnumerator +{ + private readonly String _span; + + private readonly Boolean _isInitialized; + + private Int32 _currentStart; + private Int32 _currentEnd; + + /// + public ReadOnlySpan Current => _span.AsSpan()[_currentStart.._currentEnd]; + + /// + /// Creates a new over a span of characters. + /// + public CsvEnumerator(String span) + { + _isInitialized = true; + _span = span; + _currentStart = 0; + _currentEnd = -1; + } + + /// + public Boolean MoveNext() + { + Int32 start = _currentEnd + 1; + if (!_isInitialized || start > _span.Length) + return false; + + var slice = _span[start..]; + _currentStart = start; + + Boolean quoted = false; + Boolean escaped = false; + Int32 i; + for (i = 0; i < slice.Length; i++) + { + Char curChar = slice[i]; + if (curChar == '\\') + { + if (!escaped) + { + escaped = true; + continue; + } + } + else if (curChar == '"') + { + if (!escaped) + quoted = !quoted; + } + else if (curChar == ',') + { + if (!quoted) + break; + } + + escaped = false; + } + + Int32 elementLength = i; + + _currentEnd = _currentStart + elementLength; + return true; + } + + /// + /// Returns an enumerator suitable for use in foreach loops. + /// + public CsvEnumerator GetEnumerator() => this; +} diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs index c9fc38904..38184c4cf 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs @@ -28,7 +28,7 @@ protected static int TryParseInt(int index, string[] parts) { if (index < parts.Length) { - if(Int32.TryParse(parts[index], out int val)) + if (Int32.TryParse(parts[index], out int val)) { return val; } @@ -37,6 +37,19 @@ protected static int TryParseInt(int index, string[] parts) return default(int); } + protected static int TryParseInt(CsvEnumerator enumerator) + { + if (enumerator.MoveNext()) + { + if (Int32.TryParse(enumerator.Current, out int val)) + { + return val; + } + } + + return default; + } + protected static bool TryParseBoolean(int index, string[] parts) { if (index < parts.Length) @@ -50,6 +63,19 @@ protected static bool TryParseBoolean(int index, string[] parts) return default(bool); } + protected static bool TryParseBoolean(CsvEnumerator enumerator) + { + if (enumerator.MoveNext()) + { + if (Int32.TryParse(enumerator.Current, out int val)) + { + return val != 256 && val != 999 && val > 0; + } + } + + return default; + } + protected static string? GetString(int index, string[] parts) { if (index < parts.Length) @@ -60,6 +86,14 @@ protected static bool TryParseBoolean(int index, string[] parts) return default; } + protected static string? GetString(CsvEnumerator enumerator) + { + if (enumerator.MoveNext()) + return enumerator.Current.ToString().Replace("\"", string.Empty); + + return default; + } + protected static DateTime TryParseDateTime(int index, string[] parts) { if (index < parts.Length) @@ -73,6 +107,19 @@ protected static DateTime TryParseDateTime(int index, string[] parts) return default(DateTime); } + protected static DateTime TryParseDateTime(CsvEnumerator enumerator) + { + if (enumerator.MoveNext()) + { + if (DateTime.TryParse(enumerator.Current, out DateTime val)) + { + return val; + } + } + + return default; + } + protected static long TryParseLong(int index, string[] parts) { if (index < parts.Length) @@ -85,5 +132,18 @@ protected static long TryParseLong(int index, string[] parts) return default(long); } + + protected static long TryParseLong(CsvEnumerator enumerator) + { + if (enumerator.MoveNext()) + { + if (Int64.TryParse(enumerator.Current, out long val)) + { + return val; + } + } + + return default; + } } } diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs index ca89011c9..a360fe8fa 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs @@ -18,26 +18,20 @@ public MessageLogLine() : base("MSG") public static MessageLogLine Parse(string line) { - string[] parts = line.Substring(4).Split(','); + var enumerator = new CsvEnumerator(line[4..]); var result = new MessageLogLine { - Code = GetString(0, parts), - Flags = GetString(1, parts), - ParamCount = TryParseInt(2, parts), - Message = GetString(3, parts), - MessageTemplate = GetString(4, parts), + Code = GetString(enumerator), + Flags = GetString(enumerator), + ParamCount = TryParseInt(enumerator), + Message = GetString(enumerator), + MessageTemplate = GetString(enumerator), OriginalLine = line }; - for (int i = 5; i < parts.Length; i++) - { - string? val = GetString(i, parts); - if (val != null) - { - result.Params.Add(val); - } - } + while (GetString(enumerator) is {} val) + result.Params.Add(val); return result; } From fdede1cac64af302ce9863f6a14098d93fafb953 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Mon, 11 Nov 2024 00:59:52 -0600 Subject: [PATCH 4/7] Fix exception when reading an empty drive name --- .../source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs index d63b881d8..695733007 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs @@ -92,7 +92,7 @@ public async Task CleanLogs(int driveIndex, string path, CancellationToken cance // becomes // DRV:1,2,999,12,"redacted by ImportBuddy","42","/redacted/by/ImportBuddy" var driveLine = DriveScanLogLine.Parse(originalLine); - if (driveLine.DriveName is not null) + if (!string.IsNullOrEmpty(driveLine.DriveName)) { // Always redact the drive name, since it could contain a serial number line = originalLine.Replace(driveLine.DriveName, "redacted by ImportBuddy"); From 88c57fe7ddca3d1e4ea4630bdab0b6f1e08df802 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 12 Nov 2024 23:44:59 -0600 Subject: [PATCH 5/7] Move and document TryParse methods for CsvEnumerator --- .../LogParser/CsvEnumerator.cs | 82 +++++++++++++++++++ .../LogParser/LogLines/LogLine.cs | 60 -------------- .../LogParser/LogLines/MessageLogLine.cs | 12 +-- 3 files changed, 88 insertions(+), 66 deletions(-) diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs index 79a816cb3..68c6cd1ea 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs @@ -74,4 +74,86 @@ public Boolean MoveNext() /// Returns an enumerator suitable for use in foreach loops. /// public CsvEnumerator GetEnumerator() => this; + + /// + /// Attempts to advance the enumerator and parse the value as an . + /// + /// The parsed value, or the value if enumeration or parsing failed. + public int TryParseInt() + { + if (MoveNext()) + { + if (Int32.TryParse(Current, out int val)) + { + return val; + } + } + + return default; + } + + /// + /// Attempts to advance the enumerator and parse the value as a . + /// + /// The parsed value, or if enumeration or parsing failed. + public bool TryParseBoolean() + { + if (MoveNext()) + { + if (Int32.TryParse(Current, out int val)) + { + return val != 256 && val != 999 && val > 0; + } + } + + return default; + } + + /// + /// Attempts to advance the enumerator and parse the value as a . + /// + /// The parsed value, or if enumeration or parsing failed. + public string? GetString() + { + if (MoveNext()) + { + return Current.ToString().Replace("\"", string.Empty); + } + + return default; + } + + /// + /// Attempts to advance the enumerator and parse the value as a . + /// + /// The parsed value, or the value if enumeration or parsing failed. + public DateTime TryParseDateTime() + { + if (MoveNext()) + { + if (DateTime.TryParse(Current, out DateTime val)) + { + return val; + } + } + + return default; + } + + /// + /// Attempts to advance the enumerator and parse the value as a . + /// + /// The parsed value, or the value if enumeration or parsing failed. + public long TryParseLong() + { + if (MoveNext()) + { + if (Int64.TryParse(Current, out long val)) + { + return val; + } + } + + return default; + } } diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs index 38184c4cf..f2499e1bf 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/LogLine.cs @@ -37,19 +37,6 @@ protected static int TryParseInt(int index, string[] parts) return default(int); } - protected static int TryParseInt(CsvEnumerator enumerator) - { - if (enumerator.MoveNext()) - { - if (Int32.TryParse(enumerator.Current, out int val)) - { - return val; - } - } - - return default; - } - protected static bool TryParseBoolean(int index, string[] parts) { if (index < parts.Length) @@ -63,19 +50,6 @@ protected static bool TryParseBoolean(int index, string[] parts) return default(bool); } - protected static bool TryParseBoolean(CsvEnumerator enumerator) - { - if (enumerator.MoveNext()) - { - if (Int32.TryParse(enumerator.Current, out int val)) - { - return val != 256 && val != 999 && val > 0; - } - } - - return default; - } - protected static string? GetString(int index, string[] parts) { if (index < parts.Length) @@ -86,14 +60,6 @@ protected static bool TryParseBoolean(CsvEnumerator enumerator) return default; } - protected static string? GetString(CsvEnumerator enumerator) - { - if (enumerator.MoveNext()) - return enumerator.Current.ToString().Replace("\"", string.Empty); - - return default; - } - protected static DateTime TryParseDateTime(int index, string[] parts) { if (index < parts.Length) @@ -107,19 +73,6 @@ protected static DateTime TryParseDateTime(int index, string[] parts) return default(DateTime); } - protected static DateTime TryParseDateTime(CsvEnumerator enumerator) - { - if (enumerator.MoveNext()) - { - if (DateTime.TryParse(enumerator.Current, out DateTime val)) - { - return val; - } - } - - return default; - } - protected static long TryParseLong(int index, string[] parts) { if (index < parts.Length) @@ -132,18 +85,5 @@ protected static long TryParseLong(int index, string[] parts) return default(long); } - - protected static long TryParseLong(CsvEnumerator enumerator) - { - if (enumerator.MoveNext()) - { - if (Int64.TryParse(enumerator.Current, out long val)) - { - return val; - } - } - - return default; - } } } diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs index a360fe8fa..401f3a7b3 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs @@ -22,15 +22,15 @@ public static MessageLogLine Parse(string line) var result = new MessageLogLine { - Code = GetString(enumerator), - Flags = GetString(enumerator), - ParamCount = TryParseInt(enumerator), - Message = GetString(enumerator), - MessageTemplate = GetString(enumerator), + Code = enumerator.GetString(), + Flags = enumerator.GetString(), + ParamCount = enumerator.TryParseInt(), + Message = enumerator.GetString(), + MessageTemplate = enumerator.GetString(), OriginalLine = line }; - while (GetString(enumerator) is {} val) + while (enumerator.GetString() is { } val) result.Params.Add(val); return result; From adb50e30048d4f8fdb82404ef65b47a43ee489c2 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 12 Nov 2024 23:46:02 -0600 Subject: [PATCH 6/7] Redact messages with "***" --- .../ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs index 695733007..6896686af 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs @@ -74,11 +74,11 @@ public async Task CleanLogs(int driveIndex, string path, CancellationToken cance var (toRedact, replacement) = msgLine.Code switch { // The debug file path is usually in the user's home directory - "1004" => (msgLine.Params[0], "file::///redacted/by/ImportBuddy"), + "1004" => (msgLine.Params[0], "***"), // The drive name can sometimes contain a serial number - "2003" => (msgLine.Params[1], "redacted by ImportBuddy"), + "2003" => (msgLine.Params[1], "***"), // The .MakeMKV folder is usually in the user's home directory - "3338" => (msgLine.Params[1], "/redacted/by/ImportBuddy"), + "3338" => (msgLine.Params[1], "***"), // No other messages are known to contain sensitive information _ => (null, ""), }; @@ -95,13 +95,13 @@ public async Task CleanLogs(int driveIndex, string path, CancellationToken cance if (!string.IsNullOrEmpty(driveLine.DriveName)) { // Always redact the drive name, since it could contain a serial number - line = originalLine.Replace(driveLine.DriveName, "redacted by ImportBuddy"); + line = originalLine.Replace(driveLine.DriveName, "***"); // Only keep the disc name for the active drive if (driveLine.Index != driveIndex && !string.IsNullOrEmpty(driveLine.DiscName)) - line = line.Replace(driveLine.DiscName, "redacted by ImportBuddy"); + line = line.Replace(driveLine.DiscName, "***"); // Always redact the drive letter or path if (!string.IsNullOrEmpty(driveLine.DriveLetter)) - line = line.Replace(driveLine.DriveLetter, "/redacted/by/ImportBuddy"); + line = line.Replace(driveLine.DriveLetter, "***"); } } From e927144d2cb2e4da3e303154fc45aa5bf4aa5096 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 12 Nov 2024 23:47:59 -0600 Subject: [PATCH 7/7] Add braces to if and while statements --- .../TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs | 6 ++++++ .../LogParser/LogLines/MessageLogLine.cs | 2 ++ .../ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs index 68c6cd1ea..2bd989964 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/CsvEnumerator.cs @@ -31,7 +31,9 @@ public Boolean MoveNext() { Int32 start = _currentEnd + 1; if (!_isInitialized || start > _span.Length) + { return false; + } var slice = _span[start..]; _currentStart = start; @@ -53,12 +55,16 @@ public Boolean MoveNext() else if (curChar == '"') { if (!escaped) + { quoted = !quoted; + } } else if (curChar == ',') { if (!quoted) + { break; + } } escaped = false; diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs index 401f3a7b3..41d38a5b6 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/LogParser/LogLines/MessageLogLine.cs @@ -31,7 +31,9 @@ public static MessageLogLine Parse(string line) }; while (enumerator.GetString() is { } val) + { result.Params.Add(val); + } return result; } diff --git a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs index 6896686af..42d7b8d1a 100644 --- a/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs +++ b/tools/ImportBuddy/source/ImportBuddy/TheDiscDb.MakeMkv/MakeMkvHelper.cs @@ -84,7 +84,9 @@ public async Task CleanLogs(int driveIndex, string path, CancellationToken cance }; if (toRedact is not null) + { line = originalLine.Replace(toRedact, replacement); + } } else if (originalLine.StartsWith("DRV")) { @@ -96,21 +98,31 @@ public async Task CleanLogs(int driveIndex, string path, CancellationToken cance { // Always redact the drive name, since it could contain a serial number line = originalLine.Replace(driveLine.DriveName, "***"); + // Only keep the disc name for the active drive if (driveLine.Index != driveIndex && !string.IsNullOrEmpty(driveLine.DiscName)) + { line = line.Replace(driveLine.DiscName, "***"); + } + // Always redact the drive letter or path if (!string.IsNullOrEmpty(driveLine.DriveLetter)) + { line = line.Replace(driveLine.DriveLetter, "***"); + } } } if (line is null) + { // This line wasn't modified, use the original line line = originalLine; + } else + { // Something was changed, ensure the file is overwritten fileChanged = true; + } output.Add(line); }