|
| 1 | +$url = "https://raw.githubusercontent.com/opencv/opencv_3rdparty/@FFMPEG_BINARIES_COMMIT@/ffmpeg/opencv_ffmpeg_64.dll" |
| 2 | +$expected_md5 = "@FFMPEG_FILE_HASH_BIN64@" |
| 3 | +$output = "$PSScriptRoot\@OPENCV_BIN_INSTALL_PATH@\opencv_ffmpeg@OPENCV_DLLVERSION@_64.dll" |
| 4 | + |
| 5 | +Write-Output ("=" * 120) |
| 6 | +try { |
| 7 | + Get-content -Path "$PSScriptRoot\etc\licenses\ffmpeg-readme.txt" -ErrorAction 'Stop' |
| 8 | +} catch { |
| 9 | + Write-Output "Refer to OpenCV FFmpeg wrapper readme notes about library usage / licensing details." |
| 10 | +} |
| 11 | +Write-Output ("=" * 120) |
| 12 | +Write-Output "" |
| 13 | + |
| 14 | +if(![System.IO.File]::Exists($output)) { |
| 15 | + try { |
| 16 | + Write-Output ("Downloading: " + $output) |
| 17 | + Import-Module BitsTransfer |
| 18 | + $start_time = Get-Date |
| 19 | + Start-BitsTransfer -Source $url -Destination $output -ErrorAction 'Stop' |
| 20 | + Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds" |
| 21 | + } catch { |
| 22 | + $_ # Dump error |
| 23 | + try { |
| 24 | + Write-Output ("Downloading (second attempt): " + $output) |
| 25 | + $start_time = Get-Date |
| 26 | + Invoke-WebRequest -Uri $url -OutFile $output |
| 27 | + Write-Output "Downloaded in $((Get-Date).Subtract($start_time).Seconds) seconds" |
| 28 | + } catch { |
| 29 | + Write-Output ("Can't download file: " + $output) |
| 30 | + Write-Output ("URL: " + $url) |
| 31 | + Write-Output "You need to download this file manually. Stop" |
| 32 | + Pause |
| 33 | + Exit |
| 34 | + } |
| 35 | + } |
| 36 | +} else { |
| 37 | + Write-Output ("File exists: " + $output) |
| 38 | + Write-Output ("Downloading is skipped. Remove this file and re-run this script to force downloading.") |
| 39 | +} |
| 40 | + |
| 41 | +if(![System.IO.File]::Exists($output)) { |
| 42 | + Write-Output ("Destination file not found: " + $output) |
| 43 | + Write-Output "Stop" |
| 44 | + Pause |
| 45 | + Exit |
| 46 | +} |
| 47 | + |
| 48 | +try { |
| 49 | + $hash = Get-FileHash $output -Algorithm MD5 -ErrorAction 'Stop' |
| 50 | + |
| 51 | + if($hash.Hash -eq $expected_md5) { |
| 52 | + Write-Output "MD5 check passed" |
| 53 | + } else { |
| 54 | + Write-Output ("MD5 : " + $hash.Hash.toLower()) |
| 55 | + Write-Output ("Expected: " + $expected_md5) |
| 56 | + Write-Output "MD5 hash mismatch" |
| 57 | + } |
| 58 | +} catch { |
| 59 | + $_ # Dump error |
| 60 | + Write-Output "Can't check MD5 hash (requires PowerShell 4+)" |
| 61 | +} |
| 62 | +Pause |
| 63 | +Write-Output "Exit" |
0 commit comments