+
+
+Function .onInit
+
+ ReadRegStr \$R0 HKLM \
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
+ "UninstallString"
+ StrCmp \$R0 "" done
+
+ MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
+ "${PROGRAM_NAME} is already installed. Click 'OK' to remove the previous version or 'Cancel' to cancel this upgrade." \
+ IDOK uninst
+ Abort
+
+ uninst:
+ ClearErrors
+ ExecWait '\$R0 _?=\$INSTDIR'
+ IfErrors uninstall_error
+
+ ReadRegStr \$R1 HKLM \
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
+ "UninstallString"
+ StrCmp \$R1 "" 0 done
+
+ Delete "\$INSTDIR\\uninstall.exe"
+ RMDir "\$INSTDIR"
+ goto done
+
+ uninstall_error:
+
+ MessageBox MB_OK|MB_ICONEXCLAMATION \
+ "Uninstaller did not complete successfully. Continue at your own risk..." \
+ IDOK done
+
+ done:
+
+ \${If} \${AtMostWinXP}
+ SectionSetFlags \${SecWASAPI} \${SF_RO}
+ \${Else}
+ SectionSetFlags \${SecWASAPI} \${SF_SELECTED}
+ \${EndIf}
+
+FunctionEnd
+
+Function .onInstSuccess
+
+ \${If} \${AtMostWinXP}
+ goto pa_no_wasapi
+ \${EndIf}
+
+ SectionGetFlags \${SecWASAPI} \$R0
+
+ IntOp \$R0 \$R0 & \${SF_SELECTED}
+ IntCmp \$R0 \${SF_SELECTED} pa_with_wasapi pa_no_wasapi
+
+ pa_with_wasapi:
+; VISTA .. 9, libportaudio with WASAPI is good.
+ Delete "\$INSTDIR\\bin\\libportaudio-2.xp"
+ goto endportaudio
+
+; Windows XP lacks support for WASAPI, Windows10 on some system has issues
+; http://tracker.ardour.org/view.php?id=6507
+ pa_no_wasapi:
+ Delete "\$INSTDIR\\bin\\libportaudio-2.dll"
+ Rename "\$INSTDIR\\bin\\libportaudio-2.xp" "\$INSTDIR\\bin\\libportaudio-2.dll"
+
+ endportaudio:
+
+FunctionEnd