; example2.nsi
;
; This script is based on example1.nsi, but adds uninstall support
; and (optionally) start menu shortcuts.
;
; It will install notepad.exe into a directory that the user selects,
;

; The name of the installer
Name "Example2"

; The file to write
OutFile "example2.exe"

; The default installation directory
InstallDir $PROGRAMFILESExample2
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM SOFTWARENSIS_Example2 "Install_Dir"

; The text to prompt the user to enter a directory
ComponentText "This will install the less simple example2 on your computer. Select which optional things you want installed."
; The text to prompt the user to enter a directory
DirText "Choose a directory to install in to:"

; The stuff to install
Section "Example2 (required)"
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  ; Put file there
  File "..makensisw.exe"
  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARENSIS_Example2 "Install_Dir" "$INSTDIR"
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallExample2" "DisplayName" "NSIS Example2 (remove only)"
  WriteRegStr HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallExample2" "UninstallString" '"$INSTDIRuninstall.exe"'
  WriteUninstaller "uninstall.exe"
SectionEnd

; optional section
Section "Start Menu Shortcuts"
  CreateDirectory "$SMPROGRAMSExample2"
  CreateShortCut "$SMPROGRAMSExample2Uninstall.lnk" "$INSTDIRuninstall.exe" "" "$INSTDIRuninstall.exe" 0
  CreateShortCut "$SMPROGRAMSExample2Example2 (notepad).lnk" "$INSTDIR\notepad.exe" "" "$INSTDIRmakensisw.exe" 0
SectionEnd

; uninstall stuff

UninstallText "This will uninstall example2. Hit next to continue."

; special uninstall section.
Section "Uninstall"
  ; remove registry keys
  DeleteRegKey HKLM "SoftwareMicrosoftWindowsCurrentVersionUninstallExample2"
  DeleteRegKey HKLM SOFTWARENSIS_Example2
  ; remove files
  Delete $INSTDIRmakensisw.exe
  ; MUST REMOVE UNINSTALLER, too
  Delete $INSTDIRuninstall.exe
  ; remove shortcuts, if any.
  Delete "$SMPROGRAMSExample2*.*"
  ; remove directories used.
  RMDir "$SMPROGRAMSExample2"
  RMDir "$INSTDIR"
SectionEnd

function gogo
FileOpen $0 "file.txt" r
GetTempFileName $R0
FileOpen $1 $R0 w
loop:
   ReadFile $0 $2
   IfErrors done
   StrCmp $2 "line to replace$\r$\n" 0 +2
      FileWrite $1 "replacement of line$\r$\n"
      Goto loop
   FileWrite $1 $2
   Goto loop

done:
   FileClose $0
   FileClose $1
   Delete "file.txt"
   CopyFiles /SILENT $R0 "file.txt"
FunctionEnd
; eof