NSIS:为什么 "Text" 来自文本框的值变成了数字?
NSIS : Why "Text" from text box value became numeric?
我创建了一个自定义页面(.nsh)
,有 3 个文本框 (url, user, password)
供用户在其中输入,.NSI
文件会将这些数据写入属性文件.
但是那些文字变成了数字这样9502966, 4718976 and 8455398.
我该怎么办?
这是我的示例代码:
AcustomPage.nsh
...
!macro create_AcustomPage APP_NAME CUS_URL CUS_USER CUS_PWD
Page custom create_AcustomPage
Function create_AcustomPage
...
${NSD_CreateText} 60u 50u 60% 11u "${CUS_URL}"
Pop $AcustomPage.url
${NSD_CreateText} 60u 50u 60% 11u "${CUS_USER}"
Pop $AcustomPage.user
${NSD_CreateText} 60u 50u 60% 11u "${CUS_PWD}"
Pop $AcustomPage.pwd
...
FunctionEnd
...
!macroend
Project.nsi
...
!insertmacro create_AcustomPage "${NAME} ${VERSION}-${RELEASE}" "url.localhost" "username" "password"
...
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_url=" "$CUS_URL" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_user=" "$CUS_USER" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_password=" "$CUS_PWD" $R0
结果#configure.properties
addi_url=18940788
addi_user=6750598
addi_password=11469950
但应该是:
addi_url=usl.localhost
addi_user=username
addi_password=password
谢谢,
我猜你正在将控件句柄写入文件,但由于你的示例代码很差,所以不可能知道。
它应该看起来像这样:
InstallDir "$Temp\Test"
!include TextFunc.nsh
!include nsDialogs.nsh
var hCtlUrl
var hCtlUsr
var hCtlPwd
!define DefaultUrl "url.localhost"
!define DefaultUsr "foo"
!define DefaultPwd "bar"
Function mypageCreate
nsDialogs::Create 1018
Pop [=10=]
${NSD_CreateText} 60u 30u 60% 11u "${DefaultUrl}"
Pop $hCtlUrl
${NSD_CreateText} 60u 50u 60% 11u "${DefaultUsr}"
Pop $hCtlUsr
${NSD_CreateText} 60u 70u 60% 11u "${DefaultPwd}"
Pop $hCtlPwd
nsDialogs::Show
FunctionEnd
Function mypageLeave
${NSD_GetText} $hCtlUrl [=10=]
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_url=" "[=10=]" $R0
${NSD_GetText} $hCtlUsr [=10=]
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_user=" "[=10=]" $R0
${NSD_GetText} $hCtlPwd [=10=]
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_password=" "[=10=]" $R0
FunctionEnd
Page Directory
Page InstFiles
Page Custom mypageCreate mypageLeave
首先,您需要变量来存储控件的 HWND。您的自定义页面还需要一个 "leave" 函数。它将在用户单击下一步按钮时执行。该函数必须读取文本控件。像这样:
Var customer_url
Var customer_user
Var customer_password
Page custom create_AcustomPage leave_AcustomPage
Function create_AcustomPage
...
${NSD_CreateText} 60u 50u 60% 11u "Type your url..."
Pop [=10=]
${NSD_CreateText} 60u 50u 60% 11u "Type your username..."
Pop
${NSD_CreateText} 60u 50u 60% 11u "Type your password..."
Pop
...
FunctionEnd
Function leave_AcustomPage
# Read form
${NSD_GetText} [=10=] $customer_url
${NSD_GetText} $customer_user
${NSD_GetText} $customer_password
# save form to config file
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_url=" "$customer_url" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_user=" "$customer_user" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_password=" "$customer_password" $R0
FunctionEnd
我创建了一个自定义页面(.nsh)
,有 3 个文本框 (url, user, password)
供用户在其中输入,.NSI
文件会将这些数据写入属性文件.
但是那些文字变成了数字这样9502966, 4718976 and 8455398.
我该怎么办?
这是我的示例代码:
AcustomPage.nsh
...
!macro create_AcustomPage APP_NAME CUS_URL CUS_USER CUS_PWD
Page custom create_AcustomPage
Function create_AcustomPage
...
${NSD_CreateText} 60u 50u 60% 11u "${CUS_URL}"
Pop $AcustomPage.url
${NSD_CreateText} 60u 50u 60% 11u "${CUS_USER}"
Pop $AcustomPage.user
${NSD_CreateText} 60u 50u 60% 11u "${CUS_PWD}"
Pop $AcustomPage.pwd
...
FunctionEnd
...
!macroend
Project.nsi
...
!insertmacro create_AcustomPage "${NAME} ${VERSION}-${RELEASE}" "url.localhost" "username" "password"
...
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_url=" "$CUS_URL" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_user=" "$CUS_USER" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_password=" "$CUS_PWD" $R0
结果#configure.properties
addi_url=18940788
addi_user=6750598
addi_password=11469950
但应该是:
addi_url=usl.localhost
addi_user=username
addi_password=password
谢谢,
我猜你正在将控件句柄写入文件,但由于你的示例代码很差,所以不可能知道。
它应该看起来像这样:
InstallDir "$Temp\Test"
!include TextFunc.nsh
!include nsDialogs.nsh
var hCtlUrl
var hCtlUsr
var hCtlPwd
!define DefaultUrl "url.localhost"
!define DefaultUsr "foo"
!define DefaultPwd "bar"
Function mypageCreate
nsDialogs::Create 1018
Pop [=10=]
${NSD_CreateText} 60u 30u 60% 11u "${DefaultUrl}"
Pop $hCtlUrl
${NSD_CreateText} 60u 50u 60% 11u "${DefaultUsr}"
Pop $hCtlUsr
${NSD_CreateText} 60u 70u 60% 11u "${DefaultPwd}"
Pop $hCtlPwd
nsDialogs::Show
FunctionEnd
Function mypageLeave
${NSD_GetText} $hCtlUrl [=10=]
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_url=" "[=10=]" $R0
${NSD_GetText} $hCtlUsr [=10=]
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_user=" "[=10=]" $R0
${NSD_GetText} $hCtlPwd [=10=]
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_password=" "[=10=]" $R0
FunctionEnd
Page Directory
Page InstFiles
Page Custom mypageCreate mypageLeave
首先,您需要变量来存储控件的 HWND。您的自定义页面还需要一个 "leave" 函数。它将在用户单击下一步按钮时执行。该函数必须读取文本控件。像这样:
Var customer_url
Var customer_user
Var customer_password
Page custom create_AcustomPage leave_AcustomPage
Function create_AcustomPage
...
${NSD_CreateText} 60u 50u 60% 11u "Type your url..."
Pop [=10=]
${NSD_CreateText} 60u 50u 60% 11u "Type your username..."
Pop
${NSD_CreateText} 60u 50u 60% 11u "Type your password..."
Pop
...
FunctionEnd
Function leave_AcustomPage
# Read form
${NSD_GetText} [=10=] $customer_url
${NSD_GetText} $customer_user
${NSD_GetText} $customer_password
# save form to config file
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_url=" "$customer_url" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_user=" "$customer_user" $R0
${ConfigWriteS} "$INSTDIR\configure.properties" "custom_password=" "$customer_password" $R0
FunctionEnd