@@ -42,8 +42,25 @@ public UsageTracker(
4242 [ Import ( typeof ( SVsServiceProvider ) ) ] IServiceProvider serviceProvider )
4343 {
4444 fileExists = ( path ) => System . IO . File . Exists ( path ) ;
45- readAllText = ( path , encoding ) => System . IO . File . ReadAllText ( path , encoding ) ;
46- writeAllText = ( path , content , encoding ) => System . IO . File . WriteAllText ( path , content , encoding ) ;
45+ readAllText = ( path , encoding ) =>
46+ {
47+ try
48+ {
49+ return System . IO . File . ReadAllText ( path , encoding ) ;
50+ }
51+ catch
52+ {
53+ return null ;
54+ }
55+ } ;
56+ writeAllText = ( path , content , encoding ) =>
57+ {
58+ try
59+ {
60+ System . IO . File . WriteAllText ( path , content , encoding ) ;
61+ }
62+ catch { }
63+ } ;
4764 dirCreate = ( path ) => System . IO . Directory . CreateDirectory ( path ) ;
4865
4966 this . connectionManager = connectionManager ;
@@ -138,9 +155,18 @@ public void IncrementLoginCount()
138155
139156 UsageStore LoadUsage ( )
140157 {
141- var result = fileExists ( storePath ) ?
142- SimpleJson . DeserializeObject < UsageStore > ( readAllText ( storePath , Encoding . UTF8 ) ) :
143- new UsageStore { Model = new UsageModel ( ) } ;
158+ var json = fileExists ( storePath ) ? readAllText ( storePath , Encoding . UTF8 ) : null ;
159+ UsageStore result = null ;
160+ try
161+ {
162+ result = json != null ?
163+ SimpleJson . DeserializeObject < UsageStore > ( json ) :
164+ new UsageStore { Model = new UsageModel ( ) } ;
165+ }
166+ catch
167+ {
168+ result = new UsageStore { Model = new UsageModel ( ) } ;
169+ }
144170
145171 result . Model . Lang = CultureInfo . InstalledUICulture . IetfLanguageTag ;
146172 result . Model . AppVersion = AssemblyVersionInformation . Version ;
0 commit comments