; unixv1.nsi
;
; This script is based on example1.nsi, but it remember the directory, 
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install unixv1.nsi into a directory that the user selects,

;--------------------------------

; The name of the installer
Name "unixv1"

; The file to write
OutFile "Research-unixv1-0.3.exe"


##########################
Function .onGUIInit
	# the plugins dir is automatically deleted when the installer exits
	InitPluginsDir
	# lets extract some bitmaps...
        File /oname=$PLUGINSDIR\unixv1.bmp "unixv1.bmp"  


	# set the initial background for images to be drawn on
	BgImage::SetBg /NOUNLOAD /GRADIENT 0x10 0x10 0xff 0x0 0x0 0x0 0xff
        BgImage::AddImage /NOUNLOAD $PLUGINSDIR\unixv1.bmp 0 200
	# create the font for the following text
	CreateFont $R0 "Comic Sans MS" 50 700
	BgImage::AddText /NOUNLOAD "Unix v1 on SIMH 3.8-1" $R0 255 255 255 48 48 1024 198
	BgImage::Redraw /NOUNLOAD
	# Refresh doesn't return any value
	
FunctionEnd

#####################3

; The default installation directory
InstallDir $PROGRAMFILES\unixv1

; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\unixv1" "Install_Dir"


LicenseText "unixv1 Copyright notices"
LicenseData "unixv1license.txt"

;--------------------------------

; Pages

Page license
Page components
Page directory
Page instfiles


UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------






; The stuff to install
Section "Emulator"

  ;SectionIn RO
  
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  
  ; Put file there
  File "pdp11.exe"
  File "unixv1.cmd"
  File "simh.cfg"
  File "m792low.load"
; 
  File "ttermpro.exe"
  File "ttpcmn.dll"
  File "ttpdlg.dll"
  File "ttpfile.dll"
  File "ttpset.dll"
  File "ttptek.dll"


  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\unixv1 "Install_Dir" "$INSTDIR"
  
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\unixv1" "DisplayName" "unixv1"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\unixv1" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\unixv1" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\unixv1" "NoRepair" 1
  WriteUninstaller "uninstall.exe"
SectionEnd

Section "Disk Images"
  File "rf0.dsk"
  File "rk0.dsk"
SectionEnd

Section "Installs"
  File "svntree-20081216.tar.gz"
  File "images-20080625.tgz"
SectionEnd

Section "PDF Documentation"
  FILE "Unix_2nd_Edition_Manual_Jun72.pdf"
SectionEnd

Section "NSI Installscript"
  File "unixv1.nsi"
SectionEnd

#################################################

###################################################



; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"

  CreateDirectory "$SMPROGRAMS\unixv1"
  CreateShortCut "$SMPROGRAMS\unixv1\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\unixv1\RUN unixv1.lnk" "$INSTDIR\unixv1.cmd" "" "$INSTDIR\unixv1.cmd" 0
  CreateShortCut "$SMPROGRAMS\unixv1\Attach a PTY.lnk" "$INSTDIR\ttermpro.exe" "localhost 12323" "$INSTDIR\ttermpro.exe" 0
  CreateShortCut "$SMPROGRAMS\unixv1\Unix 2nd Edition Manual June 1972.lnk" "$INSTDIR\Unix_2nd_Edition_Manual_Jun72.pdf" "" "$INSTDIR\Unix_2nd_Edition_Manual_Jun72.pdf" 0 
SectionEnd

Section ReadME (required)
SectionIN RO
  File "readme.txt"
ExecShell "open" "$INSTDIR\readme.txt"
SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"

     
  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\unixv1"
  DeleteRegKey HKLM SOFTWARE\unixv1

  ; Remove shortcuts, if any
  Delete "$SMPROGRAMS\unixv1\*.*"

  ; Remove directories used
  RMDir /r "$SMPROGRAMS\unixv1"
  SetShellVarContext all
  RMDir /r "$SMPROGRAMS\unixv1"


  ; Remove files and uninstaller
  Delete $INSTDIR\uninstall.exe
  Delete $INSTDIR\images-20080625.tgz
  Delete $INSTDIR\m792low.load
  Delete $INSTDIR\pdp11.exe
  Delete $INSTDIR\readme.txt
  Delete $INSTDIR\simh.cfg
  Delete $INSTDIR\svntree-20081216.tar.gz
  Delete $INSTDIR\ttermpro.exe
  Delete $INSTDIR\ttpcmn.dll
  Delete $INSTDIR\ttpdlg.dll
  Delete $INSTDIR\ttpfile.dll
  Delete $INSTDIR\ttpset.dll
  Delete $INSTDIR\ttptek.dll
  Delete $INSTDIR\unixv1.cmd
  Delete $INSTDIR\unixv1.nsi
  Delete $INSTDIR\Unix_2nd_Edition_Manual_Jun72.pdf
  ;Delete $INSTDIR\*.*


  
  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the Operating System disk?" IDNO NoDeleteos
    Delete "$INSTDIR\rf0.dsk"
    Delete "$INSTDIR\rk0.dsk"

    ; RMDir "$INSTDIR\cpdest" ; skipped if no
  NoDeleteos:



  RMDir "$INSTDIR"

  
SectionEnd
