change Import-SamyChunk
This commit is contained in:
31
samy.ps1
31
samy.ps1
@@ -61,18 +61,33 @@ function Import-SamyChunk {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Url,
|
||||
[Parameter(Mandatory)][string]$Name
|
||||
[Parameter(Mandatory)][string]$Name,
|
||||
[Parameter(Mandatory)][string]$LocalPath
|
||||
)
|
||||
|
||||
Write-Host "[Info] Loading chunk: $Name" -ForegroundColor Cyan
|
||||
$content = (Invoke-WebRequest -UseBasicParsing -Uri $Url -ErrorAction Stop).Content
|
||||
try {
|
||||
# Download
|
||||
$content = (Invoke-WebRequest -UseBasicParsing -Uri $Url -ErrorAction Stop).Content
|
||||
if ([string]::IsNullOrWhiteSpace($content)) {
|
||||
throw "Downloaded content was empty."
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($content)) {
|
||||
throw "Downloaded content was empty."
|
||||
# Save (UTF-8 no BOM)
|
||||
$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