#region - AutoGK install script - (Nullsoft)
#include <Common_Functions.au3>
Opt('TrayIconDebug', 1)
Break(False)

; Installer.
$executable = 'AutoGK 2.40.exe'
; Default group folder in startmenu.
$group = 'AutoGK'
; Installation folder in Program Files.
$directory = 'AutoGK'
; Choose support programs to install.
$vobsub = 0
$avisynth = 1
$xvid = 1

; Run the installer.
$pid = _Nullsoft()
; Install VobSub.
If WinWait('Installer Language', 'Please select a language', 60) Then
    If $vobsub Then
        ControlClick('Installer Language', 'Please select a language', 'Button1')
        WinWait('VobSub 2.23 Setup', 'Welcome to the VobSub')
        ControlClick('VobSub 2.23 Setup', 'Welcome to the VobSub', 'Button1')
        WinWait('VobSub 2.23 Setup', 'Choose Components')
        ControlClick('VobSub 2.23 Setup', 'Choose Components', 'Button1')
        WinWait('VobSub 2.23 Setup', 'Choose Install Location')
        ControlClick('VobSub 2.23 Setup', 'Choose Install Location', 'Button1')
        WinWait('VobSub 2.23 Setup', 'Installation Complete')
        ControlClick('VobSub 2.23 Setup', 'Installation Complete', 'Button1')
    EndIf
    ProcessWaitClose('VobSub_2.23.exe', 2)
    ProcessClose('VobSub_2.23.exe')
    If WinExists('Installer Language') Then _WinClose('Installer Language')
    FileDelete(@TempDir & '\VobSub_2.23.exe')
EndIf
; Install AviSynth.
If WinWait('AviSynth 2.5.6', '', 20) Then
    If $avisynth Then
        WinSetState('AviSynth 2.5.6', '', @SW_HIDE)
        RunWait('"' & @TempDir & '\AviSynth_256.exe" /S')
    EndIf
    ProcessClose('AviSynth_256.exe')
    If WinExists('AviSynth 2.5.6') Then _WinClose('AviSynth 2.5.6')
    FileDelete(@TempDir & '\AviSynth_256.exe')
EndIf
; Install XviD.
If WinWait('XviD MPEG4 Video Codec Setup', '', 20) Then
    If $xvid Then
        WinSetState('XviD MPEG4 Video Codec Setup', '', @SW_HIDE)
        RunWait('"' & @TempDir & '\XviD.1.2.head.exe" /S')
    EndIf
    ProcessClose('XviD.1.2.head.exe')
    If WinExists('XviD MPEG4 Video Codec Setup') Then _WinClose('XviD MPEG4 Video Codec Setup')
    FileDelete(@TempDir & '\XviD.1.2.head.exe')
EndIf
ProcessWaitClose($pid)

; Remove AutoGK shortcuts.
If _Programs('AutoGK.lnk') Then
    FileMove($group & '\AutoGK.lnk', 'Audio-Video\', 9)
    DirRemove($group, 1)
EndIf

; Remove VobSub shortcuts.
If $vobsub Then
    $group = 'VobSub'
    If _MainShortcut('VobSub Configure.lnk') Then
        DirRemove($group, 1)
    EndIf
EndIf

; Remove AviSynth shortcuts.
If $avisynth Then
    $group = 'AviSynth 2.5'
    If _Programs('Uninstall AviSynth.lnk') Then
        DirRemove($group, 1)
    EndIf
EndIf

; Remove XviD shortcuts.
If $xvid Then
    $group = 'XviD'
    If _Programs('Configure Decoder.lnk') Then
        DirRemove($group, 1)
    EndIf
EndIf

RegWrite('HKCU\Software\Freeware\VirtualDubMod', 'VirtualDub', 'Reg_Dword', '0x00000001')
RegWrite('HKCU\Software\Freeware\VirtualDubMod', 'SeenWelcome', 'Reg_Dword', '0x00000001')

Exit
#endregion