; NSIS description file for Turtle Arena installer
;
; EDIT WITH CARE!
;
; This file is used to automatically build the installers in the
; openSUSE build service, don't break this!
;
; you have to copy SDL.dll and OpenAL32.dll here manually

!define VERSION "XXXVERSIONXXX"
!define RELEASE "XXXRELEASEXXX"

!define MODDIR "base"
!define PUBLISHER "The Turtle Arena Team"
!define URL "http://turtlearena.googlecode.com/"

!define GAMENAME "Turtle Arena"
!define CLIENT "turtlearena.x86.exe"
!define SERVER "turtlearena-server.x86.exe"
!define GAMEDIR "Turtle Arena"
!define GAME_FSNAME "turtlearena"

; !define MODDIR "baseq3"
; !define PUBLISHER "The ioquake3 Team"
; !define URL "http://ioquake3.org/"
;
; !define GAMENAME "ioquake3" ; This could be something like "Quake III Arena"
; !define CLIENT "ioquake3.x86.exe"
; !define SERVER "ioq3ded.x86.exe"
; !define GAMEDIR "ioquake3"
; !define GAME_FSNAME "ioquake3"

!define MULTIUSER_MUI
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "Software\${GAME_FSNAME}"
!define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "Install_Mode"
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "Software\${GAME_FSNAME}"
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME "Install_Dir"
!define MULTIUSER_INSTALLMODE_INSTDIR "${GAMEDIR}"
!include MultiUser.nsh

!include "MUI2.nsh"
!define MUI_ICON "../quake3.ico"

; The name of the installer
Name "${GAMENAME} ${VERSION}"

; The file to write
OutFile "${GAME_FSNAME}-${VERSION}-${RELEASE}.x86.exe"

; The default installation directory
; set by Multiuser.nsh
;InstallDir "$PROGRAMFILES\${GAMEDIR}"

; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
; handled by Multiuser.nsh
;InstallDirRegKey HKLM "Software\${GAME_FSNAME}" "Install_Dir"

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

!define MUI_ABORTWARNING

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

!insertmacro MULTIUSER_PAGE_INSTALLMODE
;!insertmacro MUI_PAGE_LICENSE "../../../COPYING.txt"
!define MUI_COMPONENTSPAGE_NODESC
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

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

!insertmacro MUI_LANGUAGE "English"

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

;--------------------------------
;Multiuser stuff
Function .onInit
  !insertmacro MULTIUSER_INIT
FunctionEnd

Function un.onInit
  !insertmacro MULTIUSER_UNINIT
FunctionEnd

; The stuff to install
Section "${GAMENAME} ${VERSION}-${RELEASE} (required)"

  SectionIn RO

  ; Set output path to the installation directory.
  SetOutPath $INSTDIR

!ifndef USE_INTERNAL_SPEEX
  File "libspeex.dll"
!endif
!ifndef USE_INTERNAL_ZLIB
  File "zlib1.dll"
!endif
!ifndef USE_INTERNAL_JPEG
  File "jpeg8c.dll"
!endif

  ; Put file there
  File "../../build/release-mingw32-x86/${SERVER}"
  File "../../build/release-mingw32-x86/${CLIENT}"
!ifdef USE_RENDERER_DLOPEN
  File "../../build/release-mingw32-x86/renderer_opengl1_x86.dll"
!endif

  File "GPL-2.txt"
  File "CC-BY-SA-3.0.txt"
  File "COPYRIGHTS.txt"
  File "CREDITS.txt"
  File "README.txt"

  SetOutPath "$INSTDIR\${MODDIR}"
  File "XXXASSETPATHXXX/assets0.pk3"
  File "XXXASSETPATHXXX/assets1-qvms.pk3"
  File "XXXASSETPATHXXX/assets3-game-patch.pk3"

  ; Write the installation path into the registry
  WriteRegStr SHCTX "Software\${GAME_FSNAME}" ${MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME} "$INSTDIR"
  WriteRegStr SHCTX "Software\${GAME_FSNAME}" ${MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME} "$MultiUser.InstallMode"

  ; Write the uninstall keys for Windows
  WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "DisplayName" "${GAMENAME}"
  WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "DisplayVersion" "${VERSION}-${RELEASE}"
  WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "Publisher" "${PUBLISHER}"
  WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "URLInfoAbout" "${URL}"
  WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "NoModify" 1
  WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}" "NoRepair" 1
  WriteUninstaller "uninstall.exe"

SectionEnd

; Optional section (can be disabled by the user)
Section "Music"

  SetOutPath "$INSTDIR\${MODDIR}"

  File "XXXASSETPATHXXX/assets2-music.pk3"

SectionEnd

Section "Start Menu Shortcuts"

  CreateDirectory "$SMPROGRAMS\${GAMENAME}"
  CreateShortCut "$SMPROGRAMS\${GAMENAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\${GAMENAME}\${GAMENAME}.lnk" "$INSTDIR\${CLIENT}" "" "$INSTDIR\${SERVER}" 0

SectionEnd

Section "SDL library"

  SetOutPath $INSTDIR

  File "SDL.dll"

SectionEnd

!ifdef USE_OPENAL_DLOPEN
Section "OpenAL-Soft library"

  SetOutPath $INSTDIR

  File "OpenAL32.dll"

SectionEnd
!endif

!ifdef USE_CURL_DLOPEN
Section "libcurl"

  SetOutPath $INSTDIR

  File "libcurl-4.dll"

SectionEnd
!endif

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

; Uninstaller

Section "Uninstall"

  ; Remove registry keys
  DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${GAME_FSNAME}"
  DeleteRegKey SHCTX "Software\${GAME_FSNAME}"

  ; Remove files and uninstaller
  Delete $INSTDIR\${MODDIR}\assets0.pk3
  Delete $INSTDIR\${MODDIR}\assets1-qvms.pk3
  Delete $INSTDIR\${MODDIR}\assets2-music.pk3
  Delete $INSTDIR\${CLIENT}
  Delete $INSTDIR\${SERVER}
!ifdef USE_RENDERER_DLOPEN
  Delete $INSTDIR\renderer_opengl1_x86.dll
!endif

  Delete $INSTDIR\GPL-2.txt
  Delete $INSTDIR\CC-BY-SA-3.0.txt
  Delete $INSTDIR\COPYRIGHTS.txt
  Delete $INSTDIR\CREDITS.txt
  Delete $INSTDIR\README.txt

!ifndef USE_INTERNAL_SPEEX
  Delete $INSTDIR\libspeex.dll
!endif
!ifndef USE_INTERNAL_ZLIB
  Delete $INSTDIR\zlib1.dll
!endif
!ifndef USE_INTERNAL_JPEG
  Delete $INSTDIR\jpeg8c.dll
!endif

  Delete $INSTDIR\SDL.dll
!ifdef USE_OPENAL_DLOPEN
  Delete $INSTDIR\OpenAL32.dll
!endif
!ifdef USE_CURL_DLOPEN
  Delete $INSTDIR\libcurl-4.dll
!endif

  Delete $INSTDIR\uninstall.exe

  ; Remove shortcuts, if any
  Delete "$SMPROGRAMS\${GAMENAME}\Uninstall.lnk"
  Delete "$SMPROGRAMS\${GAMENAME}\${GAMENAME}.lnk"

  ; Remove directories used
  RMDir "$SMPROGRAMS\${GAMENAME}"
  RMDir "$INSTDIR\${MODDIR}"
  RMDir "$INSTDIR"

SectionEnd
