xbarns
24th November 2008 11:14 UTC
Problem with DumpLog and NSIS 2.38-1 Unicode
Hi all,
i have a little problem, i am using the DumpLog function as described here http://nsis.sourceforge.net/Docs/AppendixD.html#D.4. Now i switched from 2.37-1 Unicode to 2.38-Unicode NSIS and suddenly that DumpLog now only produces a lot of ??? in the logfile instead of dumping the log (well i guess it is the log just not readable anymore).
When i go back to 2.37-1 it works fine, the Problem is that 2.37-1 has other errors that prevent me from using it. (I get cut off strings when reading nsdialog text fields.)
Any Ideas ?
xbarns
28th November 2008 12:37 UTC
*bump*
Anyone? :)
kichik
28th November 2008 14:58 UTC
Try adding a message box with the data written to the file before it's written (before the FileWrite line). That would tell you if the problem is with the System plug-in or FileWrite. If it's with FileWrite, try opening the text file with a different editor. Notepad should probably work the best.
xbarns
28th November 2008 18:01 UTC
Well the Messagebox gives me a bunch of squares, so i guess its not the Filewrite but rather the System Plug-in.
The system.dlls do look the same, but when i replaced the 2.38 with the 2.37 one it works.
Can i just use the one from 2.37 or are there significant changes that i have to look out for?
kichik
28th November 2008 18:13 UTC
There were no changes in the official version's System plug-in on that version, so I guess the change was made in the Unicode branch. You'll have to ask Jim Park.
jimpark
6th January 2009 18:34 UTC
There are several problems with the DumpLog function that needs to be fixed. For one, the LVM_GETITEMTEXT message ID used there is for getting the ANSI string. You need a different message ID for getting the Unicode string. And secondly, when you allocate memory for the string, you have to remember that you need sizeof(wchar_t) * NSIS_MAX_STRLEN. And thirdly, when writing out a Unicode text file, you want to write out the BOM first. Here's the modified DumpLog for Unicode NSIS:
!define LVM_GETITEMCOUNT 0x1004
!define LVM_GETITEMTEXT 0x1073
Function DumpLog
Exch $5
Push $0
Push $1
Push $2
Push $3
Push $4
Push $6
Push $7
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1016
StrCmp $0 0 error
FileOpen $5 $5 "w"
FileWriteWord $5 0xfeff ; Write the BOM
StrCmp $5 0 error
SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6
IntOp $7 ${NSIS_MAX_STRLEN} * 2
System::Alloc $7
Pop $3
StrCpy $2 0
System::Call "*(i, i, i, i, i, i, i, i, i) i \
(0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
loop: StrCmp $2 $6 done
System::Call "User32::SendMessageW(i, i, i, i) i \
($0, ${LVM_GETITEMTEXT}, $2, r1)"
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
FileWriteUTF16LE $5 "$4$\r$\n"
IntOp $2 $2 + 1
Goto loop
done:
FileClose $5
System::Free $1
System::Free $3
Goto exit
error:
MessageBox MB_OK error
exit:
Pop $7
Pop $6
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Exch $5
FunctionEnd
So the lesson is when using System calls, we have to be really careful about porting the ANSI NSI script to Unicode. A lot of the math involved with memory, the message IDs being used etc. all need to be correct.
xbarns
6th January 2009 20:03 UTC
:up: :up: :up: :up:
This one works, thanks a lot.