From 997a7bc60fd76f7c3fa697fdcd4f50faf558af55 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Fri, 11 Sep 2020 16:15:18 -0700 Subject: [PATCH] adding in trim (#6584) --- .../Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs index 66adf9c2df..c69883369b 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Lib/SettingsUtils.cs @@ -4,6 +4,7 @@ using System; using System.IO; +using System.Runtime.Serialization; using System.Text.Json; namespace Microsoft.PowerToys.Settings.UI.Lib @@ -57,7 +58,12 @@ namespace Microsoft.PowerToys.Settings.UI.Lib /// Deserialized json settings object. public static T GetSettings(string powertoy = DefaultModuleName, string fileName = DefaultFileName) { - var jsonSettingsString = File.ReadAllText(GetSettingsPath(powertoy, fileName)); + // Adding Trim('\0') to overcome possible NTFS file corruption. + // Look at issue https://github.com/microsoft/PowerToys/issues/6413 you'll see the file has a large sum of \0 to fill up a 4096 byte buffer for writing to disk + // This, while not totally ideal, does work around the problem by trimming the end. + // The file itself did write the content correctly but something is off with the actual end of the file, hence the 0x00 bug + var jsonSettingsString = File.ReadAllText(GetSettingsPath(powertoy, fileName)).Trim('\0'); + return JsonSerializer.Deserialize(jsonSettingsString); }