!define BASE_PATH "..\Binary\win32"
!define SETUP_NAME "DolphinSetup_32bit_14b"

; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Dolphin"
!define PRODUCT_VERSION "1.4b"
!define PRODUCT_PUBLISHER "Dolphin DevTeam"
!define PRODUCT_WEB_SITE "http://www.dolphin-emu.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!define MUI_WELCOMEFINISHPAGE_BITMAP "wizard.bmp"
    

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "Licence.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\DolphinWx.exe"
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${SETUP_NAME}.exe"
InstallDir "$PROGRAMFILES32\Dolphin"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show

Section "Hauptgruppe" SEC01
  SetOverwrite try
  
  ; --- copy executable
  SetOutPath "$INSTDIR"
  File "${BASE_PATH}\cg.dll"
  File "${BASE_PATH}\cgGL.dll"
  File "${BASE_PATH}\DolphinWx.exe"
  File "Dolphin.ini"

  ; --- copy plugins
  SetOutPath "$INSTDIR\Plugins"
  File "${BASE_PATH}\Plugins\Plugin_DSP.dll"
  File "${BASE_PATH}\Plugins\Plugin_PadDX9.dll"
  File "${BASE_PATH}\Plugins\Plugin_PadSimple.dll"
  File "${BASE_PATH}\Plugins\Plugin_VideoDX9.dll"
  File "${BASE_PATH}\Plugins\Plugin_VideoOGL.dll"

  ; --- copy help
  ; SetOutPath "$INSTDIR\Help"
  ; File "${BASE_PATH}\Help\Dolphin.chm"

  ; --- copy data directory
  SetOutPath "$INSTDIR\Data"
  File "${BASE_PATH}\Data\*.*"
  
  ; --- create data directories and copy IPLs
  SetOutPath "$INSTDIR\Data_EUR"
  File "${BASE_PATH}\Data_EUR\SRAM.raw"
  SetOutPath "$INSTDIR\Data_JAP"
  File "${BASE_PATH}\Data_JAP\SRAM.raw"
  SetOutPath "$INSTDIR\Data_USA"
  File "${BASE_PATH}\Data_USA\SRAM.raw"

  ; --- copy patches directory
  SetOutPath "$INSTDIR\Patches"
  File "${BASE_PATH}\Patches\*.*"
  
  ; -- create shortcuts
  SetOutPath "$INSTDIR"
  CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  CreateShortCut "$SMPROGRAMS\Dolphin\${PRODUCT_NAME}.lnk" "$INSTDIR\DolphinWx.exe"
  CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\DolphinWx.exe"

SectionEnd

Section -AdditionalIcons
  SetOutPath $INSTDIR
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\Dolphin\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\Dolphin\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\DolphinWx.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\DolphinWx.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


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

  Delete "$INSTDIR\Plugins\*.*"
  Delete "$INSTDIR\Data\*.*"
  Delete "$INSTDIR\Data_USA\*.*"
  Delete "$INSTDIR\Data_EUR\*.*"
  Delete "$INSTDIR\Data_JAP\*.*"
  Delete "$INSTDIR\Help\*.*"
  Delete "$INSTDIR\Patches\*.*"
  Delete "$INSTDIR\*.*"

  Delete "$SMPROGRAMS\Dolphin\Uninstall.lnk"
  Delete "$SMPROGRAMS\Dolphin\Website.lnk"
  Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
  Delete "$SMPROGRAMS\Dolphin\${PRODUCT_NAME}.lnk"

  RMDir "$SMPROGRAMS\Dolphin"
  RMDir "$INSTDIR\Plugins"
  RMDir "$INSTDIR\Help"
  RMDir "$INSTDIR\Data_USA"
  RMDir "$INSTDIR\Data_EUR"
  RMDir "$INSTDIR\Data_JAP"
  RMDir "$INSTDIR\Data"
  RMDir "$INSTDIR\Patches"
  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  
  ; Delete old registry keys
  DeleteRegKey HKCU "Software\\${PRODUCT_NAME}"
  
  ; SetAutoClose true
SectionEnd