Writing to ini problem
Ok I have my installer built and I have a custom page where a user enters his or her username and password and then the installer writes their input to an ini file which that part works however when I first run the installer it does not write to the ini file I have to run it a second time in order for it to write the input from the username and password fields, Here is the contents of the nsi:
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;--------------------------------
;General
;Name and file
Name "Test Installer"
OutFile "Basic.exe"
;Default installation folder
InstallDir "$PROGRAMFILES\Test Directory"
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
Page custom CustomPageA
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
;Reserve Files
;These files should be inserted before other files in the data block
;Keep these lines before any File command
;Only for solid compression (by default, solid compression is enabled for BZIP2 and LZMA)
ReserveFile "post.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;--------------------------------
;Installer Sections
Section "Main Files" SecDummy
SetOutPath "$INSTDIR"
File "my.ini"
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;--------------------------------
;Installer Functions
Function .onInit
;Extract InstallOptions INI files
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "post.ini"
FunctionEnd
LangString TEXT_IO_TITLE ${LANG_ENGLISH} "User Information"
LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "Please enter your login information below"
Function CustomPageA
!insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "post.ini"
!insertmacro MUI_INSTALLOPTIONS_READ $0 "post.ini" "Field 1" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $1 "post.ini" "Field 2" "State"
WriteINIStr "$INSTDIR\my.ini" "Data" "username" "$0"
WriteINIStr "$INSTDIR\my.ini" "Data" "password" "$1"
WriteINIStr "$INSTDIR\my.ini" "Data" "Directory" "$INSTDIR"
FunctionEnd
;--------------------------------
;Descriptions
;Language strings
LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;--------------------------------
;Uninstaller Section
Section "Uninstall"
;ADD YOUR OWN FILES HERE...
Delete "$INSTDIR\Uninstall.exe"
Delete "$INSTDIR\my.ini"
RMDir "$INSTDIR"
SectionEnd