adding in trim (#6584)

This commit is contained in:
Clint Rutkas
2020-09-11 16:15:18 -07:00
committed by GitHub
parent bfbd7b53a1
commit 997a7bc60f

View File

@@ -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
/// <returns>Deserialized json settings object.</returns>
public static T GetSettings<T>(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<T>(jsonSettingsString);
}