######################################
### VDMSound NSIS Installer Script ###
########## By  Colin Snover ##########
######################################
##
#### todo: add VDMSPath to PATH envvar
##
###### figure out stupid dumbass piece
##     of shit  uninstaller uninstall-
##     ing files when I tell it not to
##     and then the installer does the
##     stupid    I-am-not-registering-
##     these-DLLs dance.

SetCompressor bzip2 # must be before anything else

### ModernUI Setup

	!include "MUI.nsh" # ModernUI header

	## program information
	!define MUI_PRODUCT "VDMSound"
	!define MUI_VERSION "2.1.0"
	!define MUI_DESCRIPTION "VDMSound is a SoundBlaster/AdLib emulator for Windows NT's Virtual DOS Machine."
	!define MUI_AUTHOR "Vlad Romascanu"
	!define MUI_CONTACT "ntvdm@hotmail.com"
	!define MUI_INFO_URL "http://ntvdm.cjb.net/"
	!define MUI_HELP_URL "http://ntvdm.cjb.net/faq/"
	!define MUI_UPDATE_URL "http://ntvdm.cjb.net/download/"
	!define MUI_UNINSTALLER_FILENAME "uninst.exe"
	!define INSTALLFROM "C:\sbin\VDMSound"         # where the installer will compile files from
	!define HAVE_RESHACK "C:\sbin\Resource Hacker" # where Resource Hacker is
 	!define HAVE_UPX "${NSISDIR}"                  # where the UPX installer packer is

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; TOUCH AFTER THIS LINE WITHOUT KNOWING WHAT YOU ARE DOING AND DIEEEEEE ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	## pages to be displayed
	!define MUI_WELCOMEPAGE
	!define MUI_CUSTOMFUNCTION_LICENSE_PRE checkPrevInstall
	!define MUI_LICENSEPAGE
	!define MUI_DIRECTORYPAGE
	!define MUI_COMPONENTSPAGE
		!define MUI_COMPONENTSPAGE_SMALLDESC
	!define MUI_CUSTOMFUNCTION_INSTFILES_PRE checkAllUsers
	!define MUI_FINISHPAGE
		!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\readme.rtf"
		!define MUI_FINISHPAGE_NOAUTOCLOSE # for debugging
	!define MUI_ABORTWARNING
	!define MUI_UNINSTALLER
		!define MUI_UNCONFIRMPAGE

## ALL BROKEN
#  	!insertmacro MUI_UNPAGECOMMAND_CONFIRM
#  	!insertmacro MUI_UNPAGECOMMAND_INSTFILES
# 	!insertmacro MUI_UNFINISHHEADER
# 	!insertmacro MUI_UNPAGECOMMAND_COMPONENTS ## does not exist "yet"

### ModernUI Settings

	## interface settings
	!define MUI_UI "${NSISDIR}\Contrib\UIs\modern.exe"
	!define MUI_UI_HEADERBITMAP "${NSISDIR}\Contrib\UIs\modern_headerbmp.exe"
	!define MUI_UI_SMALLDESCRIPTION "${NSISDIR}\Contrib\UIs\modern_smalldesc.exe"
	!define MUI_ICON "${NSISDIR}\Contrib\Icons\yi-simple2_install.ico"
	!define MUI_UNICON "${NSISDIR}\Contrib\Icons\yi-simple2_uninstall.ico"
	!define MUI_CHECKBITMAP "${NSISDIR}\Contrib\Icons\yi-simple2_check.bmp"
	!define MUI_FONT "Tahoma"
	!define MUI_FONTSIZE "8"
	!define MUI_FONT_HEADER "Tahoma"
	!define MUI_FONTSIZE_HEADER "11"
	!define MUI_FONTSTYLE_HEADER "700"
	!define MUI_FONT_TITLE "Verdana"
	!define MUI_FONTSIZE_TITLE "12"
	!define MUI_FONTSTYLE_TITLE "700"
	!define MUI_INSTALLCOLORS /windows
	!define MUI_PROGRESSBAR "smooth"
	!define MUI_HEADERBITMAP "${NSISDIR}\Contrib\Icons\modern-header 2.bmp"
	!define MUI_SPECIALINI "${NSISDIR}\Contrib\Modern UI\ioSpecial.ini"
	!define MUI_SPECIALBITMAP "${NSISDIR}\Contrib\Icons\modern-wizard.bmp"

	## language includes
	!insertmacro MUI_LANGUAGE "English"
	!insertmacro MUI_LANGUAGE "French"
	!insertmacro MUI_LANGUAGE "German"
	!insertmacro MUI_LANGUAGE "Spanish"
#	!insertmacro MUI_LANGUAGE "SimpChinese"
	!insertmacro MUI_LANGUAGE "TradChinese"
	!insertmacro MUI_LANGUAGE "Japanese"
# 	!insertmacro MUI_LANGUAGE "Korean" ## error in this MUI_LANGUAGE
	!insertmacro MUI_LANGUAGE "Italian"
	!insertmacro MUI_LANGUAGE "Dutch"
	!insertmacro MUI_LANGUAGE "Danish"
	!insertmacro MUI_LANGUAGE "Greek"
	!insertmacro MUI_LANGUAGE "Russian"
	!insertmacro MUI_LANGUAGE "PortugueseBR"
	!insertmacro MUI_LANGUAGE "Polish"
	!insertmacro MUI_LANGUAGE "Ukrainian"
	!insertmacro MUI_LANGUAGE "Czech"
#	!insertmacro MUI_LANGUAGE "Slovak"
#	!insertmacro MUI_LANGUAGE "Croatian"
# 	!insertmacro MUI_LANGUAGE "Bulgarian" ## error in this MUI_LANGUAGE
#	!insertmacro MUI_LANGUAGE "Hungarian"
	!insertmacro MUI_LANGUAGE "Thai"
	!insertmacro MUI_LANGUAGE "Romanian"
#	!insertmacro MUI_LANGUAGE "Macedonian"
	!insertmacro MUI_LANGUAGE "Turkish"

# 	!define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
# 	!define MUI_LANGDLL_REGISTRY_KEY "Software\${MUI_PRODUCT}"
# 	!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"

	## reserve files (to make installer start faster; these files go first in the archive)
	!insertmacro MUI_RESERVEFILE_WELCOMEFINISHPAGE
# 	!insertmacro MUI_RESERVEFILE_INSTALLOPTION ## doesn't exist
	!insertmacro MUI_RESERVEFILE_LANGDLL
	!insertmacro MUI_RESERVEFILE_SPECIALINI
	!insertmacro MUI_RESERVEFILE_SPECIALBITMAP

### NSIS Settings

# 	!ifdef HAVE_RESHACK ## there is no multipass !packhdr
# 		!packhdr tmp.dat "${HAVE_RESHACK}\ResHacker.exe -addoverwrite tmp.dat, tmp.dat, vdmsound.res, versioninfo,1,"
# 	!endif
	!ifdef HAVE_UPX
		!packhdr tmp.dat "${HAVE_UPX}\upx -9 tmp.dat"
	!endif

	OutFile "${MUI_PRODUCT}${MUI_VERSION}.exe"     # installer executable name
	XPStyle on                                     # XP style manifest, hey why the fuck not?

	InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"
	InstallDirRegKey HKLM "SYSTEM\CurrentControlSet\Session Manager\Environment" "VDMSPath"

	ShowInstDetails show
	ShowUninstDetails show

	LicenseData /LANG=${LANG_ENGLISH} "${NSISDIR}\license.en.txt"
	LicenseData /LANG=${LANG_FRENCH} "${NSISDIR}\license.fr.txt"
	LicenseData /LANG=${LANG_GERMAN} "${NSISDIR}\license.de.txt"
	LicenseData /LANG=${LANG_SPANISH} "${NSISDIR}\license.es.txt"
	LicenseData /LANG=${LANG_TRADCHINESE} "${NSISDIR}\license.cn.big5"
	LicenseData /LANG=${LANG_JAPANESE} "${NSISDIR}\license.jp.sjs"
	LicenseData /LANG=${LANG_ITALIAN} "${NSISDIR}\license.it.txt"
	LicenseData /LANG=${LANG_DUTCH} "${NSISDIR}\license.nl.txt"
	LicenseData /LANG=${LANG_DANISH} "${NSISDIR}\license.da.txt"
	LicenseData /LANG=${LANG_GREEK} "${NSISDIR}\license.el.txt"
	LicenseData /LANG=${LANG_RUSSIAN} "${NSISDIR}\license.ru.txt"
	LicenseData /LANG=${LANG_PORTUGESEBR} "${NSISDIR}\license.pt_br.txt"
	LicenseData /LANG=${LANG_POLISH} "${NSISDIR}\license.pl.txt"
	LicenseData /LANG=${LANG_UKRANIAN} "${NSISDIR}\license.ua.txt"
	LicenseData /LANG=${LANG_CZECH} "${NSISDIR}\license.cz.txt"
	LicenseData /LANG=${LANG_THAI} "${NSISDIR}\license.th.txt"
	LicenseData /LANG=${LANG_ROMANIAN} "${NSISDIR}\license.ro.txt"
	LicenseData /LANG=${LANG_TURKISH} "${NSISDIR}\license.tr.txt"

### Predefined Functions

	Function .onInit
		!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "${NSISDIR}\Contrib\Modern UI\ioSpecial.ini" "ioSpecial.ini" # extract the special InstallOptions
		!insertmacro MUI_LANGDLL_DISPLAY # choose a language prior to installation
	FunctionEnd

	Function un.onInit
		!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "${NSISDIR}\Contrib\Modern UI\ioSpecial.ini" "ioSpecial.ini" # extract the special InstallOptions
		!insertmacro MUI_LANGDLL_DISPLAY
		MessageBox MB_YESNO|MB_ICONQUESTION "This will uninstall VDMSound. Continue?" IDYES NoAbort IDNO Abort
		Abort:
			Quit
		NoAbort:
			MessageBox MB_YESNO|MB_ICONQUESTION "Keep your VDMS.INI, AUTOEXEC.VDMS and CONFIG.VDMS files?$\r$\nNote: this doesn't work." IDYES remFiles IDNO noRemFiles
			remFiles:
				!define REMFILES
			noRemFiles:
	FunctionEnd

	Function checkAllUsers
#		MessageBox MB_YESNO|MB_ICONQUESTION "Install for ALL USERS?$\r$\n(Otherwise, ${MUI_PRODUCT} will only be installed for the current user.)" IDYES AllUserInstall IDNO ThisUserInstall
#			AllUserInstall:
				!define ALLUSERS
#			ThisUserInstall:
	FunctionEnd

	Function checkPrevInstall
		ClearErrors
		ReadRegStr $1 HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{8ECBE643-8230-11D5-9D6B-00A024112F81}" "DisplayName"
			IfErrors check2 prevInstall
			check2:
				ClearErrors
				ReadRegStr $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{8ECBE643-8230-11D5-9D6B-00A024112F81}" "DisplayName"
				IfErrors noPrevInstall prevInstall
			prevInstall:
				ClearErrors
				MessageBox MB_YESNO|MB_ICONEXCLAMATION "Previous version of VDMSound detected.$\r$\nIt is HIGHLY recommended that you uninstall the old version first.$\r$\nWould you like to automatically uninstall the previous version?" IDYES uninstall IDNO noUninstall
				uninstall:
					ExecWait "MsiExec.exe /X{8ECBE643-8230-11D5-9D6B-00A024112F81}"
					UnRegDLL "$INSTDIR\Launchpad.dll"
					Delete "$INSTDIR\Launchpad.dll"
					UnRegDLL "$INSTDIR\EmuPPDAC.dll"
					Delete "$INSTDIR\EmuPPDAC.dll"
					Delete "$INSTDIR\joy1.map"
					Delete "$INSTDIR\joy2.map"
					Delete "$INSTDIR\joy3.map"
					Delete "$INSTDIR\VDMConfig.GID"
					ClearErrors
					IfFileExists "$INSTDIR\Launchpad.dll" launchpadNoDelete
					launchpadNoDelete:
						SetRebootFlag true
						MessageBox MB_OKCANCEL "Previous version of VDMSound could not be completely uninstalled.$\r$\nPlease click 'OK' to reboot your system now, or 'cancel' to reboot later. You must reboot before installation can successfully be completed." IDOK rebootNow IDCANCEL rebootLater
						rebootNow:
							WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" "VDMSound Installer" "$CMDLINE"
							MessageBox MB_OK "Installation will be restarted upon reboot of computer."
							Reboot
						rebootLater:
							WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" "VDMSound Installer" "$CMDLINE"
							MessageBox MB_OK "Installation will be restarted upon reboot of computer."
							Quit
				noUninstall:
					ClearErrors
			noPrevInstall:
					ClearErrors
	FunctionEnd

### Installer

	## quick-install packages
	InstType "Complete"
	InstType "Just VDMSound"
	InstType /COMPONENTSONLYONCUSTOM

	## vdmsound files

	SubSection "VDMSound" DESC_vdms
		Section "VDMSound Core" DESC_core
			SectionIn 1 2 RO
			SetOutPath "$INSTDIR"
			File "${INSTALLFROM}\DOSDRV.EXE"
			File "${INSTALLFROM}\DMAController.dll"
			File "${INSTALLFROM}\DSoundDevice.dll"
			File "${INSTALLFROM}\VDDLoader.dll"
			File "${INSTALLFROM}\VDMConfig.dll"
			File "${INSTALLFROM}\WaveDevice.dll"

			RegDLL "$INSTDIR\DMAController.dll"
			RegDLL "$INSTDIR\DSoundDevice.dll"
			RegDLL "$INSTDIR\VDDLoader.dll"
			RegDLL "$INSTDIR\VDMConfig.dll"
			RegDLL "$INSTDIR\WaveDevice.dll"

			File "${INSTALLFROM}\readme.rtf"
			File "${INSTALLFROM}\CHANGES.txt"
			File "${INSTALLFROM}\license.txt"

			File "${INSTALLFROM}\VDMSound.ico"
# 			File "${INSTALLFROM}\VDMSRun.pif" ## vlad doesn't want these?
# 			File "${INSTALLFROM}\VDMSRun.bat" ## vlad doesn't want these?

			File "${INSTALLFROM}\VDMS.INI"
			File "${INSTALLFROM}\AUTOEXEC.VDMS"
			File "${INSTALLFROM}\CONFIG.VDMS"
		SectionEnd
		Section "VDMSound Help" DESC_help
			SectionIn 1 2
			File "${INSTALLFROM}\VDMConfig.cnt"
			File "${INSTALLFROM}\VDMConfig.hlp"
		SectionEnd
		Section "SoundBlaster" DESC_sndb
			SectionIn 1 2
			File "${INSTALLFROM}\EmuSBCompat.dll"
			RegDLL "$INSTDIR\EmuSBCompat.dll"
		SectionEnd
		Section "AdLib" DESC_adlb
			SectionIn 1 2
			File "${INSTALLFROM}\EmuAdlib.dll"
			RegDLL "$INSTDIR\EmuAdlib.dll"
		SectionEnd
		SubSection "MPU-401" DESC_m401
			Section "MPU-401 Core" DESC_mcor
				SectionIn 1 2
					File "${INSTALLFROM}\EmuMPU401.dll"
				RegDLL "$INSTDIR\EmuMPU401.dll"
				File "${INSTALLFROM}\MIDIDevice.dll"
				RegDLL "$INSTDIR\MIDIDevice.dll"
				File "${INSTALLFROM}\MIDIIndicator.dll"
				RegDLL "$INSTDIR\MIDIIndicator.dll"
				File "${INSTALLFROM}\MIDIToolkit.dll"
				RegDLL "$INSTDIR\MIDIToolkit.dll"
				File "${INSTALLFROM}\identity.map"
			SectionEnd
			Section "MT2GM patch" DESC_gm32
				SectionIn 1 2
					File "${INSTALLFROM}\mt2gm.map"
			SectionEnd
			Section "GM2MT patch" DESC_32gm
				SectionIn 1 2
					File "${INSTALLFROM}\gm2mt.map"
			SectionEnd
		SubSectionEnd
		Section "PPDAC" DESC_pdac
			SectionIn 1 2
			File "${INSTALLFROM}\EmuPPDAC.dll"
			RegDLL "$INSTDIR\EmuPPDAC.dll"
		SectionEnd
		SubSection "Joystick" DESC_joys
			Section "Joystick Core" DESC_jcor
				SectionIn 1 2
					File "${INSTALLFROM}\EmuJoystick.dll"
				RegDLL "$INSTDIR\EmuJoystick.dll"
			SectionEnd
			Section "4-button 4-axis map" DESC_joy1
				SectionIn 1 2
					File "${INSTALLFROM}\joy1.map"
			SectionEnd
			Section "Two 2-button 2-axis map" DESC_joy2
				SectionIn 1 2
					File "${INSTALLFROM}\joy2.map"
			SectionEnd
			Section "2-button 3-axis rudder & POV map" DESC_joy3
				SectionIn 1 2
					File "${INSTALLFROM}\joy3.map"
			SectionEnd
		SubSectionEnd
		Section "DiskWriter" DESC_dskw
			SectionIn 1 2
			File "${INSTALLFROM}\DiskWriter.dll"
			RegDLL "$INSTDIR\DiskWriter.dll"
		SectionEnd
	SubSectionEnd

	## vdmsound launchpad files
	Section "Launchpad" DESC_lpad
		SectionIn 1
		File "${INSTALLFROM}\Launchpad.dll"
		RegDLL "$INSTDIR\Launchpad.dll"
	SectionEnd

	## nolfb files
	SubSection "NOLFB" DESC_nlfb
		Section "Program" DESC_nlfp
			SectionIn 1
			File "${INSTALLFROM}\NOLFB.COM"
		SectionEnd
		Section "Source" DESC_nlfs
			SetOutPath "$INSTDIR\Source"
			File "${INSTALLFROM}\NOLFB.ASM"
		SectionEnd
	SubSectionEnd
 #	Section "SAPUCDEX" DESC_sapu ## needs OK from SaPu
 #		SectionIn 1
 #	SectionEnd

	## this section must be installed
	Section ""
		SetOutPath "$INSTDIR"
		!ifdef ALLUSERS
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName" "${MUI_PRODUCT}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayVersion" "${MUI_VERSION}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "Comments" "${MUI_DESCRIPTION}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "Publisher" "${MUI_AUTHOR}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "Contact" "${MUI_CONTACT}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "URLInfoAbout" "${MUI_INFO_URL}"
			WriteRegExpandStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "HelpLink" "${MUI_HELP_URL}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "URLUpdateInfo" "${MUI_UPDATE_URL}"
			WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString" "$INSTDIR\${MUI_UNINSTALLER_FILENAME}"

			WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "VDMSPath" "$INSTDIR"
		!else
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName" "${MUI_PRODUCT}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayVersion" "${MUI_VERSION}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "Comments" "${MUI_DESCRIPTION}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "Publisher" "${MUI_AUTHOR}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "Contact" "${MUI_CONTACT}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "URLInfoAbout" "${MUI_INFO_URL}"
			WriteRegExpandStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "HelpLink" "${MUI_HELP_URL}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "URLUpdateInfo" "${MUI_UPDATE_URL}"
			WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString" "$INSTDIR\${MUI_UNINSTALLER_FILENAME}"

			WriteRegExpandStr HKCU "Environment" "VDMSPath" "$INSTDIR"
		!endif

		IfErrors errorShit else
			errorShit:
				MessageBox MB_OK "$\r$\n$0 $\r$\n$1 $\r$\n$2 $\r$\n$3 $\r$\n$4 $\r$\n$5 $\r$\n$6 $\r$\n$7 $\r$\n$8 $\r$\n$9"
				Goto "else"
			else:

		SendMessage 65535 26 0 "STR:Environment" /TIMEOUT=2500

		WriteUninstaller "${MUI_UNINSTALLER_FILENAME}"
	SectionEnd

	## end of section

### Uninstaller

	## uninstall ev-ry-thing
	Section "Uninstall"
		ClearErrors
		Delete "$INSTDIR\DOSDRV.EXE"
		UnRegDLL "$INSTDIR\DMAController.dll"
		Delete "$INSTDIR\DMAController.dll"
		UnRegDLL "$INSTDIR\DSoundDevice.dll"
		Delete "$INSTDIR\DSoundDevice.dll"
		UnRegDLL "$INSTDIR\VDDLoader.dll"
		Delete "$INSTDIR\VDDLoader.dll"
		UnRegDLL "$INSTDIR\VDMConfig.dll"
		Delete "$INSTDIR\VDMConfig.dll"
		UnRegDLL "$INSTDIR\WaveDevice.dll"
		Delete "$INSTDIR\WaveDevice.dll"

		Delete "$INSTDIR\readme.rtf"
		Delete "$INSTDIR\CHANGES.txt"
		Delete "$INSTDIR\license.txt"

		Delete "$INSTDIR\VDMSound.ico"

		Delete "$INSTDIR\VDMConfig.cnt"
		Delete "$INSTDIR\VDMConfig.hlp"
		Delete "$INSTDIR\VDMConfig.GID"

		UnRegDLL "$INSTDIR\EmuSBCompat.dll"
		Delete "$INSTDIR\EmuSBCompat.dll"

		UnRegDLL "$INSTDIR\EmuAdlib.dll"
		Delete "$INSTDIR\EmuAdlib.dll"

		UnRegDLL "$INSTDIR\EmuMPU401.dll"
		Delete "$INSTDIR\EmuMPU401.dll"
		UnRegDLL "$INSTDIR\MIDIDevice.dll"
		Delete "$INSTDIR\MIDIDevice.dll"
		UnRegDLL "$INSTDIR\MIDIIncidator.dll"
		Delete "$INSTDIR\MIDIIndicator.dll"
		UnRegDLL "$INSTDIR\MIDIToolkit.dll"
		Delete "$INSTDIR\MIDIToolkit.dll"
		Delete "$INSTDIR\identity.map"
			Delete "$INSTDIR\mt2gm.map"
			Delete "$INSTDIR\gm2mt.map"

		UnRegDLL "$INSTDIR\EmuPPDAC.dll"
		Delete "$INSTDIR\EmuPPDAC.dll"

		UnRegDLL "$INSTDIR\EmuJoystick.dll"
		Delete "$INSTDIR\EmuJoystick.dll"
			Delete "$INSTDIR\joy1.map"
			Delete "$INSTDIR\joy2.map"
			Delete "$INSTDIR\joy3.map"

		UnRegDLL "$INSTDIR\DiskWriter.dll"
		Delete "$INSTDIR\DiskWriter.dll"

		## launchpad
		UnRegDLL "$INSTDIR\Launchpad.dll"
		Delete "$INSTDIR\Launchpad.dll"

		## nolfb
		Delete "$INSTDIR\NOLFB.COM"
		Delete "$INSTDIR\Source\NOLFB.ASM"

		!ifdef REMFILES
			Delete "$INSTDIR\VDMS.INI"
			Delete "$INSTDIR\AUTOEXEC.VDMS"
			Delete "$INSTDIR\CONFIG.VDMS"
			RMDir "$INSTDIR"
		!endif

		Delete "$INSTDIR\${MUI_UNINSTALLER_FILENAME}"

		IfErrors rebootMaybeRequired
			rebootMaybeRequired:
				MessageBox MB_OK "You may need to reboot your computer to remove files that could not be deleted during uninstallation. $\r$\n$0 $\r$\n$1 $\r$\n$2 $\r$\n$3 $\r$\n$4 $\r$\n$5 $\r$\n$6 $\r$\n$7 $\r$\n$8 $\r$\n$9"

		ReadRegStr $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName"
		IfErrors installedInHKCU installedInHKLM
			installedInHKLM:
				DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"
				DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "VDMSPath"
				Goto "continue"
			installedInHKCU:
				DeleteRegKey HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"
				DeleteRegValue HKCU "Environment" "VDMSPath"
			continue:

		DeleteRegValue HKCU "Software\${MUI_PRODUCT}" "Installer Language"
		SendMessage 65535 26 0 "STR:Environment" /TIMEOUT=2500

		## end of section
	SectionEnd

### Section Descriptions

	!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
		!insertmacro MUI_DESCRIPTION_TEXT ${DESC_vdms} "The VDMSound program itself."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_core} "The VDMSound engine."
	   !insertmacro MUI_DESCRIPTION_TEXT ${DESC_help} "VDMS.INI configuration guide."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_sndb} "SoundBlaster Compatible plugin."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_adlb} "AdLib OPL2 and OPL3 plugin."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_m401} "MPU-401 General MIDI Interface."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_mcor} "MPU-401 General MIDI Interface plugins."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_gm32} "MT-32 to General MIDI patch."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_32gm} "General MIDI to MT-32 patch."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_pdac} "Parallel port Digital-to-Analogue Converter plugin (Disney Sound Source)."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_joys} "Gameport Joystick."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_jcor} "Gameport Joystick plugin."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_joy1} "Map file for one joystick with four buttons and four axes."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_joy2} "Map file for two joysticks with two buttons and two axes per joystick."
		  !insertmacro MUI_DESCRIPTION_TEXT ${DESC_joy3} "Map file for one joystick with two buttons, three axes, rudder and discrete POV."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_dskw} "Enables the ability to output sound to disk."
		!insertmacro MUI_DESCRIPTION_TEXT ${DESC_lpad} "Windows GUI for VDMSound."
		!insertmacro MUI_DESCRIPTION_TEXT ${DESC_nlfb} "Disables Linear Framebuffer in DOS VESA games. By Ken Silverman."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_nlfp} "Executable for NOLFB."
		 !insertmacro MUI_DESCRIPTION_TEXT ${DESC_nlfs} "Source code for NOLFB (written in assembly)."
 #		!insertmacro MUI_DESCRIPTION_TEXT ${DESC_sapu} "Restores full MSCDEX functionality (MSCDEXNT replacement). By Sauro Puccini." ## does not exist yet
	!insertmacro MUI_FUNCTIONS_DESCRIPTION_END

### <<EOF