@@ -30,7 +30,7 @@ public TranslationProvider()
30
30
Directory . CreateDirectory ( _translationsDir ) ;
31
31
}
32
32
33
- if ( IsUpdateAvailable ( ) )
33
+ if ( IsUpdateAvailable ( ) != null )
34
34
{
35
35
UpdateTranslations ( ) ;
36
36
}
@@ -138,7 +138,7 @@ public void ParseTranslationFiles()
138
138
}
139
139
catch ( Exception ex )
140
140
{
141
- MessageBox . Show ( $ "There was a problem while updating the translations file .\n " +
141
+ MessageBox . Show ( $ "There was a problem while parsing the translation files .\n " +
142
142
$ "Details: { ex . Message } ") ;
143
143
}
144
144
}
@@ -148,52 +148,68 @@ public void ParseTranslationFiles()
148
148
/// </summary>
149
149
public void UpdateTranslations ( )
150
150
{
151
- // Clear temp folder before beggining
152
- DirUtils . ClearTempFolder ( ) ;
153
-
154
- // Download latest release zip file
155
- var wc = new WebClient ( ) ;
156
- var downloadedFile = Path . Combine ( _tempDir , "langs.zip" ) ;
157
- wc . Headers . Add ( HttpRequestHeader . UserAgent , Constants . ProductHeaderValueName ) ;
158
- wc . DownloadFile ( _latestVersion . ZipballUrl , downloadedFile ) ;
159
-
160
- // Decompress and replace all of its files
161
- ZipFile . ExtractToDirectory ( downloadedFile , _tempDir ) ;
162
- var filesDir = Directory . GetFiles ( Directory . GetDirectories ( _tempDir ) [ 0 ] ) . Where ( x => x . EndsWith ( ".xml" ) ) ;
163
- foreach ( var file in filesDir )
151
+ try
164
152
{
165
- // Create wrapper
166
- var fInfo = new FileInfo ( file ) ;
167
-
168
- // Replace current file with this one
169
- var destination = Path . Combine ( _translationsDir , fInfo . Name ) ;
170
- if ( File . Exists ( destination ) )
153
+ // Clear temp folder before beggining
154
+ DirUtils . ClearTempFolder ( ) ;
155
+
156
+ // Download latest release zip file
157
+ var wc = new WebClient ( ) ;
158
+ var downloadedFile = Path . Combine ( _tempDir , "langs.zip" ) ;
159
+ wc . Headers . Add ( HttpRequestHeader . UserAgent , Constants . ProductHeaderValueName ) ;
160
+ wc . DownloadFile ( _latestVersion . ZipballUrl , downloadedFile ) ;
161
+
162
+ // Decompress and replace all of its files
163
+ ZipFile . ExtractToDirectory ( downloadedFile , _tempDir ) ;
164
+ var filesDir = Directory . GetFiles ( Directory . GetDirectories ( _tempDir ) [ 0 ] ) . Where ( x => x . EndsWith ( ".xml" ) ) ;
165
+ foreach ( var file in filesDir )
171
166
{
172
- File . Delete ( destination ) ;
167
+ // Create wrapper
168
+ var fInfo = new FileInfo ( file ) ;
169
+
170
+ // Replace current file with this one
171
+ var destination = Path . Combine ( _translationsDir , fInfo . Name ) ;
172
+ if ( File . Exists ( destination ) )
173
+ {
174
+ File . Delete ( destination ) ;
175
+ }
176
+ File . Move ( fInfo . FullName , destination ) ;
173
177
}
174
- File . Move ( fInfo . FullName , destination ) ;
175
- }
176
178
177
- // Delete all temp folder contents
178
- DirUtils . ClearTempFolder ( ) ;
179
+ // Delete all temp folder contents
180
+ DirUtils . ClearTempFolder ( ) ;
179
181
180
- // Update version to options object
181
- Program . OptionsObject . TranslationsVersion = int . Parse ( _latestVersion . Name ) ;
182
+ // Update version to options object
183
+ Program . OptionsObject . TranslationsVersion = int . Parse ( _latestVersion . Name ) ;
184
+ }
185
+ catch ( Exception ex )
186
+ {
187
+ MessageBox . Show ( $ "There was a problem while downloading the new translation files.\n " +
188
+ $ "Details: { ex . Message } ") ;
189
+ }
182
190
}
183
191
184
192
/// <summary>
185
193
/// Compares the stored version of the translations release with the one from GitHub
186
194
/// </summary>
187
195
/// <returns>Whether there's an update available</returns>
188
- public bool IsUpdateAvailable ( )
196
+ public bool ? IsUpdateAvailable ( )
189
197
{
190
- var client = new GitHubClient ( new ProductHeaderValue ( Constants . ProductHeaderValueName ) ) ;
191
- var versionStored = Program . OptionsObject . TranslationsVersion ;
198
+ try
199
+ {
200
+ var client = new GitHubClient ( new ProductHeaderValue ( Constants . ProductHeaderValueName ) ) ;
201
+ var versionStored = Program . OptionsObject . TranslationsVersion ;
192
202
193
- _latestVersion = client . Repository . Release . GetAll ( Constants . OrgName ,
194
- Constants . TranslationsRepoName ) . Result [ 0 ] ;
203
+ _latestVersion = client . Repository . Release . GetAll ( Constants . OrgName ,
204
+ Constants . TranslationsRepoName ) . Result [ 0 ] ;
205
+
206
+ return versionStored < int . Parse ( _latestVersion . Name ) ;
207
+ }
208
+ catch ( Exception )
209
+ {
210
+ return null ;
211
+ }
195
212
196
- return versionStored < int . Parse ( _latestVersion . Name ) ;
197
213
}
198
214
}
199
215
}
0 commit comments