
$content = @"
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{E6D6B700-124D-11D4-86F3-DB80AFD98778}]
@="AviSynth"

[HKEY_CLASSES_ROOT\CLSID\{E6D6B700-124D-11D4-86F3-DB80AFD98778}\InProcServer32]
@="InstallDir\\AviSynth.dll"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\Media Type\Extensions\.avs]
@=""
"Source Filter"="{D3588AB0-0781-11CE-B03A-0020AF0BA770}"

[HKEY_CLASSES_ROOT\.avs]
@="avsfile"

[HKEY_CLASSES_ROOT\avsfile]
@="AviSynth Script"

[HKEY_CLASSES_ROOT\avsfile\DefaultIcon]
@="InstallDir\\AviSynth.dll,0"

[HKEY_CLASSES_ROOT\.avsi]
@="avs_auto_file"

[HKEY_CLASSES_ROOT\avs_auto_file]
@="AviSynth Autoload Script"

[HKEY_CLASSES_ROOT\avs_auto_file\DefaultIcon]
@="InstallDir\\AviSynth.dll,0"

[HKEY_CLASSES_ROOT\AVIFile\Extensions\AVS]
@="{E6D6B700-124D-11D4-86F3-DB80AFD98778}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth]
@="InstallDir"
"PluginDir+"="InstallDir\\plugins"
"PluginDir2_5"="InstallDir\\plugins2_5"

[HKEY_CURRENT_USER\Software\AviSynth]
@="InstallDir"
"PluginDir+"="InstallDir\\plugins"
"PluginDir2_5"="InstallDir\\plugins2_5"

"@

# save reg file
$dir = $PSScriptRoot + '\..\AviSynth'
$dir = Convert-Path $dir
$escapedDir = $dir -replace '\\','\\'
$content = $content -replace 'InstallDir',$escapedDir
$path = Join-Path $env:TEMP Install-AviSynth.reg
$content > $path

# run reg file
Start-Process $path -Wait
Remove-Item $path

# add to PATH
$path = [Environment]::GetEnvironmentVariable('Path', 'User')

if (-not $path.Contains($dir)) {
    $path = $path + ';' + $dir
    [Environment]::SetEnvironmentVariable('Path', $path, 'User')
}
