简体   繁体   English

Nullsoft安装程序(NSIS)获取价值并保存到文件

[英]Nullsoft Installer (NSIS) Get Value and save to file

am working on an installer for specific tinc-vpn installations. 正在为特定的tinc-vpn安装开发安装程序。 I need to have nullsoft installer ask me for two things: 我需要让nullsoft安装程序问我两件事:

  1. The VPN address VPN地址
  2. The name of the computer on the VPN network. VPN网络上的计算机的名称。

These values will be written to text files by the installer (that's a later step). 这些值将由安装程序写入文本文件(这是后续步骤)。

for now, I am trying to figure out how to access the vars once they have been put in. 现在,我正在尝试弄清楚一旦放入var后如何访问它们。

Here's what I have so far: 这是我到目前为止的内容:

 !include LogicLib.nsh
 !include nsDialogs.nsh

 Name nsDialogs
 OutFile nsDialogs.exe

 XPStyle on

 Var Dialog
 Var Label1
 Var Label2
 Var IPAddr
 Var VPNName

 Page custom nsDialogsPage nsDialogsPageLeave
 Page instfiles

 Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
    Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 12u "What's Your IP Address on the VPN?"
Pop $Label1

${NSD_CreateText} 0 12u 100% 12u ""
Pop $IPAddr

${NSD_CreateLabel} 0 24u 100% 12u "What's Your IP Address on the VPN?"
Pop $Label2

${NSD_CreateText} 0 36u 100% 12u ""
Pop $VPNName

nsDialogs::Show

 FunctionEnd

 Function nsDialogsPageLeave
${NSD_GetText} $VPNName $0
DetailPrint "VPN Name: $0"
 Function End

 Section

 SectionEnd

This, of course, fails in the compiler. 当然,这在编译器中会失败。 Does anyone know how to make this work? 有谁知道如何使这项工作? I just want to do something simple: prompt for a text value, then store that text value in a text file, and copy that file to a desination... 我只想做一些简单的事情:提示输入文本值,然后将该文本值存储在文本文件中,然后将该文件复制到目标位置...

There were some syntax errors in your script. 您的脚本中存在一些语法错误。

How do you compile your file? 您如何编译文件? Do you use some editor - HM NIS Edit, Visual Studio or pure notepad? 您是否使用某些编辑器-HM NIS Edit,Visual Studio或纯记事本?

In all cases NSIS compiles tells you where (which line) the error is. 在所有情况下,NSIS编译都会告诉您错误在哪里(哪一行)。

Here is fixed script: 这是固定的脚本:

!include LogicLib.nsh
 !include nsDialogs.nsh

 Name nsDialogs
 OutFile nsDialogs.exe

 XPStyle on

 Var Dialog
 Var Label1
 Var Label2
 Var IPAddr
 Var VPNName

 Page custom nsDialogsPage nsDialogsPageLeave
 Page instfiles

 Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog

${If} $Dialog == error
    Abort
${EndIf}

${NSD_CreateLabel} 0 0 100% 12u "What's Your IP Address on the VPN?"
Pop $Label1

${NSD_CreateText} 0 12u 100% 12u ""
Pop $IPAddr

${NSD_CreateLabel} 0 24u 100% 12u "What's Your VPN name?"
Pop $Label2

${NSD_CreateText} 0 36u 100% 12u ""
Pop $VPNName

nsDialogs::Show

 FunctionEnd

 Function nsDialogsPageLeave
${NSD_GetText} $VPNName $0
${NSD_GetText} $IPAddr $1
MessageBox MB_OK "VPN Name: $0, IP: $1"
 FunctionEnd

 Section main

 SectionEnd

Use MessageBox instead of DetailPrint because DetailPrint is used to add messages into install page and you want to show something when install page is not initialized yet. 使用MessageBox而不是DetailPrint,因为DetailPrint用于将消息添加到安装页面中,并且您要在尚未初始化安装页面时显示一些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM