Dump log to file: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
m (→The Function: Last one?) |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{ | {{PageAuthor|KiCHiK}} | ||
== Description == | == Description == | ||
This function will dump the log of the installer (installer details) to a file of your choice. I created this function for Afrow_UK who requested a way to dump the log to a file in [http://forums.winamp.com/showthread.php?s=&threadid=125431 this forum thread]. | This function will dump the log of the installer (installer details) to a file of your choice. I created this function for Afrow_UK who requested a way to dump the log to a file in [http://forums.winamp.com/showthread.php?s=&threadid=125431 this forum thread]. | ||
This function will not work in silent mode. | '''This function will not work when your installer is run in silent mode.''' | ||
== How To Use ==
To use it push a file name and call it. It will dump the log to the file specified. For example: | |||
<highlight-nsis>GetTempFileName $0
Push $0
Call DumpLog
</highlight-nsis> | == How To Use == | ||
To use it push a file name and call it. It will dump the log to the file specified. For example: | |||
<highlight-nsis>GetTempFileName $0 | |||
Push $0 | |||
Call DumpLog | |||
</highlight-nsis> | |||
Or: | |||
<highlight-nsis>StrCpy $0 "$EXEDIR\install.log" | |||
Push $0 | |||
Call DumpLog | |||
</highlight-nsis> | |||
== The Function == | == The Function == | ||
Here is the function: | Here is the function: | ||
<highlight-nsis> | <highlight-nsis> | ||
!define LVM_GETITEMCOUNT 0x1004 | !define /IfNDef LVM_GETITEMCOUNT 0x1004 | ||
!define LVM_GETITEMTEXT | !define /IfNDef LVM_GETITEMTEXTA 0x102D | ||
!define /IfNDef LVM_GETITEMTEXTW 0x1073 | |||
!if "${NSIS_CHAR_SIZE}" > 1 | |||
!define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTW} | |||
!else | |||
!define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTA} | |||
!endif | |||
Function DumpLog | Function DumpLog | ||
Exch $5 | Exch $5 | ||
Line 22: | Line 37: | ||
Push $4 | Push $4 | ||
Push $6 | Push $6 | ||
FindWindow $0 "#32770" "" $HWNDPARENT | FindWindow $0 "#32770" "" $HWNDPARENT | ||
GetDlgItem $0 $0 1016 | GetDlgItem $0 $0 1016 | ||
Line 29: | Line 43: | ||
StrCmp $5 "" exit | StrCmp $5 "" exit | ||
SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6 | SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6 | ||
System:: | System::Call '*(&t${NSIS_MAX_STRLEN})p.r3' | ||
StrCpy $2 0 | StrCpy $2 0 | ||
System::Call "*(i, i, i, i, i, | System::Call "*(i, i, i, i, i, p, i, i, i) p (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1" | ||
loop: StrCmp $2 $6 done | loop: StrCmp $2 $6 done | ||
System::Call "User32:: | System::Call "User32::SendMessage(p, i, p, p) p ($0, ${LVM_GETITEMTEXT}, $2, r1)" | ||
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)" | System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)" | ||
FileWrite $5 "$4$\r$\n" | !ifdef DumpLog_As_UTF16LE | ||
FileWriteUTF16LE ${DumpLog_As_UTF16LE} $5 "$4$\r$\n" | |||
!else | |||
FileWrite $5 "$4$\r$\n" ; Unicode will be translated to ANSI! | |||
!endif | |||
IntOp $2 $2 + 1 | IntOp $2 $2 + 1 | ||
Goto loop | Goto loop | ||
Line 52: | Line 67: | ||
Pop $1 | Pop $1 | ||
Pop $0 | Pop $0 | ||
Pop $5 | |||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Logging Functions]] |
Latest revision as of 10:18, 12 August 2021
Author: KiCHiK (talk, contrib) |
Description
This function will dump the log of the installer (installer details) to a file of your choice. I created this function for Afrow_UK who requested a way to dump the log to a file in this forum thread. This function will not work when your installer is run in silent mode.
How To Use
To use it push a file name and call it. It will dump the log to the file specified. For example:
GetTempFileName $0 Push $0 Call DumpLog
Or:
StrCpy $0 "$EXEDIR\install.log" Push $0 Call DumpLog
The Function
Here is the function:
!define /IfNDef LVM_GETITEMCOUNT 0x1004 !define /IfNDef LVM_GETITEMTEXTA 0x102D !define /IfNDef LVM_GETITEMTEXTW 0x1073 !if "${NSIS_CHAR_SIZE}" > 1 !define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTW} !else !define /IfNDef LVM_GETITEMTEXT ${LVM_GETITEMTEXTA} !endif Function DumpLog Exch $5 Push $0 Push $1 Push $2 Push $3 Push $4 Push $6 FindWindow $0 "#32770" "" $HWNDPARENT GetDlgItem $0 $0 1016 StrCmp $0 0 exit FileOpen $5 $5 "w" StrCmp $5 "" exit SendMessage $0 ${LVM_GETITEMCOUNT} 0 0 $6 System::Call '*(&t${NSIS_MAX_STRLEN})p.r3' StrCpy $2 0 System::Call "*(i, i, i, i, i, p, i, i, i) p (0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1" loop: StrCmp $2 $6 done System::Call "User32::SendMessage(p, i, p, p) p ($0, ${LVM_GETITEMTEXT}, $2, r1)" System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)" !ifdef DumpLog_As_UTF16LE FileWriteUTF16LE ${DumpLog_As_UTF16LE} $5 "$4$\r$\n" !else FileWrite $5 "$4$\r$\n" ; Unicode will be translated to ANSI! !endif IntOp $2 $2 + 1 Goto loop done: FileClose $5 System::Free $1 System::Free $3 exit: Pop $6 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 Pop $5 FunctionEnd