; Script generated by the HM NIS Edit Script Wizard.

;---------------------
;Include Modern UI
!include "MUI.nsh"

;--------------------------------
;General

!define PRODUCT_NAME "FreeDoko"
!define PRODUCT_VERSION "FREEDOKO_VERSION"
!define PRODUCT_AUTHORS "Borg Enders und Diether Knof"
!define PRODUCT_PUBLISHER "${PRODUCT_AUTHORS}"
!define PRODUCT_WEB_SITE "http://free-doko.sourceforge.net/"

;Name and file
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME}_${PRODUCT_VERSION}.de.Setup.exe"

;Default installation folder
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"

;Get installation folder from registry if available
;InstallDirRegKey HKCU "Software\Modern UI Test" ""
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""

;--------------------------------
;Pages

Page custom Uebersichtsseite
;!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES

;--------------------------------
;Interface Settings

!define MUI_ABORTWARNING

;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "German"

;--------------------------------
;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 "FreeDoko.de.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

;--------------------------------
;Variables

Var CREATE_DESKTOP_ICON
Var ICONS_GROUP


;--------------------------------
;Installer Sections

Function .onInit
  ;!insertmacro MUI_LANGDLL_DISPLAY
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "FreeDoko.de.ini"

  WriteINIStr "FreeDoko.de.ini" "Field 3" "State" $INSTDIR
  WriteINIStr "FreeDoko.de.ini" "Field 5" "State" ${PRODUCT_NAME}
  WriteINIStr "FreeDoko.de.ini" "Field 6" "State" "1"
FunctionEnd

Function Uebersichtsseite
  !insertmacro MUI_HEADER_TEXT "${PRODUCT_NAME} ${PRODUCT_VERSION} Installation" "Übersicht"
  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "FreeDoko.de.ini"
FunctionEnd

Section "Installation"
  ;Read the values from
  ;ReadINIStr $INSTDIR			"FreeDoko.de.ini" "Field 3" "State"
  ;ReadINIStr $ICONS_GROUP		"FreeDoko.de.ini" "Field 5" "State"
  ;ReadINIStr $CREATE_DESKTOP_ICON	"FreeDoko.de.ini" "Field 6" "State"
  !insertmacro MUI_INSTALLOPTIONS_READ $CREATE_DESKTOP_ICON "FreeDoko.de.ini" "Field 6" "State"
  !insertmacro MUI_INSTALLOPTIONS_READ $ICONS_GROUP "FreeDoko.de.ini" "Field 5" "State"
  !insertmacro MUI_INSTALLOPTIONS_READ $INSTDIR "FreeDoko.de.ini" "Field 3" "State"


  SetOutPath "$INSTDIR"
  SetOverwrite try
  File /r "${PRODUCT_NAME}_${PRODUCT_VERSION}\*"

  ;Display a messagebox if check box was checked
  StrCmp $CREATE_DESKTOP_ICON "0" +2
    CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.bat" "" "$INSTDIR\${PRODUCT_NAME}.ico"

  StrCmp $ICONS_GROUP "" EndIconGroup
  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME}.lnk" "$INSTDIR\${PRODUCT_NAME}.bat" "" "$INSTDIR\${PRODUCT_NAME}.ico"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\uninstall.lnk" "$INSTDIR\uninst.exe"
  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP\Dokumentation"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Dokumentation\Handbuch.lnk" "$INSTDIR\doc\manual\de\overview.html"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Dokumentation\Regeln.lnk" "$INSTDIR\doc\manual\de\rules.html"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Dokumentation\Einführung.lnk" "$INSTDIR\doc\de\Einfuehrung.txt"
  EndIconGroup:
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\${PRODUCT_NAME}.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}" "DisplayIcon" "$INSTDIR\${PRODUCT_NAME}.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}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstDir" "$INSTDIR"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "IconsGroup" "$ICONS_GROUP"

  WriteRegStr HKLM "Software\${PRODUCT_NAME}" "Version" "${PRODUCT_VERSION}"
  WriteRegStr HKLM "Software\${PRODUCT_NAME}" "Directory" "$INSTDIR"
  WriteRegStr HKLM "Software\${PRODUCT_NAME}" "Help Directory" "$INSTDIR\doc\manual"
SectionEnd


Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) wurde erfolgreich deinstalliert."
FunctionEnd

Function un.onInit
  ;!insertmacro MUI_UNGETLANGUAGE
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Möchten Sie $(^Name) und alle seinen Komponenten deinstallieren?" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  ;!insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP

  ReadRegStr $INSTDIR ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstDir"
  ReadRegStr $ICONS_GROUP ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "IconsGroup"

  RMDir /r "$INSTDIR"
  StrCmp $ICONS_GROUP "" +2
  RMDir /r "$SMPROGRAMS\$ICONS_GROUP"
  Delete "$DESKTOP\${PRODUCT_NAME}.lnk"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  DeleteRegKey HKLM "Software\${PRODUCT_NAME}"
  SetAutoClose true
SectionEnd
