@@ -47,18 +47,25 @@ private async Task Load()
4747 if ( Model == null )
4848 {
4949 Model = new TerminalFileModel ( ) ;
50- throw new JsonSerializationException ( $ " { JsonFileName } is empty, regenerating..." ) ;
50+ throw new JsonParsingNullException ( JsonFileName ) ;
5151 }
5252 }
53- catch ( JsonSerializationException )
53+ catch ( JsonParsingNullException )
5454 {
5555 var defaultFile = StorageFile . GetFileFromApplicationUriAsync ( new Uri ( defaultTerminalPath ) ) ;
56-
56+
5757 JsonFile = await Folder . CreateFileAsync ( JsonFileName , CreationCollisionOption . ReplaceExisting ) ;
5858 await FileIO . WriteBufferAsync ( JsonFile , await FileIO . ReadBufferAsync ( await defaultFile ) ) ;
5959 var defaultContent = await FileIO . ReadTextAsync ( JsonFile ) ;
6060 Model = JsonConvert . DeserializeObject < TerminalFileModel > ( defaultContent ) ;
6161 }
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+ }
6269 }
6370
6471 public async void Init ( )
@@ -95,6 +102,8 @@ public async Task GetInstalledTerminals()
95102
96103 public void SaveModel ( )
97104 {
105+ if ( JsonFile == null ) return ;
106+
98107 using ( var file = File . CreateText ( Folder . Path + Path . DirectorySeparatorChar + JsonFileName ) )
99108 {
100109 JsonSerializer serializer = new JsonSerializer ( ) ;
@@ -103,4 +112,9 @@ public void SaveModel()
103112 }
104113 }
105114 }
115+
116+ public class JsonParsingNullException : Exception
117+ {
118+ public JsonParsingNullException ( string jsonFileName ) : base ( $ "{ jsonFileName } is empty, regenerating...") { }
119+ }
106120}
0 commit comments