Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 15th November 2014, 12:03   #1
Raven83
Junior Member
 
Join Date: Nov 2014
Posts: 19
Question NSIS installer error, probably has to do with $INSTDIR variable

0 down vote favorite


I have an NSIS script used to make an application patch exe which will copy application files and execute some sql scripts for our erp application. NSIS script was made by someone else so i'm not very easy with this. Lately its been throwing a weird error mostly in windows 2012 machines. In the middle of installation , the INSTDIR variable gets changed to "1033" which is my understanding of the happening, not able to post image but the error is ,



The installer works on some windows machines but on some this error pops up. I added some msg blocks in between the code and found out the value of INSTDIR is getting changed after a certain statements.Default path is "C:/APP but this changed to "1033", what i did to counter this is, i copied the initial INSTDIR variable to another $INSTLOC and then copied the string from $INSTLOC to $INSTDIR where the value of $INSTDIR was getting changed. This worked on some machines now i have the same error in another machine although this copy code is already there. This default path is getting changed elsewhere in the code in runtime now, Wonder why this is happening anybody has any insights..would be very helpful, thanks...
Raven83 is offline   Reply With Quote
Old 15th November 2014, 17:09   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,148
NSIS Version?

It would really help if you could narrow it down to a small piece of code where the problem happens. Both scripting code and plugins can change $instdir. 1033 sounds like a language code, perhaps from $language.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th November 2014, 11:27   #3
Raven83
Junior Member
 
Join Date: Nov 2014
Posts: 19
Question

This is the script in question, couldn't pinpoint where this is occuring so i've pasted the whole source, and $langauge is not used anymore to clear that up..would be great if there are any more insights on this,

code:
; Script generated by the HM NIS Edit Script Wizard.
; Script for Backup and Restore
!define FileCopy `!insertmacro FileCopy`
!macro FileCopy FilePath TargetDir
CreateDirectory `${TargetDir}`
CopyFiles `${FilePath}` `${TargetDir}`
!macroend
;
!define RestoreCopy `!insertmacro RestoreCopy`
!macro RestoreCopy FilePath TargetDir
CopyFiles `${FilePath}` `${TargetDir}`
!macroend
;
; HM NIS Edit Wizard helper defines
!define PATCH_NUMBER "34"
!define PREPATCH_NUMBER "33"
!define PREPREPATCH_NUMBER "32"
!define PRODUCT_NAME "SuitePatch"
!define PRODUCT_VERSION "V3.0.${PATCH_NUMBER}"
!define CORE_VERSION "V3.0"
!define BUILD_NUMBER "038"
!define PRODUCT_PUBLISHER "@ Software Solutions"
!define PRODUCT_WEB_SITE ""
!define PRODUCT_DIR_REGKEY "Software\${PRODUCT_NAME}\${PRODUCT_VERSION}"
!define PRODUCT_PDIR_REGKEY "Software\${PRODUCT_NAME}\${CORE_VERSION}.${PREPATCH_NUMBER}"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\${PRODUCT_VERSION}"
!define PRODUCT_UNINST_PREV_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${CORE_VERSION}\${PREPATCH_NUMBER}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
!define QSUITE_UNINST_EXE "${PRODUCT_NAME}-Setup-${PRODUCT_VERSION}.${BUILD_NUMBER}-uninst.exe"
!define QSUITE_UNINSTALL_LNK "${PRODUCT_NAME}-Setup-${PRODUCT_VERSION}.${BUILD_NUMBER}-Uninstall.lnk"

SetCompressor lzma

; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "nsDialogs.nsh"
!include "WordFunc.nsh"
!include "FileFunc.nsh"
!insertmacro GetParameters
!insertmacro GetOptions
!define LVM_GETITEMCOUNTW 0x1004
!define LVM_GETITEMTEXTW 0x102D
!define LVM_GETITEMCOUNTU 0x1004
!define LVM_GETITEMTEXTU 0x102D
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "..\Icons\insticon.ico"
!define MUI_UNICON "..\Icons\uninsticon.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Start menu page
var ICONS_GROUP
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_NAME}"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; Instfiles page
page custom SqlPage SqlPageTmpLeave
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
;page custom SqlPageLeave
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; Define Variables
Var cmdLineParams
; MUI end ------
RequestExecutionLevel admin
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "..\${PRODUCT_NAME}-Setup-${PRODUCT_VERSION}.${BUILD_NUMBER}.exe"
InstallDir "$EXEDIR"
InstallDirRegKey HKLM "${PRODUCT_PDIR_REGKEY}" "Installlocation"
ShowInstDetails nevershow
ShowUnInstDetails nevershow
BrandingText "@ Software Solutions"
;
; Create a log file at the begining
Section "-dumplog" SEC00
StrCpy $0 "$EXEDIR\myinstall.log"
Push $0
SectionEnd
; Installation features
SectionGroup "MainSection" GRP_1
;
Section "Database" SEC03
IfSilent sqlTL sqlPL
sqlTL:
call SqlPageTmpLeave
call SqlPageLeave
Goto sqlend
sqlPL:
call SqlPageLeave
Goto sqlend
sqlend:
SectionEnd
;
Section "Pro" SEC01
SetOverwrite ifnewer
!include "InstallSections\InstallProfiles.nsh"
SectionEnd
;
Section "ProQcm" SEC02
SetOverwrite ifnewer
!include "InstallSections\InstallProQcmfiles.nsh"
SectionEnd
;
SectionGroupEnd
;
Section -AdditionalIcons
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${QSUITE_UNINSTALL_LNK}" "$INSTDIR\${QSUITE_UNINST_EXE}"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
;
Section -Post
# Delete old uninstaller links and exe
ReadRegStr $3 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\${CORE_VERSION}.${PREPATCH_NUMBER}" "Build"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}-Setup-${CORE_VERSION}.${PREPATCH_NUMBER}.$3-Uninstall.lnk"
!insertmacro FileCopy "$INSTDIR\${PRODUCT_NAME}-Setup-${CORE_VERSION}.${PREPATCH_NUMBER}.$3-uninst.exe" "$Windir\installer"
Delete "$INSTDIR\${PRODUCT_NAME}-Setup-${CORE_VERSION}.${PREPATCH_NUMBER}.$3-uninst.exe"
# Adding to Registry
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "DisplayName" "$(^Name)"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "PatchNumber" "${PATCH_NUMBER}"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "PrePatchNumber" "${PREPATCH_NUMBER}"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Build" "${BUILD_NUMBER}"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Backup.${PATCH_NUMBER}" "$INSTDIR\_${PRODUCT_VERSION}_bkp"
WriteUninstaller "$INSTDIR\${QSUITE_UNINST_EXE}"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Installlocation" "$INSTDIR"
WriteRegStr HKLM "Software\${PRODUCT_NAME}" "Installlocation" "$INSTDIR"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\${QSUITE_UNINST_EXE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "PatchNumber" "${PATCH_NUMBER}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "PrePatchNumber" "${PREPATCH_NUMBER}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Build" "${BUILD_NUMBER}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Backup.${PATCH_NUMBER}" "$INSTDIR\_${PRODUCT_VERSION}_bkp"

SectionEnd

; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${GRP_1} ""
!insertmacro MUI_FUNCTION_DESCRIPTION_END

Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd

Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
Abort
FunctionEnd

Section Uninstall
StrCpy $0 "$INSTDIR\Uninstall.log"
Push $0
#Restore old copy and Remove patch
!include "InstallSections\UnInstallProFiles.nsh"
!include "InstallSections\UnInstallProQcmFiles.nsh"
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
Delete "$INSTDIR\${QSUITE_UNINST_EXE}"
Delete "$SMPROGRAMS\$ICONS_GROUP\${QSUITE_UNINSTALL_LNK}"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
RMDir "$SMPROGRAMS\$ICONS_GROUP"
RMDir /r "$INSTDIR\_${PRODUCT_VERSION}_bkp"
SetAutoClose true
call un.DumpLog
SectionEnd

; Checking the Suite Installed Directory exist --End
; Check patch already installed
Function .onInit
IfSilent GetOpt GetVar
GetOpt:
call GetSilentParams
Goto Start
GetVar:
call GetVariables
Goto Start
Start:

# Check if the SQL Install dir is selected (Enable in mainsection), unselected disable in mainsection
Push "..\include\Database\*.*"
Call isEmptyDir
Pop $0
StrCmp $0 1 0 +2
!insertmacro UnselectSection ${SEC03}
SectionSetText ${SEC03} ""
StrCmp $0 0 0 +2
!insertmacro selectSection ${SEC03}
SectionSetText ${SEC03} "Database"

ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\${CORE_VERSION}.${PREPATCH_NUMBER}" "PrePatchNumber" ;Enble this for Patch is greaterThan 1
;ifErrors Continue ;Do not Enable this.
StrCmp $1 ${PATCH_NUMBER} NoDSPH CheckCurrentPatch ;Enble this for Patch is greaterThan 1, 2nd exe distribution
CheckCurrentPatch:
ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\${CORE_VERSION}.${PATCH_NUMBER}" "PatchNumber" ;Enable it from 2nd patch.
StrCmp $0 ${PATCH_NUMBER} NoDSP CheckPreviousPatch ;Enable it for PatchNo>1
;StrCmp $0 ${PATCH_NUMBER} NoDSP Continue ;Enable it for Patchno:1
;ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\${PRODUCT_VERSION}" "PatchNumber" ;Enable it for 1st patch.
;IfErrors Continue ;Go to the label "Continue: Enble this exe distribution"
;IfErrors Exit ;Go to the label "Exit: Enble this 3rd exe distribution"
; Enble CheckPreviousPatch if patchno is greaterThan 1 or 2nd Patch
CheckPreviousPatch:
ReadRegStr $2 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\${CORE_VERSION}.${PREPATCH_NUMBER}" "PatchNumber" ;Enble this for Patch is greaterThan 1
StrCmp $2 ${PREPATCH_NUMBER} Continue NoDS ;Enable it from 2nd patch.

NoDS:
; IfSilent +1 ;If the installer is being run silently, we do not want to display a message, so skip ahead 2 lines (to Abort)
MessageBox MB_ICONEXCLAMATION "This Patch Pack requires ${PRODUCT_NAME} ${PREPATCH_NUMBER} to be installed"
Abort ;Previous Patch Pack not installed, Abort the install
NoDSP:
; IfSilent +1 ;If the installer is being run silently, we do not want to display a message, so skip ahead 2 lines (to Abort)
MessageBox MB_ICONEXCLAMATION "This Patch Pack ${PRODUCT_NAME} ${PATCH_NUMBER} already Installed"
Abort ;Installer version already exist, Abort the install
NoDSPH:
; IfSilent +1 ;If the installer is being run silently, we do not want to display a message, so skip ahead 2 lines (to Abort)
MessageBox MB_ICONEXCLAMATION "You already have Higher Version Installed"
Abort ;Higher version found, Abort the install
;Exit: ;Enble this 2st time exe distribution
; MessageBox MB_ICONEXCLAMATION "None of the previous Patches installed"
; Abort "No previous patch found"
Continue: ;Enble this 1st time exe distribution
FunctionEnd

;Generate installer log
Function DumpLog
Exch $5
Push $0
Push $1
Push $2
Push $3
Push $4
Push $6

FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1016
StrCmp $0 0 exit
FileOpen $5 $5 "w"
StrCmp $5 "" exit
SendMessage $0 ${LVM_GETITEMCOUNTW} 0 0 $6
System::Alloc ${NSIS_MAX_STRLEN}
Pop $3
StrCpy $2 0
System::Call "*(i, i, i, i, i, i, i, i, i) i \
(0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
loop: StrCmp $2 $6 done
System::Call "User32::SendMessageW(i, i, i, i) i \
($0, ${LVM_GETITEMTEXTW}, $2, r1)"
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
FileWrite $5 "$4$\r$\n"
IntOp $2 $2 + 1
Goto loop
done:
FileClose $5
System::Free $1
System::Free $3
exit:
Pop $6
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Exch $5
FunctionEnd

;Generate uninstaller log
Function un.DumpLog
Exch $5
Push $0
Push $1
Push $2
Push $3
Push $4
Push $6

FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1016
StrCmp $0 0 exit
FileOpen $5 $5 "a"
StrCmp $5 "" exit
SendMessage $0 ${LVM_GETITEMCOUNTU} 0 0 $6
System::Alloc ${NSIS_MAX_STRLEN}
Pop $3
StrCpy $2 0
System::Call "*(i, i, i, i, i, i, i, i, i) i \
(0, 0, 0, 0, 0, r3, ${NSIS_MAX_STRLEN}) .r1"
loop: StrCmp $2 $6 done
System::Call "User32::SendMessageA(i, i, i, i) i \
($0, ${LVM_GETITEMTEXTU}, $2, r1)"
System::Call "*$3(&t${NSIS_MAX_STRLEN} .r4)"
FileWrite $5 "$4$\r$\n"
IntOp $2 $2 + 1
Goto loop
done:
FileClose $5
System::Free $1
System::Free $3
exit:
Pop $6
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
Exch $5
FunctionEnd

;Service Dialog Variables
Var Dialog
Var lblService
Var LblNotes
Var LblCode
Var txtCode
Var txtService
;SQLAuth Dialog Variables
Var lblServer
Var lblDatabase
Var lblUsername
Var lblPassword
Var txtServer
Var txtDatabase
Var txtUsername
Var pwdPassword
; To add SqlPage Dialog in InstallOption Dialog
; Exclude Dialog to appear if not selected
; Do-not-change dialog x-y-wd-hg
Function SqlPage
SectionGetFlags ${SEC03} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} show
Abort

show:
call GetVariables
nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 20u "Product Configuration not found, fill as per document"
Pop $LblNotes
${NSD_CreateLabel} 0 20u 50u 12u "Customer Code"
Pop $lblCode
${NSD_CreateText} 80u 20u 30u 12u "$txtCode"
Pop $txtCode
${NSD_CreateLabel} 0 40u 70u 12u " Suite Service"
Pop $lblService
${NSD_CreateText} 80u 40u 100% 12u "$txtService"
Pop $txtService
;${NSD_CreateLabel} 0 0 100% 24u "Please specify the Server, Database, Username, and Password for your SQL Database Authentication."
;Pop $lblLabel1

${NSD_CreateLabel} 0 60u 50u 12u "Instance Name"
Pop $lblServer

${NSD_CreateLabel} 0 80u 36u 12u "Database"
Pop $lblDatabase

${NSD_CreateLabel} 0 100u 36u 12u "Username"
Pop $lblUsername

${NSD_CreateLabel} 0 120u 36u 12u "Password"
Pop $lblPassword

${NSD_CreateText} 80u 60u 100% 12u "$txtServer"
Pop $txtServer

${NSD_CreateText} 36u 80u 100% 12u "$txtDatabase"
Pop $txtDatabase

${NSD_CreateText} 36u 100u 100% 12u "$txtUsername"
Pop $txtUsername

${NSD_CreatePassword} 36u 120u 100% 12u "$pwdPassword"
Pop $pwdPassword

nsDialogs::Show

FunctionEnd
;
Function SqlPageTmpLeave
ifSilent GetSil sqlnorm

GetSil:
call GetSilentParams
StrCpy $txtServer $R1
StrCpy $txtDatabase $R2
StrCpy $txtUsername $R3
StrCpy $pwdPassword $R4
StrCpy $txtService $R5
StrCpy $txtCode $R6
Goto Sqlrun

sqlnorm:
${NSD_GetText} $txtServer $R1
${NSD_GetText} $txtDatabase $R2
${NSD_GetText} $txtUsername $R3
${NSD_GetText} $pwdPassword $R4
${NSD_GetText} $txtService $R5
${NSD_GetText} $txtCode $R6
StrCpy $txtServer $R1
StrCpy $txtDatabase $R2
StrCpy $txtUsername $R3
StrCpy $pwdPassword $R4
StrCpy $txtService $R5
StrCpy $txtCode $R6
Goto Sqlrun

Sqlrun:
Var /GLOBAL INSTLOC
StrCpy $INSTLOC $INSTDIR
; capture the details Write to registry
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Data Source" "$R1"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "initial catalog" "$R2"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "User ID" "$R3"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Password" "$R4"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "WebServiceURL" "$R5"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "ClientName" "$R6"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Data Source" "$R1"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "initial catalog" "$R2"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "User ID" "$R3"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Password" "$R4"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "WebServiceURL" "$R5"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "ClientName" "$R6"
StrCpy $INSTDIR $INSTLOC
;MessageBox MB_OK "INSDIR end of SQLRUN: $INSTDIR"
InitPluginsDir
SetOutPath "$PLUGINSDIR"
SetOverwrite On
CreateDirectory $PLUGINSDIR\Scripts
SetOutPath "$PLUGINSDIR\Scripts"
File /nonfatal /x ".svn" "..\Tools\scriptexecutor.exe"
File /nonfatal /x ".svn" "..\Tools\checksql.txt"
; MessageBox MB_OKCANCEL "$R1 $R4 - $txtServer $pwdPassword" IDCANCEL GETOUT
nsExec::Exec '$PLUGINSDIR\Scripts\scriptexecutor.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:1 /q /f:"$PLUGINSDIR\Scripts\checksql.txt"'
IfFileExists $PLUGINSDIR\Scripts\ScriptErr.txt noSql SqlCont
noSql:
FileOpen $7 "$PLUGINSDIR\Scripts\ScriptErr.txt" r
FileRead $7 $8
FileRead $7 $9
FileClose $7
; MessageBox MB_OK "Status: $0"
; MessageBox MB_OK "pass: $pwdPassword"
GetDlgItem $0 $HWNDPARENT 1 ; Next button
SendMessage $0 ${WM_SETTEXT} 0 "STR:Retry"
MessageBox MB_OK "SQL Authentication failed, please try again. $8 $9"
Abort ;Do not leave the page until SQL completes successfully
;GetOut:
;Quit
SqlCont:
FunctionEnd
; SqlPageLeave - Make sure every new customers are added to this list so that
; their specific scripts are not missed out...check the pattern below and added.
; ${If} $5 == blah ; code name blah blah contructions
; SetOutPath "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\blah"
; File /nonfatal /r /x ".svn" "..\Include\Database\blah\*"
;${EndIf}
; End of the comments
Function SqlPageLeave
ifSilent GetSil1 sqlnorm1

GetSil1:
call GetSilentParams
StrCpy $txtServer $R1
StrCpy $txtDatabase $R2
StrCpy $txtUsername $R3
StrCpy $pwdPassword $R4
StrCpy $txtService $R5
StrCpy $txtCode $R6
Goto Sqlrun1

sqlnorm1:
${NSD_GetText} $txtServer $R1
${NSD_GetText} $txtDatabase $R2
StrCpy $INSTDIR $INSTLOC
${NSD_GetText} $txtUsername $R3
${NSD_GetText} $pwdPassword $R4
${NSD_GetText} $txtService $R5
${NSD_GetText} $txtCode $R6
StrCpy $txtServer $R1
StrCpy $txtDatabase $R2
StrCpy $txtUsername $R3
StrCpy $pwdPassword $R4
StrCpy $txtService $R5
StrCpy $txtCode $R6
;MessageBox MB_OK "Install Dir SQLNORM1 b4 Dumplog: $INSTDIR"
call DumpLog
;MessageBox MB_OK "InstDir SQLNORM1 end: $INSTDIR"
Goto Sqlrun1

Sqlrun1:
ReadRegStr $R1 HKLM "${PRODUCT_DIR_REGKEY}" "Data Source"
ReadRegStr $R2 HKLM "${PRODUCT_DIR_REGKEY}" "initial catalog"
ReadRegStr $R3 HKLM "${PRODUCT_DIR_REGKEY}" "User ID"
ReadRegStr $R4 HKLM "${PRODUCT_DIR_REGKEY}" "Password"
ReadRegStr $R6 HKLM "${PRODUCT_DIR_REGKEY}" "ClientName"
SetOutPath "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database"
SetOutPath "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\Common"
File /nonfatal /r /x ".svn" "..\Include\Database\Common\*"

Check1:
nsExec::Exec '$PLUGINSDIR\Scripts\scriptexecutor.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:1 /q /f:"$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\Common\*.sql"'
Pop $0 # return value/error/timeout
; MessageBox MB_OK "$0"
IfFileExists "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\Common\ScriptErr.txt" SqlErr1 SqlNext

SqlErr1:
FileOpen $7 "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\Common\ScriptErr.txt" r
FileRead $7 $8 10000
FileRead $7 $9 10000
FileClose $7
; MessageBox MB_OK "Status: $0"
; MessageBox MB_OK "pass: $pwdPassword"
MessageBox MB_RETRYCANCEL "SQL Script Error 1, please contact Suite Support with Screenshot & Cancel to Exit. $8 $9" IDRETRY Check1 IDCANCEL InstExit
Abort ;Do not leave the page until SQL completes successfully
; Make sure every new customers are added to this list so that
; their specific scripts are not missed out...check the pattern below and added.
SqlNext:
${If} $R6 == AA
SetOutPath "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\AA"
File /nonfatal /r /x ".svn" "..\Include\Database\AA\*"
${EndIf}

;MessageBox MB_OK "I am in Step 2 - $0"

SqlNext2:
;MessageBox MB_OK "I am in Step 3 - $R1 $R2 $R3 $R4 $R5 $R6"
nsExec::Exec '$PLUGINSDIR\Scripts\scriptexecutor.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:1 /q /f:"$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\$R6\*.sql"'
Pop $0 # return value/error/timeout
; MessageBox MB_OK "Check Step 4 - $0"
IfFileExists "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\$R6\ScriptErr.txt" SqlErr2 SqlDone

SqlErr2:
FileOpen $7 "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\$R6\ScriptErr.txt" r
FileRead $7 $8 10000
FileRead $7 $9 10000
FileClose $7
; MessageBox MB_OK "Status: $0"
; MessageBox MB_OK "pass: $pwdPassword"
MessageBox MB_RETRYCANCEL "SQL Script Error 2, please contact Suite Support with Screenshot or Cancel to exit. $8 $9" IDRETRY SqlNext2 IDCANCEL InstExit
Abort ;Do not leave the page until SQL completes successfully

InstExit:
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
RMDir /r "$INSTDIR\_${PRODUCT_VERSION}_bkp"
Quit ;Exit from the installation

SqlDone:
FunctionEnd

# Utility functions to zero files in a directory
Function isEmptyDir
# Stack -> # Stack: <directory>
Exch $0 # Stack: $0
Push $1 # Stack: $1, $0
FindFirst $0 $1 "$0\*.*"
strcmp $1 "." 0 _notempty
FindNext $0 $1
strcmp $1 ".." 0 _notempty
ClearErrors
FindNext $0 $1
IfErrors 0 _notempty
FindClose $0
Pop $1 # Stack: $0
StrCpy $0 1
Exch $0 # Stack: 1 (true)
goto _end
_notempty:
FindClose $0
Pop $1 # Stack: $0
StrCpy $0 0
Exch $0 # Stack: 0 (false)
_end:
FunctionEnd

Function GetVariables
ReadRegStr $txtCode HKLM "${PRODUCT_PDIR_REGKEY}" "ClientName"
ReadRegStr $txtService HKLM "${PRODUCT_PDIR_REGKEY}" "WebServiceURL"
ReadRegStr $txtDatabase HKLM "${PRODUCT_PDIR_REGKEY}" "initial catalog"
ReadRegStr $txtUsername HKLM "${PRODUCT_PDIR_REGKEY}" "User ID"
ReadRegStr $pwdPassword HKLM "${PRODUCT_PDIR_REGKEY}" "Password"
ReadRegStr $txtServer HKLM "${PRODUCT_PDIR_REGKEY}" "Data Source"
FunctionEnd

Function GetSilentParams
${GetParameters} $cmdLineParams
${If} $cmdlineParams == "/S"
MessageBox mb_iconstop "Please specify the parameters$\r$\n\
/DtxtCode=$\t'Client Code provided '$\r$\n\
/DtxtService=$\t'SuiteService URL'$\r$\n\
/DtxtServer=$\t'Database Instance Name'$\r$\n\
/DtxtDatabase=$\t'Suite Database Name'$\r$\n\
/DtxtUsername=$\t'Database Login id'$\r$\n\
/DpwdPassword=$\t'Database Login password'$\r$\n\
/D=$\t$\t'Suite Installed Path'$\r$\n\
For ex:$\r$\n\
..\QSuitePatch-Setup-1419.${PATCH_NUMBER}.${BUILD_NUMBER}.exe /S$\r$\n\
/DtxtCode=ABC /DtxtService='http://localhost/Pro' /DtxtServer=192.168.1.245\QSuite /DtxtDatabase=suitestagdb /DtxtUsername=test /DpwdPassword=password /D=C:\inetpub\wwwroot\Suite"
quit
${EndIf}
; /DtxtCode
${GetOptions} $cmdLineParams '/DtxtCode=' $R6
${If} ${Errors}
MessageBox mb_iconstop "Missing option /DtxtCode= 'Client Code'"
Quit
${Else}
StrCpy $txtCode "$R6"
${EndIf}
;MessageBox MB_OKCANCEL "Cmp $R6 and $txtCode" IDCANCEL GETOUT IDOK OK
; /DtxtCode
${GetOptions} $cmdLineParams '/DtxtService=' $R5
${If} ${Errors}
MessageBox mb_iconstop "Missing option /DtxtService= 'SuiteService URL'"
Quit
${Else}
StrCpy $txtService $R5
${EndIf}
;MessageBox MB_OKCANCEL "Cmp $R5 and $txtService" IDCANCEL GETOUT IDOK OK
; /DtxtServer
${GetOptions} $cmdLineParams '/DtxtServer=' $R1
${If} ${Errors}
MessageBox mb_iconstop "Missing option /DtxtServer= 'Database Instance Name'"
Quit
${Else}
StrCpy $txtServer $R1
${EndIf}
;MessageBox MB_OKCANCEL "Cmp $R1 and $txtServer" IDCANCEL GETOUT IDOK OK
; /DtxtDatabase
${GetOptions} $cmdLineParams '/DtxtDatabase=' $R2
${If} ${Errors}
MessageBox mb_iconstop "Missing option /DtxtDatabase= 'Suite Database Name'"
Quit
${Else}
StrCpy $txtDatabase $R2
${EndIf}
;MessageBox MB_OKCANCEL "Cmp $R2 and $txtDatabase" IDCANCEL GETOUT IDOK OK
; /DtxtUsername
${GetOptions} $cmdLineParams '/DtxtUsername=' $R3
${If} ${Errors}
MessageBox mb_iconstop "Missing option /DtxtUsername= 'Database Login id'"
Quit
${Else}
StrCpy $txtUsername $R3
${EndIf}
;MessageBox MB_OKCANCEL "Cmp $R3 and $txtUsername" IDCANCEL GETOUT IDOK OK
; /DpwdPassword
${GetOptions} $cmdLineParams '/DpwdPassword=' $R4
${If} ${Errors}
MessageBox mb_iconstop "Missing option /DpwdPassword= 'Database Login password'"
Quit
${Else}
StrCpy $pwdPassword $R4
${EndIf}
;MessageBox MB_OKCANCEL "GetSilentParams $R4 and $pwdPassword" IDCANCEL GETOUT IDOK OK
;
;GetOut:
;Quit
;OK:
FunctionEnd

Raven83 is offline   Reply With Quote
Old 17th November 2014, 14:00   #4
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 878
So I've had a quick look over the script, and there doesn't appear to be anything wrong with it. You haven't said what version you're using so I'll try to be as generic as possible.

I would be pointing my finger at this (try commenting it out and testing if $instdir changes):
PHP Code:
Section "Pro" SEC01
  SetOverwrite ifnewer
  
!include "InstallSections\InstallProfiles.nsh"
SectionEnd
;
Section "ProQcm" SEC02
  SetOverwrite ifnewer
  
!include "InstallSections\InstallProQcmfiles.nsh"
SectionEnd 
Also, why is a section calling page funtions?
PHP Code:
Section "Database" SEC03
  IfSilent sqlTL sqlPL
  sqlTL
:
        
call SqlPageTmpLeave
  call SqlPageLeave
        
Goto sqlend
  sqlPL
:
        
call SqlPageLeave
        
Goto sqlend
  sqlend
:
SectionEnd 
One or two other things:

This $instloc code doesn't do anything because the code in between doesn't modify $instdir.
PHP Code:
StrCpy $INSTLOC $INSTDIR
capture the details Write to registry
  WriteRegStr HKLM 
"${PRODUCT_DIR_REGKEY}" "Data Source" "$R1"
  
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "initial catalog" "$R2"
  
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "User ID" "$R3"
  
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Password" "$R4"
  
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "WebServiceURL" "$R5"
  
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "ClientName" "$R6"

  
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY"${PRODUCT_UNINST_KEY}"  "Data Source" "$R1"
  
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY"${PRODUCT_UNINST_KEY}"  "initial catalog" "$R2"
  
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY"${PRODUCT_UNINST_KEY}"  "User ID" "$R3"
  
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY"${PRODUCT_UNINST_KEY}"  "Password" "$R4"
  
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY"${PRODUCT_UNINST_KEY}"  "WebServiceURL" "$R5"
  
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY"${PRODUCT_UNINST_KEY}"  "ClientName" "$R6"
  
StrCpy $INSTDIR $INSTLOC 
This StrCpy doesn't have it's opposite in this code block. $instdir isn't modified in this codeblock, so it can be removed. In fact, $instloc appears to do nothing in this script, so I would remove it.
PHP Code:
sqlnorm1:
 ${
NSD_GetText$txtServer $R1
 
${NSD_GetText$txtDatabase $R2
 StrCpy  $INSTDIR $INSTLOC
 
${NSD_GetText$txtUsername $R3
 
${NSD_GetText$pwdPassword $R4 
Also this is irrelevent, you only need the second one.
PHP Code:
SetOutPath "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database"
SetOutPath "$INSTDIR\_${PRODUCT_VERSION}_bkp\Database\Common" 
Unless you're using a really old NSIS version, this should be "MUI2.nsh":
PHP Code:
MUI 1.67 compatible ------
!include 
"MUI.nsh" 
And this can be removed since you're not using InstallOptions:
PHP Code:
Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS 
This script only has three sections, so I don't know why there is a SectionGroup here?
PHP Code:
Installation features
SectionGroup 
"MainSection" GRP_1
;
...
Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  
!insertmacro MUI_DESCRIPTION_TEXT ${GRP_1""
!insertmacro MUI_FUNCTION_DESCRIPTION_END 
Also, I don't know what this is about:
PHP Code:
Finish page
!insertmacro MUI_PAGE_FINISH
;page custom SqlPageLeave 
But the better way to do it is:
PHP Code:
Finish page
;!define MUI_PAGE_CUSTOMFUNCTION_LEAVE SqlPageLeave
!insertmacro MUI_PAGE_FINISH 

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 17th November 2014, 15:57   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,148
You really just have to use some messageboxes to try to narrow it down to where $instdir is corrupted. Nothing really jumps out at me in the code you posted...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 18th November 2014, 12:02   #6
Raven83
Junior Member
 
Join Date: Nov 2014
Posts: 19
Thank You Jason and Anders, that indeed was an in depth go through...
i'm new to the NSIS scene very noob, this was done by my predecessor, i'm still playing with the code, i'll try to answer those with what i know,

code:
Section "Pro" SEC01
SetOverwrite ifnewer
!include "InstallSections\InstallProfiles.nsh"
SectionEnd
;
Section "ProQcm" SEC02
SetOverwrite ifnewer
!include "InstallSections\InstallProQcmfiles.nsh"
SectionEnd



This section copies the files bundled, and if you're pointing to the nsh files it doesn't have anything but some filenames of required files that would be copied during the install. Commenting this , i donno but i'll try that.

code:
Section "Database" SEC03
IfSilent sqlTL sqlPL
sqlTL:
call SqlPageTmpLeave
call SqlPageLeave
Goto sqlend
sqlPL:
call SqlPageLeave
Goto sqlend
sqlend:
SectionEnd



This corresponds to function which checks the sql connectivity, this is done before the installation starts so that the installation doesn't break because of SQL connectivity error.

Now comes the important part,

code:
StrCpy $INSTLOC $INSTDIR
; capture the details Write to registry
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Data Source" "$R1"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "initial catalog" "$R2"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "User ID" "$R3"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "Password" "$R4"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "WebServiceURL" "$R5"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "ClientName" "$R6"

WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Data Source" "$R1"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "initial catalog" "$R2"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "User ID" "$R3"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Password" "$R4"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "WebServiceURL" "$R5"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "ClientName" "$R6"
StrCpy $INSTDIR $INSTLOC




Like Jason pointed out the $instloc doesn't have to be there at all, but for debugging the $INSTDIR path i added some msg blocks in between all the functions and jumps and found that just before where i inserted the instloc variable, the value of instdir was getting changed, so what i did was to copy the instdir to instloc and then copy it back after the code where it gets changed, damn thing worked on couple of machines...and it still does, but just couple of days back on a new machine i hit the same bug although this so called fix of mine is still there..so i'm out to find out what actually is causing this so this can be solved once and for all

The others are tweaks that Jason pointed , which i'll copy thanks a lot for this. But this bug is a PITA for me now...
Raven83 is offline   Reply With Quote
Old 19th November 2014, 10:58   #7
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 878
Keep at it, using something like this: DetailPrint "Value of $$INSTDIR=|$INSTDIR|", will make it easier to track the changes of $INSTDIR in the log. This won't work in a page callback function though, it only works in a section (including functions called from a section).

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 20th November 2014, 09:29   #8
Raven83
Junior Member
 
Join Date: Nov 2014
Posts: 19
I'm using MessageBox MB_OK "INSTDIR:$INSTDIR" to catch the values, is this some MS Windows setting causing this corruption of variable...because on most systems it works just fine....i was able to find the corruption on one of the machines using the msg boxes and added a buffer var for instdir, and copied it back when the value was corrupted. This time on another machine the same thing is happening, will do the practice there and see where its going corrupt...really weird though...has anyone encountered anything similar..?
Raven83 is offline   Reply With Quote
Old 21st November 2014, 13:50   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,148
What we are interested in is the code between the last messagebox where it is OK and up to the point where it is corrupted...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd December 2014, 05:07   #10
Raven83
Junior Member
 
Join Date: Nov 2014
Posts: 19
Quote:
Originally Posted by Anders View Post
What we are interested in is the code between the last messagebox where it is OK and up to the point where it is corrupted...
I kind of lost access to the machines where i faced this problem...will update once i get the error..whats baffling me is the fact that the $INSTDIR changed its value at one region in the code block in one machine which i've fixed but its getting changed somewhere else in the code block in another machine...i've a feeling this has to do with the INSTALLDIR and INSTALLDIRREGKEY commands...in the begining of the code, will check that out
Raven83 is offline   Reply With Quote
Old 2nd December 2014, 14:22   #11
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,148
InstallDir/InstallDirRegKey are used before .onInit

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd December 2014, 15:55   #12
Raven83
Junior Member
 
Join Date: Nov 2014
Posts: 19
thats right...! will check once again...
Raven83 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
installer script error, nsis error

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump