[英]NSI and DetailPrint not logging
我在我的腳本中使用NSISLog 插件和來自安裝的站點的 DLL,但是沒有寫入日志文件。
請指教我做錯了什么?
!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
我正在運行 v3.08,標志如下:
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
該插件與 Unicode 不兼容。 您可以將Unicode False
添加到您的.nsi 腳本的頂部,但理想情況下,您應該構建一個 Unicode 安裝程序。
只需用簡單的 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.