The question is this:
While the FileRead successfully stores in the variable an empty line, the FileWrite assumes that the variable is empty so does not add the empty line to the new file. Examine the example below for details as it become complicated to explain it.
If I don't execute TrimNewLines then the text reproduced correctly in the new text file, but no in the log window where I can see the symbols of return and new line.
If I do execute TrimNewLines then the text displayed correctly in the log window (with empy lines where they exist) but the filewrite does not catch the empty line stored into the variable, so I have to add $\r$\n in order to reproduce the original text structure.
Eh!
!include TextFunc.nsh
!insertmacro TrimNewLines
showinstdetails show
OutFile licopy.exe
Section
SetDetailsPrint none
IfFileExists '$EXEDIR\LicenseCopy.txt' 0 +2
Delete '$EXEDIR\LicenseCopy.txt'
FileOpen $0 "${NSISDIR}\license.txt" r ; file to read
FileOpen $R2 '$EXEDIR\LicenseCopy.txt' w ; file to write
SetDetailsPrint listonly
start:
FileRead $0 $1
StrCmp $1 '' end
;${TrimNewLines} '$1' '$1'
;StrCmp $1 '' 0 +2
;FileWrite $R2 '$\r$\n$\r$\n'
FileWrite $R2 '$1'
FileSeek $R2 '0' END
DetailPrint '$1'
goto start
end:
SetDetailsPrint none
FileClose $0
FileClose $R2
SectionEnd