change Import-SamyChunk
This commit is contained in:
31
samy.ps1
31
samy.ps1
@@ -61,18 +61,33 @@ function Import-SamyChunk {
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[Parameter(Mandatory)][string]$Url,
|
[Parameter(Mandatory)][string]$Url,
|
||||||
[Parameter(Mandatory)][string]$Name
|
[Parameter(Mandatory)][string]$Name,
|
||||||
|
[Parameter(Mandatory)][string]$LocalPath
|
||||||
)
|
)
|
||||||
|
|
||||||
Write-Host "[Info] Loading chunk: $Name" -ForegroundColor Cyan
|
try {
|
||||||
$content = (Invoke-WebRequest -UseBasicParsing -Uri $Url -ErrorAction Stop).Content
|
# Download
|
||||||
|
$content = (Invoke-WebRequest -UseBasicParsing -Uri $Url -ErrorAction Stop).Content
|
||||||
|
if ([string]::IsNullOrWhiteSpace($content)) {
|
||||||
|
throw "Downloaded content was empty."
|
||||||
|
}
|
||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($content)) {
|
# Save (UTF-8 no BOM)
|
||||||
throw "Downloaded content was empty."
|
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
||||||
|
[System.IO.File]::WriteAllText($LocalPath, $content, $utf8NoBom)
|
||||||
|
|
||||||
|
# Load
|
||||||
|
. $LocalPath
|
||||||
|
|
||||||
|
Write-Host ("[Success] {0}" -f $Name) -ForegroundColor Green
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$msg = $_.Exception.Message
|
||||||
|
if ([string]::IsNullOrWhiteSpace($msg)) { $msg = "$_" }
|
||||||
|
Write-Host ("[Failed] {0}: {1}" -f $Name, $msg) -ForegroundColor Red
|
||||||
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "[Success] Downloaded: $Name" -ForegroundColor Green
|
|
||||||
return $content
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user