@@ -205,7 +205,7 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
205
205
# aria2 input file
206
206
$urlstxt = Join-Path $cachedir " $app .txt"
207
207
$urlstxt_content = ' '
208
- $has_downloads = $false
208
+ $download_finished = $true
209
209
210
210
# aria2 options
211
211
$options = @ (
@@ -225,64 +225,66 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
225
225
" --min-tls-version=TLSv1.2"
226
226
" --stop-with-process=$PID "
227
227
" --continue"
228
- " --summary-interval 0"
228
+ " --summary-interval=0"
229
+ " --auto-save-interval=1"
229
230
)
230
231
231
- if ($cookies ) {
232
+ if ($cookies ) {
232
233
$options += " --header='Cookie: $ ( cookie_header $cookies ) '"
233
234
}
234
235
235
236
$proxy = get_config ' proxy'
236
- if ($proxy -ne ' none' ) {
237
- if ([Net.Webrequest ]::DefaultWebProxy.Address) {
237
+ if ($proxy -ne ' none' ) {
238
+ if ([Net.Webrequest ]::DefaultWebProxy.Address) {
238
239
$options += " --all-proxy='$ ( [Net.Webrequest ]::DefaultWebProxy.Address.Authority) '"
239
240
}
240
- if ([Net.Webrequest ]::DefaultWebProxy.Credentials.UserName) {
241
+ if ([Net.Webrequest ]::DefaultWebProxy.Credentials.UserName) {
241
242
$options += " --all-proxy-user='$ ( [Net.Webrequest ]::DefaultWebProxy.Credentials.UserName) '"
242
243
}
243
- if ([Net.Webrequest ]::DefaultWebProxy.Credentials.Password) {
244
+ if ([Net.Webrequest ]::DefaultWebProxy.Credentials.Password) {
244
245
$options += " --all-proxy-passwd='$ ( [Net.Webrequest ]::DefaultWebProxy.Credentials.Password) '"
245
246
}
246
247
}
247
248
248
249
$more_options = get_config ' aria2-options'
249
- if ($more_options ) {
250
+ if ($more_options ) {
250
251
$options += $more_options
251
252
}
252
253
253
- foreach ($url in $urls ) {
254
+ foreach ($url in $urls ) {
254
255
$data .$url = @ {
255
- ' filename' = url_filename $url
256
- ' target' = " $dir \$ ( url_filename $url ) "
256
+ ' target' = " $dir \$ ( url_filename $url ) "
257
257
' cachename' = fname (cache_path $app $version $url )
258
- ' source' = fullpath (cache_path $app $version $url )
258
+ ' source' = fullpath (cache_path $app $version $url )
259
259
}
260
260
261
- if (! (test-path $data .$url.source )) {
262
- $has_downloads = $true
261
+ if ((Test-Path $data .$url.source ) -and -not ((Test-Path " $ ( $data .$url.source ) .aria2" ) -or (Test-Path $urlstxt )) -and $use_cache ) {
262
+ Write-Host ' Loading ' - NoNewline
263
+ Write-Host $ (url_remote_filename $url ) -f Cyan - NoNewline
264
+ Write-Host ' from cache.'
265
+ } else {
266
+ $download_finished = $false
263
267
# create aria2 input file content
264
268
$urlstxt_content += " $ ( handle_special_urls $url ) `n "
265
- if (! $url.Contains (' sourceforge.net' )) {
269
+ if (! $url.Contains (' sourceforge.net' )) {
266
270
$urlstxt_content += " referer=$ ( strip_filename $url ) `n "
267
271
}
268
272
$urlstxt_content += " dir=$cachedir `n "
269
273
$urlstxt_content += " out=$ ( $data .$url.cachename ) `n "
270
- } else {
271
- Write-Host " Loading " - NoNewline
272
- Write-Host $ (url_remote_filename $url ) -f Cyan - NoNewline
273
- Write-Host " from cache."
274
274
}
275
275
}
276
276
277
- if ( $has_downloads ) {
277
+ if ( -not ( $download_finished ) ) {
278
278
# write aria2 input file
279
- Set-Content - Path $urlstxt $urlstxt_content
279
+ if ($urlstxt_content -ne ' ' ) {
280
+ Set-Content - Path $urlstxt $urlstxt_content
281
+ }
280
282
281
283
# build aria2 command
282
284
$aria2 = " & '$ ( Get-HelperPath - Helper Aria2) ' $ ( $options -join ' ' ) "
283
285
284
286
# handle aria2 console output
285
- Write-Host " Starting download with aria2 ..."
287
+ Write-Host ' Starting download with aria2 ...'
286
288
287
289
Invoke-Expression $aria2 | ForEach-Object {
288
290
# Skip blank lines
@@ -311,50 +313,52 @@ function dl_with_cache_aria2($app, $version, $manifest, $architecture, $dir, $co
311
313
error " Download failed! (Error $lastexitcode ) $ ( aria_exit_code $lastexitcode ) "
312
314
error $urlstxt_content
313
315
error $aria2
314
- abort $ (new_issue_msg $app $bucket " download via aria2 failed" )
316
+ abort $ (new_issue_msg $app $bucket ' download via aria2 failed' )
315
317
}
316
318
317
319
# remove aria2 input file when done
318
- if (test-path ($urlstxt )) {
319
- Remove-Item $urlstxt
320
+ if (Test-Path $urlstxt , " $ ( $data .$url.source ) .aria2*" ) {
321
+ Remove-Item $urlstxt - Force - ErrorAction SilentlyContinue
322
+ Remove-Item " $ ( $data .$url.source ) .aria2*" - Force - ErrorAction SilentlyContinue
320
323
}
321
324
}
322
325
323
- foreach ($url in $urls ) {
326
+ foreach ($url in $urls ) {
324
327
325
328
$metalink_filename = get_filename_from_metalink $data .$url.source
326
- if ($metalink_filename ) {
329
+ if ($metalink_filename ) {
327
330
Remove-Item $data .$url.source - Force
328
331
Rename-Item - Force (Join-Path - Path $cachedir - ChildPath $metalink_filename ) $data .$url.source
329
332
}
330
333
331
334
# run hash checks
332
- if ($check_hash ) {
335
+ if ($check_hash ) {
333
336
$manifest_hash = hash_for_url $manifest $url $architecture
334
337
$ok , $err = check_hash $data .$url.source $manifest_hash $ (show_app $app $bucket )
335
- if (! $ok ) {
338
+ if (! $ok ) {
336
339
error $err
337
- if ( test-path $data .$url.source ) {
340
+ if ( Test-Path $data .$url.source ) {
338
341
# rm cached file
339
- Remove-Item - force $data .$url.source
342
+ Remove-Item $data .$url.source - Force - ErrorAction SilentlyContinue
343
+ Remove-Item " $ ( $data .$url.source ) .aria2*" - Force - ErrorAction SilentlyContinue
340
344
}
341
- if ($url.Contains (' sourceforge.net' )) {
345
+ if ($url.Contains (' sourceforge.net' )) {
342
346
Write-Host -f yellow ' SourceForge.net is known for causing hash validation fails. Please try again before opening a ticket.'
343
347
}
344
- abort $ (new_issue_msg $app $bucket " hash check failed" )
348
+ abort $ (new_issue_msg $app $bucket ' hash check failed' )
345
349
}
346
350
}
347
351
348
352
# copy or move file to target location
349
- if (! (test-path $data .$url.source ) ) {
350
- abort $ (new_issue_msg $app $bucket " cached file not found" )
353
+ if (! (Test-Path $data .$url.source ) ) {
354
+ abort $ (new_issue_msg $app $bucket ' cached file not found' )
351
355
}
352
356
353
- if (! ($dir -eq $cachedir )) {
354
- if ($use_cache ) {
357
+ if (! ($dir -eq $cachedir )) {
358
+ if ($use_cache ) {
355
359
Copy-Item $data .$url.source $data .$url.target
356
360
} else {
357
- Move-Item $data .$url.source $data .$url.target - force
361
+ Move-Item $data .$url.source $data .$url.target - Force
358
362
}
359
363
}
360
364
}
0 commit comments