将输入变量从“自定义”页面传递到NSIS中的“节”

时间:2018-07-11 19:08:05

标签: nsis

下面是我编写的程序,该程序利用了Wiki中的给定IpConfig函数。我试图让用户输入文本文件($ Text)的名称,然后用该计算机的ipconfig信息填充该文本文件。这可以在命令提示符下轻松完成,但是我的目标是希望它可以在NSIS上运行。我能够使用DumpLog转储从detailprints获取的所有数据。此函数生成我需要的.txt文件。我正在努力让用户设置此.txt文件的名称。

我的问题是程序在第一个自定义页面之后结束。我可以输入文件名,但必须先关闭文件,然后程序中止。我尝试创建CustomLeave页面,但是无法将ipconfig函数与其集成。

不幸的是,即使在进行了进一步的重组之后,我也可以创建文本文件,而没有一个完全用所需数据填充的名称,这告诉我正在传递一个空的“ Text”名称变量。

感谢您的帮助!谢谢。

!addplugindir "${NSISDIR}\Plugins\x86-unicode"
!addplugindir "${NSISDIR}\Plugins\x86-ansi"
!addplugindir "${NSISDIR}\Plugins"

!include "LogicLib.nsh"
!include "MUI2.nsh"
!include "winMessages.nsh"
!include "nsDialogs.nsh"

!Macro ShowResult ItemString
    Pop $0 
    Pop $1
    ${if} $0 == "ok"
        DetailPrint "${ItemString} $1"
    ${Else}
        DetailPrint "${ItemString} Error: $1"
    ${EndIf}
!MacroEnd

!Macro ShowMultiResult ItemString
    Pop $0 
    Pop $1
    ${if} $0 != "ok"
        DetailPrint "${ItemString} Error: $1"
    ${EndIf}
!MacroEnd


    ;!define LVM_GETITEMCOUNT 0x1004
    ;!define LVM_GETITEMTEXT 0x102D

!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "Some location.bmp" 
!define MUI_HEADERIMAGE_RIGHT
!insertmacro MUI_LANGUAGE "English" 

OutFile "something.exe"


Page custom custompage
Var dialog
Var Label
Var Text
Var TextBox


Function custompage 
    !insertmacro MUI_HEADER_TEXT "Something" "Tool" 

        nsDialogs::Create 1018
            Pop $dialog

        ${NSD_CreateLabel} 0 0 100% 12u "enter text name"
            Pop $Label

        ${NSD_CreateText} 0 12u 93% 12u $Text
            Pop $TextBox

    nsDialogs::Show

FunctionEnd



Section

    DetailPrint "Windows IP-configuration"
    DetailPrint ""
    IpConfig::GetHostName
    !InsertMacro ShowResult "     Host Name.......................:"
    IpConfig::GetPrimaryDNSSuffix
    !InsertMacro ShowResult "     Primary DNS Suffix..............:"
    IpConfig::GetNodeType
    !InsertMacro ShowResult "     Node Type.......................:"
    IpConfig::IsIPRoutingEnabled
    !InsertMacro ShowResult "     IP Routing Enabled..............:"
    IpConfig::IsWINSProxyEnabled
    !InsertMacro ShowResult "     WINS Proxy Enabled..............:"
    IpConfig::GetDNSSuffixSearchList
    !InsertMacro ShowResult "     DNS Suffix Search List..........:"
    DetailPrint ""
    GetFunctionAddress $2 EnabledAdaptersCallback
    IpConfig::GetEnabledNetworkAdaptersIDsCB $2
    !InsertMacro ShowMultiResult "     GetEnabledNetworkAdaptersIDs:"


    StrCpy $0 "$Desktop\$Text.txt"
    Push $0
    Call DumpLog


SectionEnd

下面为DumpLog和IPConfig复制的功能-为清楚起见,已删除。 ================================================== =====================

1 个答案:

答案 0 :(得分:0)

首先,将所有!addplugindir指令放在脚本开头不是一个好主意,如果您调用了错误的插件类型,安装程序将崩溃!

您的安装程序将在第一页之后结束,因为您只有一页!

使用DumpLog似乎是毫无意义的工作,如果需要,您可以直接写入文件。

OutFile test.exe
RequestExecutionLevel user

!include "MUI2.nsh"
!include "nsDialogs.nsh"


!insertmacro MUI_PAGE_WELCOME
Page custom custompage custompageleave
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

Var ConfigFile
Var TextBox

Function .onInit
StrCpy $ConfigFile "Text.txt" ; Set default
FunctionEnd

Function custompage 
    !insertmacro MUI_HEADER_TEXT "Something" "Tool" 

    nsDialogs::Create 1018
    Pop $0

    ${NSD_CreateLabel} 0 0 100% 12u "enter text name"
    Pop $0

    ${NSD_CreateText} 0 12u 93% 12u $ConfigFile
    Pop $TextBox

    nsDialogs::Show
FunctionEnd

Function custompageleave
${NSD_GetText} $TextBox $ConfigFile
FunctionEnd


Section
    FileOpen $5 "$Desktop\$ConfigFile" w ; Forcing $Desktop is a bit weird, user should be able to choose a full path?
    FileWrite $5 "Hello$\r$\n"
    FileWrite $5 "World$\r$\n"
    FileClose $5
SectionEnd

如果要显示输出并保存它,则使用DumpLog很好。