Writing into Config File
Hi All
I am using NSIS installer from the past 15 days and I would like to make an installer for my project
Details are as follows
I created a custom page where we have an drop down with prior databases written and one option as Create new database
So now the thing is that when i choose create new database i need to get a textbox in the next page and should accept the name and should write in the config file specified.
If i select the database name(existing ones) it should ask for text box and instead i should directly move for the installation directory
I am in need urgent
Please help me out regarding this issue...
Here is the sample code i am using
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "XXX"
!define PRODUCT_VERSION "V1.0.0.0"
!define PRODUCT_PUBLISHER "YYY"
!define PRODUCT_WEB_SITE "www.example.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
SetCompressor lzma
;General Variable Declaration and Definitions
!define LVM_GETITEMCOUNT 0x1004
!define LVM_GETITEMTEXT 0x102D
!define REGKEY "SOFTWARE\$(^Name)"
!define TEMP1 $R0
!define TEMP2 $R1
!define TEMP3 $R3
; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "WordFunc.nsh"
!include "TextFunc.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Custom pages
Page custom Select_DataBase
;Page custom EnterUsername_Password
;!define MUI_PAGE_CUSTOMFUNCTION_PRE txt_box
; 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 "ADB_Setup"
!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
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "ADB_SETUP"
!define MUI_FINISHPAGE_SHOWREADME "ReadMe.txt"
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION} [${__DATE__}]"
OutFile "ADB_Setup.exe"
CRCCheck on
XPStyle on
BrandingText "Created By Cytrion Technologies"
InstallDir "$PROGRAMFILES\ADB_Setup"
ShowInstDetails show
ShowUnInstDetails show
Section "ADB_SECTION" SEC01
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath $INSTDIR
SetOverwrite on
File /r "D:\CodeIgniter_1.7.1\*"
WriteRegStr HKLM "${REGKEY}\Components" Main 1
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "[SEC_READ_CONFIG_FILES]" SEC02
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
;Get Install Options dialog user input
ReadINIStr ${TEMP2} "$PLUGINSDIR\test.ini" "Field 2" "State"
StrCpy $3 "${TEMP2}"
DetailPrint "Facility Name: ${TEMP2}"
${ConfigWrite} "$INSTDIR\system\application\config\database.php" "$db['default']['database'] = " '"$3"' ${TEMP3}
;ReadINIStr ${TEMP1} "$PLUGINSDIR\up.ini" "Field 2" "State"
;DetailPrint "Password: ${TEMP1}"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "SEC_002" SEC03
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
;Get Install Options dialog user input
ReadINIStr ${TEMP1} "$PLUGINSDIR\db_select.ini" "Field 1" "State"
StrCpy $4 "${TEMP1}"
DetailPrint "Facility Name: ${TEMP1}"
${ConfigWrite} "$INSTDIR\system\application\config\database.php" "$db['default']['database'] = " '"$4"' ${TEMP3}
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "SEC_003" SEC04
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "SEC_004" SEC05
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "SEC_005" SEC06
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "[SEC_PATCH_FIXING]" SEC07
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section "[SEC_LOG_FILE]" SEC08
; Shortcuts
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
StrCpy $0 "$INSTDIR\install.log"
Push $0
Call DumpLog
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section -AdditionalIcons
SetOutPath $INSTDIR
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SEC01} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC02} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC03} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC04} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC05} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC06} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC07} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC08} "Log File is Generated and Customer can view the file for complete installation process"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
#-------------------- Function which initializes------------------------------#
#------ all the necessary config files specifiedby the user ------------------#
Function .onInit
StrCpy $2 0
InitPluginsDir
;File /oname=$PLUGINSDIR\up.ini "up.ini"
File /oname=$PLUGINSDIR\db_select.ini "db_select.ini"
File /oname=$PLUGINSDIR\test.ini "test.ini"
FunctionEnd
#--------------------End of the Functon Init----------------------------------#
#----------------------------Function to Select Database----------------------#
Function Select_DataBase
;Display the InstallOptions dialog
Push ${TEMP2}
InstallOptions::dialog "$PLUGINSDIR\db_select.ini"
again: InstallOptions::dialog "$PLUGINSDIR\test.ini"
Pop ${TEMP2}
StrCmp ${TEMP2} "success" 0 continue
ReadINIStr $0 "$PLUGINSDIR\db_select.ini" "Field 1" "State"
continue: Pop ${TEMP2}
Return
FunctionEnd
#----------------------------End of the Function------------------------------#
#---------------------------Function to create custom facilityname------------#
;Function txt_box
; MessageBox MB_OK "Hi"
;FunctionEnd
#----------------------------End of the Function------------------------------#
#-----------------------------Enter Username and Password Function -----------#
/*Function EnterUsername_Password
;Display the InstallOptions dialog
Push ${TEMP1}
again: InstallOptions::dialog "$PLUGINSDIR\up.ini"
Pop ${TEMP1}
StrCmp ${TEMP1} "success" 0 continue
ReadINIStr $0 "$PLUGINSDIR\up.ini" "Field 1" "State"
ReadINIStr $1 "$PLUGINSDIR\up.ini" "Field 4" "State"
StrCmp $0 "user1" 0 +2
StrCmp $1 "user1 password" continue wrong
StrCmp $0 "user2" 0 +2
StrCmp $1 "user2 password" continue wrong
StrCmp $0 "user3" 0 +2
StrCmp $1 "user3 password" continue wrong
wrong:
IntOp $2 $2 + 1
StrCmp $2 3 kill
MessageBox MB_OK|MB_ICONSTOP "Wrong user name and password, try again"
Goto again
continue: Pop ${TEMP1}
Return
kill: MessageBox MB_OK|MB_ICONSTOP "3 times wrong, bye!"
Quit
FunctionEnd*/
#------------------------------End of Function------------------------------------#
#----------------------------------Function DumpLog Start-------------------------#
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_GETITEMCOUNT} 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_GETITEMTEXT}, $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
#----------------------------------Function DumpLog 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
!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\install.log"
Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"
Delete "$SMPROGRAMS\$ICONS_GROUP\Website.lnk"
RMDir /REBOOTOK "$SMPROGRAMS\$ICONS_GROUP"
RmDir /REBOOTOK $INSTDIR
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
SetAutoClose true
SectionEnd