简体   繁体   中英

NSI and DetailPrint not logging

I am using the NSISLog plugin in my script with the DLL from the site installed in, however the log file is not written to.

Please advise what I am doing wrong?

!define COMPANYNAME "My Company"
!define APPNAME "My App"

InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}"
!define INSTALL_LOG_NAME "install.log"
!define INSTALL_LOG_PATH "$INSTDIR\${INSTALL_LOG_NAME}"
!define PRODUCT_NAME "${COMPANYNAME} ${APPNAME} ${VERSION}"
Name "${PRODUCT_NAME}"
OutFile "installer.exe"

!macro Log str
    MessageBox MB_OK "${str}." /SD IDOK
    ; Log to NSIS console
    DetailPrint "${str}"
    IfFileExists $INSTDIR 0 +2 ; check exists
    nsislog::log ${INSTALL_LOG_PATH} "${str}"
    ; Log to stdout
    System::Call 'kernel32::GetStdHandle(i -11)i.r9'
    System::Call 'kernel32::AttachConsole(i -1)'
    FileWrite $9 "${str}$\r$\n"
!macroend

Function .onInit
    MessageBox MB_OK "Start." /SD IDOK
FunctionEnd
 
Section
    SetOutPath $INSTDIR # define output path
    MessageBox MB_OK "Main." /SD IDOK
    nsislog::log "$INSTDIR\hello-main.txt" "hello"
    !insertmacro Log "$\rhello-main"
    File test.txt
    WriteUninstaller $INSTDIR\uninstaller.exe   # define uninstaller name
SectionEnd
 
Section "Uninstall"
    Delete $INSTDIR\test.txt # Delete installed file
    Delete $INSTDIR\uninstaller.exe # Delete the uninstaller
    RMDir $INSTDIR # Delete the directory
SectionEnd

I am running v3.08 and the flags are below:

PS C:\Program Files (x86)\NSIS> .\makensis.exe /HDRINFO
Size of first header is 28 bytes.
Size of main header is 300 bytes.
Size of each section is 2072 bytes.
Size of each page is 64 bytes.
Size of each instruction is 28 bytes.

Defined symbols: __GLOBAL__,NSIS_CHAR_SIZE=2,NSIS_COMPRESS_BZIP2_LEVEL=9,NSIS_CONFIG_COMPONENTPAGE,NSIS_CONFIG_COMPRESSION_SUPPORT,NSIS_CONFIG_CRC_SUPPORT,NSIS_CONFIG_ENHANCEDUI_SUPPORT,NSIS_CONFIG_LICENSEPAGE,NSIS_CONFIG_PLUGIN_SUPPORT,NSIS_CONFIG_SILENT_SUPPORT,NSIS_CONFIG_UNINSTALL_SUPPORT,NSIS_CONFIG_VISIBLE_SUPPORT,NSIS_CPU=x86,NSIS_DEFAULT_LANG=1033,NSIS_FIX_COMMENT_HANDLING,NSIS_IX86=400,NSIS_LOCKWINDOW_SUPPORT,NSIS_MAX_INST_TYPES=32,NSIS_MAX_STRLEN=1024,NSIS_PACKEDVERSION=0x03008000,NSIS_PTR_SIZE=4,NSIS_SUPPORT_ACTIVEXREG,NSIS_SUPPORT_BGBG,NSIS_SUPPORT_CODECALLBACKS,NSIS_SUPPORT_COPYFILES,NSIS_SUPPORT_CREATESHORTCUT,NSIS_SUPPORT_DELETE,NSIS_SUPPORT_ENVIRONMENT,NSIS_SUPPORT_EXECUTE,NSIS_SUPPORT_FILE,NSIS_SUPPORT_FILEFUNCTIONS,NSIS_SUPPORT_FINDFIRST,NSIS_SUPPORT_FNUTIL,NSIS_SUPPORT_GETDLLVERSION,NSIS_SUPPORT_GETFILETIME,NSIS_SUPPORT_HWNDS,NSIS_SUPPORT_INIFILES,NSIS_SUPPORT_INTOPTS,NSIS_SUPPORT_LANG_IN_STRINGS,NSIS_SUPPORT_MESSAGEBOX,NSIS_SUPPORT_MOVEONREBOOT,NSIS_SUPPORT_NAMED_USERVARS,NSIS_SUPPORT_REBOOT,NSIS_SUPPORT_REGISTRYFUNCTIONS,NSIS_SUPPORT_RENAME,NSIS_SUPPORT_RMDIR,NSIS_SUPPORT_SHELLEXECUTE,NSIS_SUPPORT_STACK,NSIS_SUPPORT_STANDARD_PREDEFINES,NSIS_SUPPORT_STROPTS,NSIS_SUPPORT_VERSION_INFO,NSIS_UNICODE,NSIS_UNICODE_MAKENSIS,NSIS_VARS_SECTION=.ndata,NSIS_VERSION=v3.08,NSIS_WIN32_MAKENSIS,NSISDIR=C:\Program Files (x86)\NSIS

That plug-in is not Unicode compatible. You could add Unicode False to the top of your.nsi script but ideally you should build a Unicode installer.

You can just replace the plug-in with a simple function:

!define FileAppendLine '!insertmacro FileAppendLine '
!macro FileAppendLine f l
Push "${l}"
Push "${f}"
Call FileAppendLine
!macroend
Function FileAppendLine
Exch $0
Exch
Exch $1
FileOpen $0 $0 a
StrCmp $0 "" err
FileSeek $0 0 END
!if "${NSIS_CHAR_SIZE}" > 1 ; Replace this with "!if 0" if you always want to force ASCII (not all strings might convert correctly)
FileWriteUTF16LE /BOM $0 $1
FileWriteUTF16LE $0 "$\r$\n"
!else
FileWrite $0 $1
FileWrite $0 "$\r$\n"
!endif
FileClose $0
err:
Pop $1
Pop $0
FunctionEnd


Section 
SetOutPath $InstDir
${FileAppendLine} "$InstDir\install.log" "Hello"
${FileAppendLine} "$InstDir\install.log" "World"
SectionEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM