NSIS:页面离开功能中止后页面出错

NSIS: Error in page after abort from page leave function

我有一个 NSIS 脚本来复制 .NET 应用程序构建并在 SQL 数据库上执行一些脚本。我在 nsis 中使用 xsqlexecutor 工具来 运行 在捕获 sql 实例、数据库和登录等详细信息后这些脚本。这些是在调用 nsis 自定义页面时从 windows 注册表中填充的。页面离开功能检查它是否可以成功连接到这个数据库,如果不能,它会中止离开功能并返回到 page.Problem 这里是,当我第一次给出错误的细节时,离开功能中止并返回页面,但如果我再次提供正确的数据库详细信息,它说 xsqlexecutor 已停止运行。但是,如果返回一个页面然后点击下一步并再次回到该页面,如果我提供正确的数据库详细信息,它似乎可以正常工作,

    Function SqlConfigPage
         SectionGetFlags ${SEC03} $R0
         IntOp $R0 $R0 & ${SF_SELECTED}
         IntCmp $R0 ${SF_SELECTED} show
         Abort

show:
 nsDialogs::Create /NOUNLOAD 1018
 Pop $Dialog
 ${If} $Dialog == error
  Abort
 ${EndIf}
 ${NSD_CreateLabel} 0 0 100% 15u "Enter SQL Details"
   Pop $Label

   ${NSD_CreateLabel} 0 15u 50u 12u "Server Instance"
   Pop $Server

    ${NSD_CreateText} 60u 15u 100% 12u "$instance"
   Pop $instance

   ${NSD_CreateLabel} 0 30u 36u 12u "SQL DB"
   Pop $dblabel

   ${NSD_CreateText} 36u 30u 100% 12u "$db"
   Pop $db

   ${NSD_CreateLabel} 0 45u 36u 12u "Username"
   Pop $userlabel

   ${NSD_CreateText} 36u 45u 100% 12u "$user"
   Pop $user

   ${NSD_CreateLabel} 0 60u 36u 12u "Password"
   Pop $Passwordlabel

   ${NSD_CreatePassword} 36u 60u 100% 12u "$pwd"
   Pop $pwd
                nsDialogs::Show

FunctionEnd

Function SqlConfigPageLeave

 ${NSD_GetText} $Server $R1
 ${NSD_GetText} $db $R2
 ${NSD_GetText} $user $R3
 ${NSD_GetText} $pwd $R4
 StrCpy $server $R1
 StrCpy $db $R2
 StrCpy $user $R3
 StrCpy $pwd $R4

InitPluginsDir
SetOutPath "$PLUGINSDIR"
SetOverwrite On
  CreateDirectory $PLUGINSDIR\SQL
  SetOutPath "$PLUGINSDIR\SQL"
  File /nonfatal "..\xsql.exe"
  File /nonfatal "..\sqlconnectioncheck.txt"
  nsExec::Exec '$PLUGINSDIR\SQL\xsql.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:3 /q /f:"$PLUGINSDIR\SQL\sqlconnectioncheck.txt"'
   IfFileExists $PLUGINSDIR\SQL\ScriptErr.txt sqlerror continue
 sqlerror:
 FileOpen  "$PLUGINSDIR\Scripts\ScriptErr.txt" r
 FileRead  
 FileRead  
 FileClose 
  MessageBox MB_OK "SQL Connetion failed, check SQL details provided once again.  "

continue:
FunctionEnd

任何输入都会有所帮助,在此先感谢..

看来,您正在重写 -Leave 函数中的控件句柄。:

 StrCpy $server $R1
 StrCpy $db $R2
 StrCpy $user $R3
 StrCpy $pwd $R4

因此,在第二次调用时,您总是在参数中遇到垃圾:

 ${NSD_GetText} $Server $R1
 ${NSD_GetText} $db $R2
 ${NSD_GetText} $user $R3
 ${NSD_GetText} $pwd $R4

因为 $Server,$db, $user, $pwd 包含以前的值而不是控制句柄。

对控件及其值使用单独的变量,如下所示:

Var server_ctrl
Var db_ctrl
Var user_ctrl
Var pwd_ctrl
     Function SqlConfigPage
             SectionGetFlags ${SEC03} $R0
             IntOp $R0 $R0 & ${SF_SELECTED}
             IntCmp $R0 ${SF_SELECTED} show
             Abort

    show:
 nsDialogs::Create /NOUNLOAD 1018
 Pop $Dialog
 ${If} $Dialog == error
  Abort
 ${EndIf}
 ${NSD_CreateLabel} 0 0 100% 15u "Enter SQL Details"
   Pop $Label

   ${NSD_CreateLabel} 0 15u 50u 12u "Server Instance"
   Pop $Server_ctrl

    ${NSD_CreateText} 60u 15u 100% 12u "$instance"
   Pop $instance

   ${NSD_CreateLabel} 0 30u 36u 12u "SQL DB"
   Pop $dblabel

   ${NSD_CreateText} 36u 30u 100% 12u "$db"
   Pop $db_ctrl

   ${NSD_CreateLabel} 0 45u 36u 12u "Username"
   Pop $userlabel

   ${NSD_CreateText} 36u 45u 100% 12u "$user"
   Pop $user_ctrl

   ${NSD_CreateLabel} 0 60u 36u 12u "Password"
   Pop $Passwordlabel

   ${NSD_CreatePassword} 36u 60u 100% 12u "$pwd"
   Pop $pwd_ctrl
                nsDialogs::Show

FunctionEnd

Function SqlConfigPageLeave

 ${NSD_GetText} $Server_ctrl $R1
 ${NSD_GetText} $db_ctrl $R2
 ${NSD_GetText} $user_ctrl $R3
 ${NSD_GetText} $pwd_ctrl $R4
 StrCpy $server $R1
 StrCpy $db $R2
 StrCpy $user $R3
 StrCpy $pwd $R4

InitPluginsDir
SetOutPath "$PLUGINSDIR"
SetOverwrite On
  CreateDirectory $PLUGINSDIR\SQL
  SetOutPath "$PLUGINSDIR\SQL"
  File /nonfatal "..\xsql.exe"
  File /nonfatal "..\sqlconnectioncheck.txt"
  nsExec::Exec '$PLUGINSDIR\SQL\xsql.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:3 /q /f:"$PLUGINSDIR\SQL\sqlconnectioncheck.txt"'
   IfFileExists $PLUGINSDIR\SQL\ScriptErr.txt sqlerror continue
 sqlerror:
 FileOpen  "$PLUGINSDIR\Scripts\ScriptErr.txt" r
 FileRead  
 FileRead  
 FileClose 
  MessageBox MB_OK "SQL Connetion failed, check SQL details provided once again.  "

continue:
FunctionEnd