diff --git a/.bin/Scripts/borrowed/set-eol.ps1 b/.bin/Scripts/borrowed/set-eol.ps1 new file mode 100644 index 00000000..ef98a91d --- /dev/null +++ b/.bin/Scripts/borrowed/set-eol.ps1 @@ -0,0 +1,45 @@ +## Borrowed from https://ss64.com/ps/syntax-set-eol.html +# +# set-eol.ps1 +# Change the line endings of a text file to: Windows (CR/LF), Unix (LF) or Mac (CR) +# Requires PowerShell 3.0 or greater + +# Syntax +# ./set-eol.ps1 -lineEnding {mac|unix|win} -file FullFilename + +# mac, unix or win : The file endings desired. +# FullFilename : The full pathname of the file to be modified. + +# ./set-eol win "c:\demo\data.txt" + +[CmdletBinding()] +Param( + [Parameter(Mandatory=$True,Position=1)] + [ValidateSet("mac","unix","win")] + [string]$lineEnding, + [Parameter(Mandatory=$True)] + [string]$file +) + +# Convert the friendly name into a PowerShell EOL character +Switch ($lineEnding) { + "mac" { $eol="`r" } + "unix" { $eol="`n" } + "win" { $eol="`r`n" } +} + +# Replace CR+LF with LF +$text = [IO.File]::ReadAllText($file) -replace "`r`n", "`n" +[IO.File]::WriteAllText($file, $text) + +# Replace CR with LF +$text = [IO.File]::ReadAllText($file) -replace "`r", "`n" +[IO.File]::WriteAllText($file, $text) + +# At this point all line-endings should be LF. + +# Replace LF with intended EOL char +if ($eol -ne "`n") { + $text = [IO.File]::ReadAllText($file) -replace "`n", $eol + [IO.File]::WriteAllText($file, $text) +} diff --git a/Build Kit.cmd b/Build Kit.cmd index 063d34c6..8d82bb60 100644 --- a/Build Kit.cmd +++ b/Build Kit.cmd @@ -22,10 +22,15 @@ mkdir OUT_KIT\.cbin >nul 2>&1 attrib +h OUT_KIT\.bin >nul 2>&1 attrib +h OUT_KIT\.cbin >nul 2>&1 +:EnsureCRLF +rem Rewrite main.py using PowerShell to have CRLF/`r`n lineendings +set "script=OUT_KIT\.bin\Scripts\borrowed\set-eol.ps1" +set "main=OUT_KIT\.bin\Scripts\settings\main.py" +powershell -executionpolicy bypass -noprofile -file %script% -lineEndings win -file %main% || goto ErrorUnknown + :Launch -rem Calls the Launch.cmd script using the variables defined above -set "file=OUT_KIT\.bin\Scripts\build_kit.ps1" -powershell -executionpolicy bypass -noprofile -file %file% || goto ErrorUnknown +set "script=OUT_KIT\.bin\Scripts\build_kit.ps1" +powershell -executionpolicy bypass -noprofile -file %script% || goto ErrorUnknown goto Exit :: Functions :: diff --git a/Build PE.cmd b/Build PE.cmd index 49b04d4a..4c49be8a 100644 --- a/Build PE.cmd +++ b/Build PE.cmd @@ -17,8 +17,15 @@ if not exist "%dandi_set_env%" (goto ErrorKitNotFound) if not exist "%ps_script%" (goto ErrorPSScriptMissing) call "%dandi_set_env%" || goto ErrorUnknown +:EnsureCRLF +rem Rewrite main.py using PowerShell to have CRLF/`r`n lineendings +set "script=%~dp0\.bin\Scripts\borrowed\set-eol.ps1" +set "main=%~dp0\.bin\Scripts\settings\main.py" +powershell -executionpolicy bypass -noprofile -file %script% -lineEndings win -file %main% || goto ErrorUnknown + :Launch -PowerShell -ExecutionPolicy bypass -File %ps_script%" +set "script=%~dp0\.bin\Scripts\build_pe.ps1" +powershell -executionpolicy bypass -noprofile -file %script% || goto ErrorUnknown goto Exit :: Functions ::