; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "VisualBoyAdvance-M"
!define PRODUCT_VERSION "2.1.0"
!define PRODUCT_PUBLISHER "visualboyadvance"
!define PRODUCT_WEB_SITE "https://vba-m.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\visualboyadvance-m.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
#If you're building this, point it to your mingw installation folder
!define MINGW32_ROOT "D:\Development\msys64\mingw32\bin"
!define MINGW64_ROOT "D:\Development\msys64\mingw64\bin"
#This is where you installed vba-m with make install.
!define VBAM_INSTALL_ROOT "D:\Development\msys64\opt\vbam"
#comment this out if not building with msys2
!define MSYS2

!ifdef MSYS2
  OutFile "vba-m-${PRODUCT_VERSION}-msys2.exe"
!else
  OutFile "vba-m-${PRODUCT_VERSION}.exe
!endif
SetCompressor /SOLID lzma
ShowInstDetails show
ShowUninstDetails show
XPStyle on

!packhdr tmpexe.tmp "upx --lzma -9 --compress-icons=0 tmpexe.tmp"

BrandingText "VisualBoyAdvance-M Version ${PRODUCT_VERSION}" 

; MUI 1.67 compatible ------
!include "MUI.nsh"
!include "Sections.nsh"
!include "x64.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"

;--------------------------------
;Version resource
VIProductVersion "${PRODUCT_VERSION}.0"
VIAddVersionKey "ProductName" "visualboyadvance-m"
VIAddVersionKey "FileVersion" "${PRODUCT_VERSION}"
VIAddVersionKey "ProductVersion" "${PRODUCT_VERSION}"
VIAddVersionKey "LegalCopyright" ""
!ifdef MSYS2
VIAddVersionKey "FileDescription" "visualboyadvance-m GBA Emulator (built with msys2)"
!else
VIAddVersionKey "FileDescription" "visualboyadvance-m GBA Emulator"
!endif

;--------------------------------
;Reserve files used in .onInit
;for faster start-up
ReserveFile "${NSISDIR}\Plugins\unicode\System.dll"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
!insertmacro MUI_RESERVEFILE_LANGDLL

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE ".\doc\gpl.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\visualboyadvance-m.exe"
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "vba-m_${PRODUCT_VERSION}_setup.exe"
InstallDir "$PROGRAMFILES64\VisualBoyAdvance-M"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show

Function .onInit
  Aero::Apply
FunctionEnd

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  SetOverwrite ifnewer
  !ifdef MSYS2
    File "${VBAM_INSTALL_ROOT}\bin\visualboyadvance-m.exe"
    File "${MINGW64_ROOT}\libwinpthread-1.dll"
    File "${MINGW64_ROOT}\libpng16-16.dll"
    File "${MINGW64_ROOT}\libintl-8.dll"
    File "${MINGW64_ROOT}\SDL2.dll"
    File "${MINGW64_ROOT}\libsfml-network-2.dll"
    File "${MINGW64_ROOT}\libsfml-system-2.dll"
    File "${MINGW64_ROOT}\wxbase30u_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxbase30u_net_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxbase30u_xml_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxmsw30u_adv_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxmsw30u_core_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxmsw30u_html_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxmsw30u_gl_gcc_custom.dll"
    File "${MINGW64_ROOT}\wxmsw30u_xrc_gcc_custom.dll"
    File "${MINGW64_ROOT}\zlib1.dll"
    File "${MINGW64_ROOT}\libiconv-2.dll"
    File "${MINGW64_ROOT}\libgcc_s_seh-1.dll"
    File "${MINGW64_ROOT}\libstdc++-6.dll"
    File "${MINGW64_ROOT}\libjpeg-8.dll"
    File "${MINGW64_ROOT}\libtiff-5.dll"
    File "${MINGW64_ROOT}\libexpat-1.dll"
    File "${MINGW64_ROOT}\liblzma-5.dll"
  !else
    File "${VBAM_INSTALL_ROOT}\bin\visualboyadvance-m.exe"
  !endif
    CreateDirectory "$SMPROGRAMS\VisualBoyAdvance-M"
    CreateShortCut "$SMPROGRAMS\VisualBoyAdvance-M\VisualBoyAdvance.lnk" "$INSTDIR\visualboyadvance-m.exe"
    CreateShortCut "$DESKTOP\VisualBoyAdvance.lnk" "$INSTDIR\visualboyadvance-m.exe"
SectionEnd

Section "Localization"
    SetOutPath "$INSTDIR\locale"
    File "${VBAM_INSTALL_ROOT}\share\locale\ar\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\br\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\bs\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ca\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ca_ES\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\cs\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\da\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\da_DK\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\de\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\de_DE\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\el\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\el_GR\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\en\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\en_GB\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\en_US\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_419\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_AR\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_CL\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_CO\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_ES\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_MX\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_PR\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\es_US\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\fil\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\fr\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\fr_CA\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\fr_FR\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\gl\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\haw\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\he\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\he_IL\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\hr\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\hu\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\hu_HU\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\id\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\id_ID\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\it\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\it_IT\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ja\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ja_JP\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\jv\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ko\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ko_KR\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ms_MY\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\nb\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\nl\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\nl_NL\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\no\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\pl\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\pl_PL\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\pt\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\pt_PT\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\pt_BR\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ru\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\ru_RU\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\sk\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\sk_SK\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\sr\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\su\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\sv\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\tk\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\tr\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh_CN\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh_CN.GB2312\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh_HK\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh_TW\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh_TW.Big5\LC_MESSAGES\wxvbam.mo"
    File "${VBAM_INSTALL_ROOT}\share\locale\zh-Hans\LC_MESSAGES\wxvbam.mo"
SectionEnd

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

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\visualboyadvance-m.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\visualboyadvance-m.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\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\uninst.exe"
  Delete "$INSTDIR\vbam.exe"
  Delete "$INSTDIR\visualboyadvance-m.exe"

  Delete "$SMPROGRAMS\VisualBoyAdvance-M\Uninstall.lnk"
  Delete "$SMPROGRAMS\VisualBoyAdvance-M\Website.lnk"
  Delete "$DESKTOP\VisualBoyAdvance.lnk"
  Delete "$SMPROGRAMS\VisualBoyAdvance-M\VisualBoyAdvance.lnk"

  RMDir "$SMPROGRAMS\VisualBoyAdvance-M"
  RMDir "$INSTDIR"

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