Updated to accept first argument as a URL. E.g. https://raiza.dev/Downloads/y2k12-something.txt
This commit is contained in:
parent
b91579f15c
commit
df5dc8240d
2 changed files with 39 additions and 3 deletions
|
@ -4,6 +4,5 @@
|
|||
<OpenFolders />
|
||||
<OpenFiles>
|
||||
<File>downloader.ps1</File>
|
||||
<File>Startup.pss</File>
|
||||
</OpenFiles>
|
||||
</ProjectState>
|
|
@ -60,5 +60,42 @@ class Catbox {
|
|||
}
|
||||
}
|
||||
|
||||
$catbox = [Catbox]::new()
|
||||
$catbox.Download()
|
||||
If ($args.Length -eq 1 -and $args[0] -and $args[0].ToString().Contains("https://raiza.dev/Downloads/y2k12-") -and $args[0].ToString().EndsWith(".txt"))
|
||||
{
|
||||
$statuscode = 404
|
||||
$file = $null
|
||||
|
||||
try
|
||||
{
|
||||
$statuscode = (Invoke-WebRequest -Uri $args[0] -UseBasicParsing | Select-Object StatusCode).StatusCode
|
||||
$file = $args[0].Substring($args[0].IndexOf(".dev/Downloads/") + 15)
|
||||
|
||||
Write-Host "Downloading" $file "..."
|
||||
}
|
||||
catch
|
||||
{
|
||||
$statuscode = 404
|
||||
$file = $null
|
||||
}
|
||||
finally
|
||||
{
|
||||
If ($statuscode -eq 200 -and $file)
|
||||
{
|
||||
Invoke-WebRequest -Uri $args[0] -OutFile $file
|
||||
|
||||
Write-Host ""
|
||||
|
||||
$catbox = [Catbox]::new()
|
||||
$catbox.Download()
|
||||
}
|
||||
Else
|
||||
{
|
||||
Write-Host "File not found on the server."
|
||||
}
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
$catbox = [Catbox]::new()
|
||||
$catbox.Download()
|
||||
}
|
Loading…
Add table
Reference in a new issue