refactor: better string handling in windows scripts

This commit is contained in:
zhom
2025-07-28 05:47:18 +04:00
parent 1ab0a41785
commit 8c7229b1a4
+3 -4
View File
@@ -223,14 +223,13 @@ set "TEMP_SCRIPT=%TEMP%\banderole-extract-!CURRENT_PID!.ps1"
rem Create PowerShell script file to avoid command line length issues
echo $scriptPath = "%~f0" > "!TEMP_SCRIPT!"
echo $content = Get-Content $scriptPath -Raw -Encoding UTF8 >> "!TEMP_SCRIPT!"
echo $content = [System.IO.File]::ReadAllText($scriptPath, [System.Text.Encoding]::UTF8) >> "!TEMP_SCRIPT!"
echo $dataMarker = '__DATA__' >> "!TEMP_SCRIPT!"
echo $dataStart = $content.IndexOf($dataMarker) >> "!TEMP_SCRIPT!"
echo if ($dataStart -eq -1) {{ Write-Error 'Data marker not found'; exit 1 }} >> "!TEMP_SCRIPT!"
echo $dataStart += $dataMarker.Length >> "!TEMP_SCRIPT!"
echo $data = $content.Substring($dataStart).Trim() >> "!TEMP_SCRIPT!"
echo $data = $data -replace '\r', '' >> "!TEMP_SCRIPT!"
echo $data = $data -replace '\n', '' >> "!TEMP_SCRIPT!"
echo $rawData = $content.Substring($dataStart) >> "!TEMP_SCRIPT!"
echo $data = ($rawData -split '[\r\n]+' ^| Where-Object {{ $_.Trim() -ne '' }}) -join '' >> "!TEMP_SCRIPT!"
echo if ([string]::IsNullOrWhiteSpace($data)) {{ Write-Error 'No data found after marker'; exit 1 }} >> "!TEMP_SCRIPT!"
echo try {{ >> "!TEMP_SCRIPT!"
echo [System.IO.File]::WriteAllBytes("%TEMP%\banderole-!CURRENT_PID!.zip", [System.Convert]::FromBase64String($data)) >> "!TEMP_SCRIPT!"