!define PKG_DIR "pkg-win"

!ifndef VERSION
  !error "VERSION not defined (pass with -DVERSION=...)"
!endif

!ifndef SHORT_SHA
  !error "SHORT_SHA not defined (pass with -DSHORT_SHA=...)"
!endif

Name "SplatTool"
OutFile "SplatTool-${VERSION}-${SHORT_SHA}-Setup.exe"
InstallDir "$PROGRAMFILES64\SplatTool"
RequestExecutionLevel admin   ; Needed to write to Program Files

Page directory
Page instfiles

Section "Install Files"

    SetOutPath "$INSTDIR"

    File /r "${PKG_DIR}\*.*"

    ; Create shortcuts
    CreateDirectory "$SMPROGRAMS\SplatTool"
    CreateShortCut "$DESKTOP\SplatTool.lnk" "$INSTDIR\SplatTool.exe" "" "$INSTDIR\icon.ico"
    CreateShortCut "$SMPROGRAMS\SplatTool\SplatTool.lnk" "$INSTDIR\SplatTool.exe" "" "$INSTDIR\icon.ico"

    WriteUninstaller "$INSTDIR\Uninstall.exe"

    ; Register in Add/Remove Programs
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SplatTool" "DisplayName" "SplatTool"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SplatTool" "UninstallString" "$INSTDIR\Uninstall.exe"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SplatTool" "DisplayIcon" "$INSTDIR\icon.ico"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SplatTool" "DisplayVersion" "${VERSION}"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SplatTool" "Publisher" "CrafterPika"

SectionEnd

Section "Uninstall"

    Delete "$INSTDIR\SplatTool.exe"
    Delete "$INSTDIR\icon.ico"

    RMDir /r "$INSTDIR"

    Delete "$DESKTOP\SplatTool.lnk"
    Delete "$SMPROGRAMS\SplatTool\SplatTool.lnk"
    RMDir "$SMPROGRAMS\SplatTool"

    ; Remove registry keys on uninstall
    DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SplatTool"

SectionEnd
