mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
adding in trim (#6584)
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Lib
|
namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||||
@@ -57,7 +58,12 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
|||||||
/// <returns>Deserialized json settings object.</returns>
|
/// <returns>Deserialized json settings object.</returns>
|
||||||
public static T GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
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);
|
return JsonSerializer.Deserialize<T>(jsonSettingsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user