我正在使用NSI创建设置 myproject.exe 的项目, 一切正常,但我想将显示的日志转储到文件中,也可以正常工作,但我的问题是我无法弄清楚何时调用日志函数
我的脚本中有12个部分,我有从Dump log to file
创建安装日志的功能 !define PRODUCT_NAME "myApplication"
!define PRODUCT_VERSION "1.7.1"
!define LVM_GETITEMCOUNT 0x1004
!define LVM_GETITEMTEXT 0x102D
!include MUI2.nsh
Name "myExe"
OutFile "C:\myExe.exe"
InstallDir $PROGRAMFILES\myprojc
InstallDirRegKey HKCU "Software\myprojc" "Install_Dir"
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\Folder-Options.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\Banner.bmp"
; Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;Languages
!insertmacro MUI_LANGUAGE "English"
BrandingText "myProj version 1.7.1"
;Here My section are decribed.. 12 of them
Section "main program and components" section1
;main promgram files are copied
SectionEnd
Section "other DLL" section2
;copy the DLLs
SectionEnd
Section "Text files" section3
;copy the required txt files
SectionEnd
;-....
;...
Section "install BDE admin" section12
;copy install BDE admin
;Calling the Dumplog function to create the log file
StrCpy $0 "$INSTDIR\Query\Presleyinstall.log"
Push $0
Call DumpLog
SectionEnd
;The function dumps the to a log file
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::Alloc ${NSIS_MAX_STRLEN}
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::SendMessageA(i, i, i, i) i \
($0, ${LVM_GETITEMTEXT}, $2, r1)"
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
FileWrite $5 "$4$\r$\n"
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
Exch $5
FunctionEnd
由于我在第12节中调用了 dumplog 功能,因此日志文件仅创建时/如果该部分被用户,如果未选择第12部分,则不会调用dumplog函数,也不会创建日志文件,
所以请告诉我如何调用dumplog函数而不管用户是否选择了该部分,即在安装完成时调用dumplog。
修改
我也可以尝试创建“创建安装程序日志”部分并检查并禁用
Section "Create installer log" section13
SectionIn RO
StrCpy $0 "$INSTDIR\myinstall.log"
Push $0
Call DumpLog
SectionEnd
这个
但有没有办法在没有部分和安装结束时调用dumplog函数?
答案 0 :(得分:2)
如果您没有给该部分命名(或使用-
开始名称),那么它将不会显示在组件页面上:
Section "Foobar"
;Install the optional Foobar
SectionEnd
Section
;Hidden section
Section
答案 1 :(得分:1)
你甚至可以把它放在回调函数中。
Function .onInstSuccess
;..
Call DumpLog
;..
FunctionEnd
Function .onInstFail
;..
Call DumpLog
;..
FunctionEnd