Created
September 18, 2016 18:43
-
-
Save sayedihashimi/2b8f352d35f2627ac78569325a7789f6 to your computer and use it in GitHub Desktop.
Download Nalimov table bases (3/4/5)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cmdletbinding()] | |
param() | |
function DownloadTablebases{ | |
[cmdletbinding()] | |
param( | |
$baseUrl = 'http://www.chesskit.com/download/nalimov', | |
$allFilename = 'all.txt', | |
$downloadRoot = ($pwd) | |
) | |
process{ | |
try{ | |
Push-Location | |
Set-Location $downloadRoot | |
# check for the all.txt, if it's not there then download it | |
$allTxtPath = (Join-Path $downloadRoot $allFilename) | |
if(-not (Test-Path $allTxtPath)){ | |
$allUrl = "$baseUrl/$allFilename" | |
'Downloading all file from [{0}] to [{1}]' -f $allUrl, $allTxtPath | Write-Verbose | |
Invoke-WebRequest -Uri $allUrl -OutFile $allTxtPath | |
} | |
Get-Content $allTxtPath | % { | |
$currentline = $_ | |
if(-not [string]::IsNullOrWhiteSpace($currentline)){ | |
$currentline = $currentline.trim() | |
} | |
if([string]::Compare($allFilename,$currentline,[System.StringComparison]::OrdinalIgnoreCase) -ne 0){ | |
# see if the file exists locally and if not then redownload it | |
$currentfile = (Join-Path $downloadRoot $currentline) | |
if(-not(Test-Path $currentfile)){ | |
$dlurl = "$baseUrl/$currentline" | |
'Downloading file from [{0}] to [{1}]' -f $baseUrl, $currentfile | Write-Verbose | |
Invoke-WebRequest -Uri $dlurl -OutFile $currentfile | |
} | |
} | |
} | |
} | |
finally{ | |
Pop-Location | |
} | |
} | |
} | |
DownloadTablebases |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment