#NoTrayIcon

#region Global Declarations.
Global $Component[18][18]; Component array.
#endregion

#region User configuration.
; -----------> User configuration starts here. <-----------

; Provide your license key or leave blank for demo version.
$LicenseKey = ''

; Choose Nero 7 components to include (1) or exclude (0).
$Component[1][0] = 0; NeroStartSmart
$Component[2][0] = 1; NeroBurningRom
$Component[3][0] = 0; NeroHome
$Component[4][0] = 0; NeroVision
$Component[5][0] = 0; NeroShowTime
$Component[6][0] = 0; NeroRecode
$Component[7][0] = 0; NeroMediaHome
$Component[8][0] = 0; NeroBackItUp
$Component[9][0] = 0; NeroCoverDesigner
$Component[10][0] = 0; NeroPhotoSnap
$Component[11][0] = 0; NeroWaveEditor
$Component[12][0] = 0; NeroSoundTrax
$Component[13][0] = 0; NeroImageDrive
$Component[14][0] = 0; NeroCDDVDSpeed
$Component[15][0] = 0; NeroDriveSpeed
$Component[16][0] = 0; NeroBurnRights
$Component[17][0] = 0; NeroInfoTool

; Enable prompt to save unsaved project/compilation when exiting?
$ProjectSavingState = 0
; Enable DVD overburning?
$EnableDVDOverSize = 1
; Enable show real recorder write speed while burning?
$ShowSingleRecorderSpeed = 1
; Disable NeroFilterCheck startup process (nerocheck.exe)?
$DisableNeroFilterCheck = 1
; Enable Short Lead-Out?
$ShortLeadOut = 1
; Prevent the CD/DVD from ejecting after burning is complete?
$EjectTheCDLater = 1

; -----------> User configuration ends here. <-----------
#endregion

#region Installation and configuration process.
; Look for Nero setup exectuable.
$Executable = _GetExeName('Nero-7.*_no_yt.exe')

; Silent switch and registration prefix.
If StringLen($LicenseKey) <> 34 Then
	$Switches = ' /qn /norestart NERO_SCOUT=FALSE'
Else
	$Switches = ' /qn /norestart SERIALNUM_USERVAL="' & $LicenseKey & '" NERO_SCOUT=FALSE'
EndIf

; Switch prefixes.
$Component[0][1] = 'CB035464E'; NeroStartSmart
$Component[0][2] = 'CBCAFF604'; NeroBurningRom
$Component[0][3] = 'C2FF8B816'; NeroHome
$Component[0][4] = 'C57D52359'; NeroVision
$Component[0][5] = 'CD773A6E2'; NeroShowTime
$Component[0][6] = 'C6035F00C'; NeroRecode
$Component[0][7] = 'C53BEFA20'; NeroMediaHome
$Component[0][8] = 'CCB9D5429'; NeroBackItUp
$Component[0][9] = 'C7CE8D626'; NeroCoverDesigner
$Component[0][10] = 'CED1EAF52'; NeroPhotoSnap
$Component[0][11] = 'CFA3A3F7B'; NeroWaveEditor
$Component[0][12] = 'C716FE146'; NeroSoundTrax
$Component[0][13] = 'CE38B9E06'; NeroImageDrive
$Component[0][14] = 'C82602EE0'; NeroCDDVDSpeed
$Component[0][15] = 'C7DFFCC12'; NeroDriveSpeed
$Component[0][16] = 'C72CC518F'; NeroBurnRights
$Component[0][17] = 'CE72D824A'; NeroInfoTool

; Loop through components to add exclusions.
For $i = 1 To UBound($Component) - 1
	If Not $Component[$i][0] Then
		$Switches = $Switches & ' ' & $Component[0][$i] & '=0'
	EndIf
Next

; Run Nero setup exectuable.
$PID = Run(@ScriptDir & '\' & $Executable & $Switches)

; Hide CAB extraction window, and wait for setup to complete.
Do
	Select
		Case WinExists('Nero 7', 'Extraction progress')
			WinSetState('Nero 7', 'Extraction progress', @SW_HIDE)
			WinWaitClose('Nero 7', 'Extraction progress')

		Case WinExists('WaitForDialog', 'Nero ProductSetup')
			WinSetState('WaitForDialog', 'Nero ProductSetup', @SW_HIDE)
			WinWaitClose('WaitForDialog', 'Nero ProductSetup')

		Case Else
			Sleep(500)
	EndSelect
Until Not ProcessExists($PID) And Not ProcessExists('SetupX.exe')

; Program configuration section.
$RunRegPath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
$NeroRegPath = 'HKCU\SOFTWARE\Ahead\Nero - Burning Rom'

If $DisableNeroFilterCheck = 1 Then RegDelete('HKLM\' & $RunRegPath, 'NeroFilterCheck')
If $Component[3][0] = 0 Then RegDelete('HKCU\' & $RunRegPath, 'BgMonitor_{79662E04-7C6C-4d9f-84C7-88D8A56B10AA}')
If $ProjectSavingState = 0 Then RegWrite($NeroRegPath & '\General', 'ProjectSavingState', 'REG_DWORD', '0')
If $EnableDVDOverSize = 1 Then RegWrite($NeroRegPath & '\General', 'EnableDVDOverSize', 'REG_DWORD', '1')
If $ShowSingleRecorderSpeed = 1 Then RegWrite($NeroRegPath & '\Recorder', 'ShowSingleRecorderSpeed', 'REG_DWORD', '1')
If $EjectTheCDLater = 1 Then RegWrite($NeroRegPath & '\General', 'EjectTheCDLater', 'REG_DWORD', '1')
If $ShortLeadOut = 1 Then RegWrite($NeroRegPath & '\Recorder', 'ShortLeadOut', 'REG_DWORD', '375')
RegWrite($NeroRegPath & '\Settings', 'WorkingDir', 'REG_SZ', @TempDir)

; Unregister Nero Scout.
RunWait('regsvr32 /u /s "' & @CommonFilesDir & '\Ahead\Lib\MediaLibraryNSE.dll"')

; Remove invalid Nero Scout shortcut and rename 'Nero 7 Demo' add/remove title.
If FileChangeDir(@ProgramsCommonDir) Then
	$search = FileFindFirstFile('Nero 7*')
	If $search <> - 1 Then
		$NeroVersion = FileFindNextFile($search)
		If Not @error Then
			If FileExists($NeroVersion & '\Nero Scout.lnk') Then
				FileDelete($NeroVersion & '\Nero Scout.lnk')
			EndIf
			For $i = 1 To 1000
				$key = RegEnumKey('HKCU\SOFTWARE\Microsoft\Installer\Products\', $i)
				If @error Then ExitLoop
				$value = RegRead('HKCU\SOFTWARE\Microsoft\Installer\Products\' & $key, 'ProductName')
				If @error Then ContinueLoop
				If StringInStr($value, 'Nero') Then
					RegWrite('HKCU\SOFTWARE\Microsoft\Installer\Products\' & $key, 'ProductName', 'REG_SZ', $NeroVersion)
					ExitLoop
				EndIf
			Next
		EndIf
		FileClose($search)
	EndIf
EndIf

#endregion

Exit

Func _GetExeName($exename)
	Local $search, $filename
	If FileChangeDir(@ScriptDir) Then
		$search = FileFindFirstFile($exename)
		If $search <> - 1 Then
			$filename = FileFindNextFile($search)
			If Not @error Then
				FileClose($search)
				Return $filename
			EndIf
			FileClose($search)
		EndIf
	EndIf
	MsgBox(0x40010, @ScriptName, 'Nero executable not found', 10)
	Exit 1
EndFunc