@@ -47,18 +47,25 @@ private async Task Load()
47
47
if ( Model == null )
48
48
{
49
49
Model = new TerminalFileModel ( ) ;
50
- throw new JsonSerializationException ( $ " { JsonFileName } is empty, regenerating..." ) ;
50
+ throw new JsonParsingNullException ( JsonFileName ) ;
51
51
}
52
52
}
53
- catch ( JsonSerializationException )
53
+ catch ( JsonParsingNullException )
54
54
{
55
55
var defaultFile = StorageFile . GetFileFromApplicationUriAsync ( new Uri ( defaultTerminalPath ) ) ;
56
-
56
+
57
57
JsonFile = await Folder . CreateFileAsync ( JsonFileName , CreationCollisionOption . ReplaceExisting ) ;
58
58
await FileIO . WriteBufferAsync ( JsonFile , await FileIO . ReadBufferAsync ( await defaultFile ) ) ;
59
59
var defaultContent = await FileIO . ReadTextAsync ( JsonFile ) ;
60
60
Model = JsonConvert . DeserializeObject < TerminalFileModel > ( defaultContent ) ;
61
61
}
62
+ catch ( Exception )
63
+ {
64
+ var defaultFile = await StorageFile . GetFileFromApplicationUriAsync ( new Uri ( defaultTerminalPath ) ) ;
65
+ JsonFile = null ;
66
+ var defaultContent = await FileIO . ReadTextAsync ( defaultFile ) ;
67
+ Model = JsonConvert . DeserializeObject < TerminalFileModel > ( defaultContent ) ;
68
+ }
62
69
}
63
70
64
71
public async void Init ( )
@@ -95,6 +102,8 @@ public async Task GetInstalledTerminals()
95
102
96
103
public void SaveModel ( )
97
104
{
105
+ if ( JsonFile == null ) return ;
106
+
98
107
using ( var file = File . CreateText ( Folder . Path + Path . DirectorySeparatorChar + JsonFileName ) )
99
108
{
100
109
JsonSerializer serializer = new JsonSerializer ( ) ;
@@ -103,4 +112,9 @@ public void SaveModel()
103
112
}
104
113
}
105
114
}
115
+
116
+ public class JsonParsingNullException : Exception
117
+ {
118
+ public JsonParsingNullException ( string jsonFileName ) : base ( $ "{ jsonFileName } is empty, regenerating...") { }
119
+ }
106
120
}
0 commit comments