@@ -4,6 +4,7 @@ Imports Microsoft.Toolkit.Mvvm.ComponentModel
4
4
Imports CompactGUI.Core
5
5
Imports System.Threading
6
6
Imports System.Collections.Specialized
7
+ Imports System.Runtime
7
8
8
9
Public Class Watcher : Inherits ObservableObject
9
10
@@ -121,21 +122,33 @@ Public Class Watcher : Inherits ObservableObject
121
122
If Not _DataFolder.Exists Then _DataFolder.Create()
122
123
If Not WatcherJSONFile.Exists Then Await WatcherJSONFile.Create().DisposeAsync()
123
124
124
- Dim WatcherJSON = IO.File.ReadAllText(WatcherJSONFile.FullName)
125
- If WatcherJSON = "" Then WatcherJSON = "{}"
126
-
127
- Dim ret = JsonSerializer.Deserialize( Of (DateTime, ObservableCollection( Of WatchedFolder)))(WatcherJSON, New JsonSerializerOptions With {.IncludeFields = True })
125
+ Dim ret = DeserializeAndValidateJSON(WatcherJSONFile)
128
126
LastAnalysed = ret.Item1
129
127
Dim _WatchedFolders = ret.Item2
130
128
131
129
132
130
Return _WatchedFolders
133
-
134
131
End Function
135
132
133
+ Private Shared Function DeserializeAndValidateJSON(inputjsonFile As IO.FileInfo) As (DateTime, ObservableCollection( Of WatchedFolder))
134
+ Dim WatcherJSON = IO.File.ReadAllText(inputjsonFile.FullName)
135
+ If WatcherJSON = "" Then WatcherJSON = "{}"
136
+
137
+ Dim validatedResult As (DateTime, ObservableCollection( Of WatchedFolder))
138
+ Try
139
+ validatedResult = JsonSerializer.Deserialize( Of (DateTime, ObservableCollection( Of WatchedFolder)))(WatcherJSON, New JsonSerializerOptions With {.IncludeFields = True })
140
+
141
+ Catch ex As Exception
142
+ validatedResult = (DateTime.Now, Nothing )
143
+
144
+ End Try
145
+
146
+ Return validatedResult
147
+
148
+ End Function
136
149
Private Sub WriteToFile()
137
150
138
- Dim output = JsonSerializer.Serialize((LastAnalysed, WatchedFolders), New JsonSerializerOptions With {.IncludeFields = True })
151
+ Dim output = JsonSerializer.Serialize((LastAnalysed, WatchedFolders), New JsonSerializerOptions With {.IncludeFields = True , .WriteIndented = True })
139
152
IO.File.WriteAllText(WatcherJSONFile.FullName, output)
140
153
141
154
End Sub
0 commit comments