将输入变量从自定义页面传递到 NSIS 中的部分
Passing input variables from Custom pages to Sections in NSIS
下面是我编写的一个程序,它利用了 wiki 中给定的 IpConfig 函数。我试图让用户输入文本文件的名称($Text),然后用计算机的 ipconfig 信息填充该文本文件。这可以在命令提示符下轻松完成,但我的目标是希望它能在 NSIS 上运行。我能够使用 DumpLog 转储从细节打印中获取的所有数据。此函数生成我需要的 .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 [=10=]
Pop
${if} [=10=] == "ok"
DetailPrint "${ItemString} "
${Else}
DetailPrint "${ItemString} Error: "
${EndIf}
!MacroEnd
!Macro ShowMultiResult ItemString
Pop [=10=]
Pop
${if} [=10=] != "ok"
DetailPrint "${ItemString} Error: "
${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 EnabledAdaptersCallback
IpConfig::GetEnabledNetworkAdaptersIDsCB
!InsertMacro ShowMultiResult " GetEnabledNetworkAdaptersIDs:"
StrCpy [=10=] "$Desktop$Text.txt"
Push [=10=]
Call DumpLog
SectionEnd
下面为 DumpLog 和 IPConfig 复制的函数 - 为清楚起见已删除。 ================================================ ======================
首先,将所有这些 !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 [=10=]
${NSD_CreateLabel} 0 0 100% 12u "enter text name"
Pop [=10=]
${NSD_CreateText} 0 12u 93% 12u $ConfigFile
Pop $TextBox
nsDialogs::Show
FunctionEnd
Function custompageleave
${NSD_GetText} $TextBox $ConfigFile
FunctionEnd
Section
FileOpen "$Desktop$ConfigFile" w ; Forcing $Desktop is a bit weird, user should be able to choose a full path?
FileWrite "Hello$\r$\n"
FileWrite "World$\r$\n"
FileClose
SectionEnd
如果你想显示输出并保存它,使用 DumpLog 是很好的。
下面是我编写的一个程序,它利用了 wiki 中给定的 IpConfig 函数。我试图让用户输入文本文件的名称($Text),然后用计算机的 ipconfig 信息填充该文本文件。这可以在命令提示符下轻松完成,但我的目标是希望它能在 NSIS 上运行。我能够使用 DumpLog 转储从细节打印中获取的所有数据。此函数生成我需要的 .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 [=10=]
Pop
${if} [=10=] == "ok"
DetailPrint "${ItemString} "
${Else}
DetailPrint "${ItemString} Error: "
${EndIf}
!MacroEnd
!Macro ShowMultiResult ItemString
Pop [=10=]
Pop
${if} [=10=] != "ok"
DetailPrint "${ItemString} Error: "
${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 EnabledAdaptersCallback
IpConfig::GetEnabledNetworkAdaptersIDsCB
!InsertMacro ShowMultiResult " GetEnabledNetworkAdaptersIDs:"
StrCpy [=10=] "$Desktop$Text.txt"
Push [=10=]
Call DumpLog
SectionEnd
下面为 DumpLog 和 IPConfig 复制的函数 - 为清楚起见已删除。 ================================================ ======================
首先,将所有这些 !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 [=10=]
${NSD_CreateLabel} 0 0 100% 12u "enter text name"
Pop [=10=]
${NSD_CreateText} 0 12u 93% 12u $ConfigFile
Pop $TextBox
nsDialogs::Show
FunctionEnd
Function custompageleave
${NSD_GetText} $TextBox $ConfigFile
FunctionEnd
Section
FileOpen "$Desktop$ConfigFile" w ; Forcing $Desktop is a bit weird, user should be able to choose a full path?
FileWrite "Hello$\r$\n"
FileWrite "World$\r$\n"
FileClose
SectionEnd
如果你想显示输出并保存它,使用 DumpLog 是很好的。