@@ -143,6 +143,7 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
143
143
var filePath = Path . Combine ( Path . GetTempPath ( ) , downloadFilename ) ;
144
144
145
145
IProgressBoxEx prgBox = null ;
146
+ var downloadCancelled = false ;
146
147
try
147
148
{
148
149
if ( ! plugin . IsFromLocalInstallPath )
@@ -158,7 +159,13 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
158
159
var totalBytes = response . Content . Headers . ContentLength ?? - 1L ;
159
160
var canReportProgress = totalBytes != - 1 ;
160
161
161
- if ( canReportProgress && ( prgBox = Context . API . ShowProgressBox ( $ "Download { plugin . Name } ...") ) != null )
162
+ if ( canReportProgress &&
163
+ ( prgBox = Context . API . ShowProgressBox ( $ "Download { plugin . Name } ...", ( ) =>
164
+ {
165
+ httpClient . CancelPendingRequests ( ) ;
166
+ downloadCancelled = true ;
167
+ prgBox = null ;
168
+ } ) ) != null )
162
169
{
163
170
await using var contentStream = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
164
171
await using var fileStream = new FileStream ( filePath , FileMode . Create , FileAccess . Write , FileShare . None , 8192 , true ) ;
@@ -173,27 +180,38 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
173
180
totalRead += read ;
174
181
175
182
var progressValue = totalRead * 100 / totalBytes ;
183
+
184
+ // check if user cancelled download before reporting progress
185
+ if ( downloadCancelled )
186
+ return ;
187
+
176
188
prgBox . ReportProgress ( progressValue ) ;
177
189
}
178
190
191
+ // check if user cancelled download before closing progress box
192
+ if ( downloadCancelled )
193
+ return ;
194
+
179
195
Application . Current . Dispatcher . Invoke ( ( ) =>
180
196
{
181
197
prgBox . Close ( ) ;
182
198
prgBox = null ;
183
199
} ) ;
200
+
201
+ Install ( plugin , filePath ) ;
184
202
}
185
203
else
186
204
{
187
205
await Http . DownloadAsync ( plugin . UrlDownload , filePath ) . ConfigureAwait ( false ) ;
206
+ Install ( plugin , filePath ) ;
188
207
}
189
208
}
190
209
else
191
210
{
192
211
filePath = plugin . LocalInstallPath ;
193
- }
194
-
195
212
Install ( plugin , filePath ) ;
196
213
}
214
+ }
197
215
catch ( HttpRequestException e )
198
216
{
199
217
Context . API . ShowMsgError (
0 commit comments