From 34e706334f0b57e1133923354a877b855311e198 Mon Sep 17 00:00:00 2001 From: indep-arg <333053532+indep-arg@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:52:47 -0300 Subject: [PATCH 1/4] Write a BOM to exported CSV files Excel opens a CSV without a BOM using the ANSI code page, so provider and device names with non-ASCII characters (Cyrillic, CJK, accents) show up garbled. Starting the file with a UTF-8 BOM makes Excel detect the encoding; other CSV readers ignore it. --- Rapr/CSVExporter.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rapr/CSVExporter.cs b/Rapr/CSVExporter.cs index 2bed2cbb..f394da09 100644 --- a/Rapr/CSVExporter.cs +++ b/Rapr/CSVExporter.cs @@ -36,7 +36,9 @@ public string Export(List driverStoreEntries) string csvFileName = saveFileDialog.FileName; using (FileStream fileStream = new FileStream(csvFileName, FileMode.Create)) - using (StreamWriter fileWriter = new StreamWriter(fileStream, new UTF8Encoding(false))) + // Excel only reads the file as UTF-8 when it starts with a BOM; without it, + // non-ASCII provider and device names are garbled. + using (StreamWriter fileWriter = new StreamWriter(fileStream, new UTF8Encoding(true))) { // Write the header once string headerLine = string.Join(csvDelimiter, Sanitize(DriverStoreEntry.GetFieldNames(), csvDelimiter)); From b01a1c459191dd1674509498213dbc9f8c62c6e7 Mon Sep 17 00:00:00 2001 From: indep-arg <333053532+indep-arg@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:53:32 -0300 Subject: [PATCH 2/4] Export Boot Critical, Extension Id and Driver Files to CSV These columns can be shown in the list but were missing from the CSV. They are added at the end so existing column positions don't change. --- Rapr/Utils/DriverStoreEntry.cs | 6 ++++++ RaprTests/DriverStoreEntryTests.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Rapr/Utils/DriverStoreEntry.cs b/Rapr/Utils/DriverStoreEntry.cs index 91f80d2b..3c21c2d0 100644 --- a/Rapr/Utils/DriverStoreEntry.cs +++ b/Rapr/Utils/DriverStoreEntry.cs @@ -270,6 +270,9 @@ public static string[] GetFieldNames() "Device Name", "Device Present", "Install Date", + "Boot Critical", + "Extension Id", + "Driver Files", }; } @@ -290,6 +293,9 @@ public string[] GetFieldValues() this.DeviceName ?? string.Empty, this.DevicePresent?.ToString() ?? string.Empty, this.InstallDate?.ToString("d") ?? string.Empty, + this.BootCritical?.ToString() ?? string.Empty, + this.DriverExtensionId == Guid.Empty ? string.Empty : this.DriverExtensionId.ToString(), + this.DriverFiles != null ? string.Join(", ", this.DriverFiles) : string.Empty, }; } diff --git a/RaprTests/DriverStoreEntryTests.cs b/RaprTests/DriverStoreEntryTests.cs index 8586a481..21c37f25 100644 --- a/RaprTests/DriverStoreEntryTests.cs +++ b/RaprTests/DriverStoreEntryTests.cs @@ -11,6 +11,32 @@ namespace Rapr.Tests [TestClass] public class DriverStoreEntryTests { + [TestMethod] + public void ExportedValuesLineUpWithTheHeader() + { + var extensionId = new Guid("1d1b2b1c-7f6e-4d8a-9c3f-1a2b3c4d5e6f"); + var entry = new DriverStoreEntry + { + BootCritical = true, + DriverExtensionId = extensionId, + DriverFiles = new List { "a.sys", "b.dll" }, + }; + + string[] names = DriverStoreEntry.GetFieldNames(); + string[] values = entry.GetFieldValues(); + + Assert.AreEqual(names.Length, values.Length); + Assert.AreEqual(bool.TrueString, values[Array.IndexOf(names, "Boot Critical")]); + Assert.AreEqual(extensionId.ToString(), values[Array.IndexOf(names, "Extension Id")]); + Assert.AreEqual("a.sys, b.dll", values[Array.IndexOf(names, "Driver Files")]); + + // Not every backend fills these in. + values = new DriverStoreEntry().GetFieldValues(); + Assert.AreEqual(string.Empty, values[Array.IndexOf(names, "Boot Critical")]); + Assert.AreEqual(string.Empty, values[Array.IndexOf(names, "Extension Id")]); + Assert.AreEqual(string.Empty, values[Array.IndexOf(names, "Driver Files")]); + } + [TestMethod] public void InstallDateIsTruncatedToTheDayItDisplays() { From 9a48455d8c8e08e43b03ed068dad7bd88d5f7037 Mon Sep 17 00:00:00 2001 From: indep-arg <333053532+indep-arg@users.noreply.github.com> Date: Tue, 27 Oct 2026 11:54:04 -0300 Subject: [PATCH 3/4] Escape CSV values that would be read as formulas Excel and other spreadsheet apps evaluate a cell that starts with =, +, - or @ as a formula. Provider and device names come from third-party INF files, so prefix such values with an apostrophe. Plain numbers like the -1 used for an unknown size are left alone. --- Rapr/CSVExporter.cs | 11 +++++++++++ RaprTests/CsvExporterTests.cs | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Rapr/CSVExporter.cs b/Rapr/CSVExporter.cs index f394da09..c11df565 100644 --- a/Rapr/CSVExporter.cs +++ b/Rapr/CSVExporter.cs @@ -14,6 +14,10 @@ public class CsvExporter : IExport { private const string CsvQuote = "\""; + // Spreadsheet apps treat a cell starting with one of these as a formula. Provider and + // device names come from third-party INF files, so they shouldn't be able to become one. + private static readonly char[] FormulaPrefixes = { '=', '+', '-', '@', '\t', '\r' }; + public string Export(List driverStoreEntries) { if (driverStoreEntries == null) @@ -69,6 +73,13 @@ private static string[] Sanitize(string[] values, string csvDelimiter) continue; } + if (values[i].Length > 0 + && Array.IndexOf(FormulaPrefixes, values[i][0]) >= 0 + && !double.TryParse(values[i], NumberStyles.Float, CultureInfo.CurrentCulture, out _)) + { + values[i] = "'" + values[i]; + } + if (values[i].Contains(csvDelimiter) || values[i].Contains(CsvQuote) || values[i].Contains("\r") diff --git a/RaprTests/CsvExporterTests.cs b/RaprTests/CsvExporterTests.cs index 31318233..e6b06811 100644 --- a/RaprTests/CsvExporterTests.cs +++ b/RaprTests/CsvExporterTests.cs @@ -42,6 +42,18 @@ public void ExportedFieldsRoundTripAsOneRecord(string delimiter, string value) } } + [TestMethod] + [DataRow("=cmd|' /C calc'!A0", "'=cmd|' /C calc'!A0")] + [DataRow("+Provider", "'+Provider")] + [DataRow("@SUM(1,1)", "'@SUM(1,1)")] + [DataRow("-Provider", "'-Provider")] + [DataRow("-1", "-1")] + [DataRow("Contoso", "Contoso")] + public void ValuesThatLookLikeFormulasAreEscaped(string value, string expected) + { + Assert.AreEqual(expected, Sanitize(new[] { value }, ";")[0]); + } + private static string NormalizeNewlines(string value) { return value.Replace("\r\n", "\n").Replace('\r', '\n'); From a246de32238141c5a8404d1ac631f8d2e15cf5eb Mon Sep 17 00:00:00 2001 From: indep-arg <333053532+indep-arg@users.noreply.github.com> Date: Tue, 27 Oct 2026 12:36:21 -0300 Subject: [PATCH 4/4] Leave Driver Files out of the CSV export On a machine with an NVIDIA GPU, the display driver package (nv_dispi.inf) lists over 13,000 files, so its Driver Files cell was about 224,000 characters. That made the CSV roughly 28 times bigger, and Excel cuts a cell at 32,767 characters. Keep the Boot Critical and Extension Id columns; the file list is still shown in the app. --- Rapr/Utils/DriverStoreEntry.cs | 4 ++-- RaprTests/DriverStoreEntryTests.cs | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Rapr/Utils/DriverStoreEntry.cs b/Rapr/Utils/DriverStoreEntry.cs index 3c21c2d0..c70d055f 100644 --- a/Rapr/Utils/DriverStoreEntry.cs +++ b/Rapr/Utils/DriverStoreEntry.cs @@ -254,6 +254,8 @@ public int? OemId } } + // Driver Files is not exported: a single GPU driver package can list over 10,000 files, + // far more than an Excel cell holds (32,767 characters). public static string[] GetFieldNames() { return new[] { @@ -272,7 +274,6 @@ public static string[] GetFieldNames() "Install Date", "Boot Critical", "Extension Id", - "Driver Files", }; } @@ -295,7 +296,6 @@ public string[] GetFieldValues() this.InstallDate?.ToString("d") ?? string.Empty, this.BootCritical?.ToString() ?? string.Empty, this.DriverExtensionId == Guid.Empty ? string.Empty : this.DriverExtensionId.ToString(), - this.DriverFiles != null ? string.Join(", ", this.DriverFiles) : string.Empty, }; } diff --git a/RaprTests/DriverStoreEntryTests.cs b/RaprTests/DriverStoreEntryTests.cs index 21c37f25..1aa25712 100644 --- a/RaprTests/DriverStoreEntryTests.cs +++ b/RaprTests/DriverStoreEntryTests.cs @@ -19,22 +19,20 @@ public void ExportedValuesLineUpWithTheHeader() { BootCritical = true, DriverExtensionId = extensionId, - DriverFiles = new List { "a.sys", "b.dll" }, }; string[] names = DriverStoreEntry.GetFieldNames(); string[] values = entry.GetFieldValues(); Assert.AreEqual(names.Length, values.Length); + CollectionAssert.DoesNotContain(names, "Driver Files"); Assert.AreEqual(bool.TrueString, values[Array.IndexOf(names, "Boot Critical")]); Assert.AreEqual(extensionId.ToString(), values[Array.IndexOf(names, "Extension Id")]); - Assert.AreEqual("a.sys, b.dll", values[Array.IndexOf(names, "Driver Files")]); // Not every backend fills these in. values = new DriverStoreEntry().GetFieldValues(); Assert.AreEqual(string.Empty, values[Array.IndexOf(names, "Boot Critical")]); Assert.AreEqual(string.Empty, values[Array.IndexOf(names, "Extension Id")]); - Assert.AreEqual(string.Empty, values[Array.IndexOf(names, "Driver Files")]); } [TestMethod]