From b6c796dd065395bd430c79d4fd21f8299420799e Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Sat, 31 Jan 2026 21:38:25 -0500 Subject: [PATCH] change Import-SamyChunk --- samy.ps1 | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/samy.ps1 b/samy.ps1 index 1fee120..a1928a0 100644 --- a/samy.ps1 +++ b/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 }