@@ -148,7 +148,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
148
148
149
149
if ( ! plugin . IsFromLocalInstallPath )
150
150
{
151
- await DeleteFileAndDownloadMsgBoxAsync (
151
+ await DownloadFileAsync (
152
152
$ "{ Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) } { plugin . Name } ",
153
153
plugin . UrlDownload , filePath , cts ) ;
154
154
}
@@ -199,32 +199,39 @@ await DeleteFileAndDownloadMsgBoxAsync(
199
199
}
200
200
}
201
201
202
- private async Task DeleteFileAndDownloadMsgBoxAsync ( string prgBoxTitle , string downloadUrl , string filePath , CancellationTokenSource cts )
202
+ private async Task DownloadFileAsync ( string prgBoxTitle , string downloadUrl , string filePath , CancellationTokenSource cts , bool deleteFile = true , bool showProgress = true )
203
203
{
204
- if ( File . Exists ( filePath ) )
204
+ if ( deleteFile && File . Exists ( filePath ) )
205
205
File . Delete ( filePath ) ;
206
206
207
- var exceptionHappened = false ;
208
- await Context . API . ShowProgressBoxAsync ( prgBoxTitle ,
209
- async ( reportProgress ) =>
210
- {
211
- if ( reportProgress == null )
212
- {
213
- // when reportProgress is null, it means there is expcetion with the progress box
214
- // so we record it with exceptionHappened and return so that progress box will close instantly
215
- exceptionHappened = true ;
216
- return ;
217
- }
218
- else
207
+ if ( showProgress )
208
+ {
209
+ var exceptionHappened = false ;
210
+ await Context . API . ShowProgressBoxAsync ( prgBoxTitle ,
211
+ async ( reportProgress ) =>
219
212
{
220
- await Context . API . HttpDownloadAsync ( downloadUrl , filePath , reportProgress , cts . Token ) . ConfigureAwait ( false ) ;
221
- }
222
- } , cts . Cancel ) ;
213
+ if ( reportProgress == null )
214
+ {
215
+ // when reportProgress is null, it means there is expcetion with the progress box
216
+ // so we record it with exceptionHappened and return so that progress box will close instantly
217
+ exceptionHappened = true ;
218
+ return ;
219
+ }
220
+ else
221
+ {
222
+ await Context . API . HttpDownloadAsync ( downloadUrl , filePath , reportProgress , cts . Token ) . ConfigureAwait ( false ) ;
223
+ }
224
+ } , cts . Cancel ) ;
223
225
224
- // if exception happened while downloading and user does not cancel downloading,
225
- // we need to redownload the plugin
226
- if ( exceptionHappened && ( ! cts . IsCancellationRequested ) )
227
- await Context . API . HttpDownloadAsync ( downloadUrl , filePath ) . ConfigureAwait ( false ) ;
226
+ // if exception happened while downloading and user does not cancel downloading,
227
+ // we need to redownload the plugin
228
+ if ( exceptionHappened && ( ! cts . IsCancellationRequested ) )
229
+ await Context . API . HttpDownloadAsync ( downloadUrl , filePath , token : cts . Token ) . ConfigureAwait ( false ) ;
230
+ }
231
+ else
232
+ {
233
+ await Context . API . HttpDownloadAsync ( downloadUrl , filePath , token : cts . Token ) . ConfigureAwait ( false ) ;
234
+ }
228
235
}
229
236
230
237
internal async ValueTask < List < Result > > RequestUpdateAsync ( string search , CancellationToken token ,
@@ -318,7 +325,7 @@ where string.Compare(existingPlugin.Metadata.Version, pluginUpdateSource.Version
318
325
319
326
if ( ! x . PluginNewUserPlugin . IsFromLocalInstallPath )
320
327
{
321
- await DeleteFileAndDownloadMsgBoxAsync (
328
+ await DownloadFileAsync (
322
329
$ "{ Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) } { x . PluginNewUserPlugin . Name } ",
323
330
x . PluginNewUserPlugin . UrlDownload , downloadToFilePath , cts ) ;
324
331
}
@@ -418,7 +425,7 @@ await Task.WhenAll(resultsForUpdate.Select(async plugin =>
418
425
{
419
426
using var cts = new CancellationTokenSource ( ) ;
420
427
421
- await DeleteFileAndDownloadMsgBoxAsync (
428
+ await DownloadFileAsync (
422
429
$ "{ Context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) } { plugin . PluginNewUserPlugin . Name } ",
423
430
plugin . PluginNewUserPlugin . UrlDownload , downloadToFilePath , cts ) ;
424
431
0 commit comments