【问题标题】:Passing input variables from Custom pages to Sections in NSIS将输入变量从自定义页面传递到 NSIS 中的部分
【发布时间】:2018-07-11 19:08:05
【问题描述】:

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

我遇到的问题是程序在第一个自定义页面之后结束。我可以输入文件的名称,但必须点击关闭并且程序中止。我已尝试创建 CustomLeave 页面,但无法将 ipconfig 功能与其集成。

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

感谢您的帮助!谢谢。

!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 函数 - 为清楚起见已删除。 ================================================== =======================

【问题讨论】:

    标签: nsis


    【解决方案1】:

    首先,将所有这些!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 很好。

    【讨论】:

    • 非常感谢!我只是强迫 $Desktop 进行自我测试。我已经编辑了我的代码并合并了您的 cmets,现在它可以完美运行了。欣赏它
    猜你喜欢
    • 2021-01-26
    • 2017-08-03
    • 2021-10-10
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    • 2017-01-07
    • 2018-04-13
    • 2023-03-11
    相关资源
    最近更新 更多