Skip to content

Commit f144270

Browse files
authored
Fix: Prevent crash on fresh startup (#10031)
1 parent 5e64eca commit f144270

File tree

4 files changed

+13
-104
lines changed

4 files changed

+13
-104
lines changed

src/Files.App/Helpers/AppUpdater.cs

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/Files.App/Serialization/ISettingsSerializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ internal interface ISettingsSerializer
66
{
77
bool CreateFile(string path);
88

9-
string? ReadFromFile();
9+
string ReadFromFile();
1010

1111
bool WriteToFile(string? text);
1212
}

src/Files.App/Serialization/Implementation/DefaultJsonSettingsDatabase.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public DefaultJsonSettingsDatabase(ISettingsSerializer settingsSerializer, IJson
2121

2222
protected Dictionary<string, object?> GetFreshSettings()
2323
{
24-
var data = SettingsSerializer.ReadFromFile() ?? string.Empty;
24+
string data = SettingsSerializer.ReadFromFile();
25+
26+
if (string.IsNullOrWhiteSpace(data))
27+
{
28+
data = "null";
29+
}
2530

2631
return JsonSettingsSerializer.DeserializeFromJson<Dictionary<string, object?>?>(data) ?? new();
2732
}

src/Files.App/Serialization/Implementation/DefaultSettingsSerializer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public bool CreateFile(string path)
2828
return true;
2929
}
3030

31-
public string? ReadFromFile()
31+
/// <summary>
32+
/// Reads a file to a string
33+
/// </summary>
34+
/// <returns>A string value or string.Empty if nothing is present in the file</returns>
35+
/// <exception cref="ArgumentNullException"></exception>
36+
public string ReadFromFile()
3237
{
3338
_ = _filePath ?? throw new ArgumentNullException(nameof(_filePath));
3439

0 commit comments

Comments
 (0)