
$content = @"
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{58F74CA0-BD0E-4664-A49B-8D10E6F0C131}]
@="VapourSynth"

[HKEY_CLASSES_ROOT\CLSID\{58F74CA0-BD0E-4664-A49B-8D10E6F0C131}\InProcServer32]
@="InstallDir\\vsvfw.dll"
"ThreadingModel"="Apartment"

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

[HKEY_CLASSES_ROOT\.vpy]
@="vpyfile"
"PerceivedType"="video"

[HKEY_CLASSES_ROOT\vpyfile]
@="VapourSynth Python Script"

[HKEY_CLASSES_ROOT\vpyfile\DefaultIcon]
@="InstallDir\\vsvfw.dll,0"

[HKEY_CLASSES_ROOT\AVIFile\Extensions\VPY]
@="{58F74CA0-BD0E-4664-A49B-8D10E6F0C131}"

"@

# save reg file
$dir = $PSScriptRoot + '\..\VapourSynth'
$dir = Convert-Path $dir
$escapedDir = $dir -replace '\\','\\'
$content = $content -replace 'InstallDir',$escapedDir
$path = Join-Path $env:TEMP Install-VapourSynth.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')
}
