; Zenipex Automagic Ends

  SetOutPath "$INSTDIR"
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  WriteIniStr "$INSTDIR\${PRODUCT_PUBLISHER}.url" "InternetShortcut" "URL" "${PUBLISHER_WEB_SITE}"
  WriteIniStr "$INSTDIR\${ZENIPEX_LIBRARY}.url" "InternetShortcut" "URL" "${ZENIPEX_LIBRARY_WEB_SITE}"
SectionEnd

Section -Redist
  SetShellVarContext all

  ExecWait '"$INSTDIR\redist\visualc\vcredist_x86_9.0.30729.17.exe" /quiet /passive /C /T:$TEMP"'
  ExecWait '"$INSTDIR\redist\visualc\vcredist_x64_9.0.30729.17.exe" /quiet /passive /C /T:$TEMP"'
  ExecWait '"$INSTDIR\redist\visualc\vcredist_x86_10.0.30319.01.exe" /q'
  ExecWait '"$INSTDIR\redist\visualc\vcredist_x64_10.0.30319.01.exe" /q'
  ExecWait '"$INSTDIR\redist\directx\DXSETUP.exe" /silent'
  ExecWait '"$INSTDIR\redist\openal\oalinst_2.0.7.0.exe" /silent'
SectionEnd

Section -Icons
  SetShellVarContext all
  !insertmacro MUI_STARTMENU_WRITE_BEGIN Application

  CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME_X86}.lnk" "$INSTDIR\${EXECUTABLE_FILE_X86}"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME_X64}.lnk" "$INSTDIR\${EXECUTABLE_FILE_X64}"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME} Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_PUBLISHER}.lnk" "$INSTDIR\${PRODUCT_PUBLISHER}.url"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\${ZENIPEX_LIBRARY}.lnk" "$INSTDIR\${ZENIPEX_LIBRARY}.url"
  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe"

  !insertmacro MUI_STARTMENU_WRITE_END
SectionEnd

Section "Desktop Icons"
  CreateShortCut "$DESKTOP\${PRODUCT_NAME_X86}.lnk" "$INSTDIR\${EXECUTABLE_FILE_X86}"
  CreateShortCut "$DESKTOP\${PRODUCT_NAME_X64}.lnk" "$INSTDIR\${EXECUTABLE_FILE_X64}"
SectionEnd

Section -Post
  SetShellVarContext all

  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\${EXECUTABLE_FILE_X86}"
  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\${EXECUTABLE_FILE_X86}"
  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
  SetShellVarContext all

;Temp Files
  !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP

  Delete "$INSTDIR\config\zenilib.xml.bak"
  Delete "$INSTDIR\stderr.txt"
  Delete "$INSTDIR\stdout.txt"

;Links
  Delete "$DESKTOP\${PRODUCT_NAME_X64}.lnk"
  Delete "$DESKTOP\${PRODUCT_NAME_X86}.lnk"
  Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"
  Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME_X64}.lnk"
  Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME_X86}.lnk"
  Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_NAME} Website.lnk"
  Delete "$SMPROGRAMS\$ICONS_GROUP\${PRODUCT_PUBLISHER}.lnk"
  Delete "$SMPROGRAMS\$ICONS_GROUP\${ZENIPEX_LIBRARY}.lnk"
  RMDir "$SMPROGRAMS\$ICONS_GROUP"

;Additional Items
  Delete "$INSTDIR\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\${PRODUCT_PUBLISHER}.url"
  Delete "$INSTDIR\${ZENIPEX_LIBRARY}.url"
  Delete "$INSTDIR\uninst.exe"

; Zenipex Automagic Begins
