Archive: Problem with DumpLog and NSIS 2.38-1 Unicode


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 ?


*bump*

Anyone? :)


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.


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?


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.


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.

:up: :up: :up: :up:

This one works, thanks a lot.