forked from MultiPoolMiner/MultiPoolMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Downloader.ps1
53 lines (41 loc) · 2.27 KB
/
Downloader.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$DownloadList = $args
if ($script:MyInvocation.MyCommand.Path) {Set-Location (Split-Path $script:MyInvocation.MyCommand.Path)}
. .\Include.ps1
$Progress = 0
$DownloadList | ForEach-Object {
$URI = $_.URI
$Path = $_.Path
$Searchable = $_.Searchable
$Progress += 100 / $DownloadList.Count
if (-not (Test-Path $Path)) {
try {
Write-Progress -Activity "Downloader" -Status $Path -CurrentOperation "Acquiring Online ($URI)" -PercentComplete $Progress
if ($URI -and (Split-Path $URI -Leaf) -eq (Split-Path $Path -Leaf)) {
New-Item (Split-Path $Path) -ItemType "Directory" | Out-Null
Invoke-WebRequest $URI -OutFile $Path -UseBasicParsing -ErrorAction Stop
}
else {
Expand-WebRequest $URI (Split-Path $Path) -ErrorAction Stop
}
}
catch {
Write-Progress -Activity "Downloader" -Status $Path -CurrentOperation "Acquiring Offline (Computer)" -PercentComplete $Progress
if ($URI) {Write-Host -BackgroundColor Yellow -ForegroundColor Black "Cannot download $($Path) distributed at $($URI). "}
else {Write-Host -BackgroundColor Yellow -ForegroundColor Black "Cannot download $($Path). "}
if ($Searchable) {
Write-Host -BackgroundColor Yellow -ForegroundColor Black "Searching for $($Path). "
$Path_Old = Get-PSDrive -PSProvider FileSystem | ForEach-Object {Get-ChildItem -Path $_.Root -Include (Split-Path $Path -Leaf) -Recurse -ErrorAction Ignore} | Sort-Object LastWriteTimeUtc -Descending | Select-Object -First 1
$Path_New = $Path
}
if ($Path_Old) {
if (Test-Path (Split-Path $Path_New)) {(Split-Path $Path_New) | Remove-Item -Recurse -Force}
(Split-Path $Path_Old) | Copy-Item -Destination (Split-Path $Path_New) -Recurse -Force
}
else {
if ($URI) {Write-Host -BackgroundColor Yellow -ForegroundColor Black "Cannot find $($Path) distributed at $($URI). "}
else {Write-Host -BackgroundColor Yellow -ForegroundColor Black "Cannot find $($Path). "}
}
}
}
}
Write-Progress -Activity "Downloader" -Completed