增加nsis中“Writeinistr”的缓冲区大小

时间:2016-09-19 14:45:35

标签: nsis

我是nsis的新手 创建包含“Text”类型的ini页面,使用此类型我在标签中显示了一些动态数据。文件大小为2 kb,因此我需要增加“Text”类型中“State”选项的大小。那么如何使用writeinistr来增加State的大小?

1 个答案:

答案 0 :(得分:0)

要绕过NSIS字符串长度限制,您必须直接调用Windows API:

Page Custom MyPage
Page InstFiles

!macro IniWriteAsciiStringPtr ini sec name strptr
!if "${NSIS_CHAR_SIZE}" > 1
Push $0
Push $1
Push $2
Push "${ini}"
Push "${name}"
Push "${sec}"
StrCpy $0 ${strptr}
System::Call 'kernel32::MultiByteToWideChar(i0, i0, i$0, i-1, i0, i0)i.r2'
System::Call '*(&w$2)i.r1'
System::Call 'kernel32::MultiByteToWideChar(i0, i0, i$0, i-1, ir1, ir2)'
System::Call 'kernel32::WritePrivateProfileString(t s, t s, ir1, t s)'
System::Free $1
Pop $2
Pop $1
Pop $0
!else
System::Call 'kernel32::WritePrivateProfileString(t "${sec}", t "${name}", i ${strptr}, t "${ini}")'
!endif
!macroend

!include InstallOptions.nsh
Function MyPage
InitPluginsDir
; Building the entire .ini at run-time in this example
WriteIniStr "$PluginsDir\io.ini" Settings NumFields 1
WriteIniStr "$PluginsDir\io.ini" "Field 1" Type Text
WriteIniStr "$PluginsDir\io.ini" "Field 1" Left 1 
WriteIniStr "$PluginsDir\io.ini" "Field 1" Right -2
WriteIniStr "$PluginsDir\io.ini" "Field 1" Top 5
WriteIniStr "$PluginsDir\io.ini" "Field 1" Bottom -10
WriteIniStr "$PluginsDir\io.ini" "Field 1" Flags MULTILINE
FileOpen $0 "$PluginsDir\test.txt" r
FileSeek $0 0 END $1
FileSeek $0 0 SET
System::Call '*(&i$1,i0)i.r2'
System::Call 'kernel32::ReadFile(ir0,ir2,ir1,*i,i0)'
!insertmacro IniWriteAsciiStringPtr "$PluginsDir\io.ini" "Field 1" "State" $2
System::Free $2
FileClose $0

!insertmacro INSTALLOPTIONS_DISPLAY "io.ini"
FunctionEnd

Function .onInit
InitPluginsDir
; Create a big file for this example
FileOpen $0 "$PluginsDir\test.txt" w
StrCpy $2 0
loop:
    StrCmp $2 2048 done
    IntOp $1 $2 % 10
    StrCmp $2 2047 0 +2
    StrCpy $1 "!"
    FileWrite $0 $1
    IntOp $2 $2 + 1
    Goto loop
done:
FileClose $0
FunctionEnd

您也可以绕过.ini并直接在对话框中设置:

Page Custom MyPage
Page InstFiles

!include InstallOptions.nsh
!include WinMessages.nsh
Function MyPage
InitPluginsDir
; Building the entire .ini at run-time in this example
WriteIniStr "$PluginsDir\io.ini" Settings NumFields 1
WriteIniStr "$PluginsDir\io.ini" "Field 1" Type Text
WriteIniStr "$PluginsDir\io.ini" "Field 1" Left 1 
WriteIniStr "$PluginsDir\io.ini" "Field 1" Right -2
WriteIniStr "$PluginsDir\io.ini" "Field 1" Top 5
WriteIniStr "$PluginsDir\io.ini" "Field 1" Bottom -10
WriteIniStr "$PluginsDir\io.ini" "Field 1" Flags MULTILINE
FileOpen $0 "$PluginsDir\test.txt" r
FileSeek $0 0 END $1
FileSeek $0 0 SET
System::Call '*(&i$1,i0)i.r2'
System::Call 'kernel32::ReadFile(ir0,ir2,ir1,*i,i0)'
FileClose $0
!insertmacro INSTALLOPTIONS_INITDIALOG "io.ini"
Pop $0
!insertmacro INSTALLOPTIONS_READ $0 "io.ini" "Field 1" "HWND"
!if "${NSIS_CHAR_SIZE}" > 1
!error TODO
!else
SendMessage $0 ${WM_SETTEXT} 0 $2
!endif
System::Free $2
!insertmacro INSTALLOPTIONS_SHOW
FunctionEnd

Function .onInit
InitPluginsDir
; Create a big file for this example
FileOpen $0 "$PluginsDir\test.txt" w
StrCpy $2 0
loop:
    StrCmp $2 2048 done
    IntOp $1 $2 % 10
    StrCmp $2 2047 0 +2
    StrCpy $1 "!"
    FileWrite $0 $1
    IntOp $2 $2 + 1
    Goto loop
done:
FileClose $0
FunctionEnd