-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
96 lines (76 loc) · 3 KB
/
install.ps1
File metadata and controls
96 lines (76 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<#
.SYNOPSIS
Installs the FFmpeg context menu converter.
.DESCRIPTION
Adds "Convert with FFmpeg" to the right-click context menu for video and audio files.
Must be run as Administrator.
#>
param(
[switch]$Uninstall
)
$ErrorActionPreference = "Stop"
# Get the script directory
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$ConverterScript = Join-Path $ScriptDir "convert-media.ps1"
# File extensions to register
$VideoExtensions = @('.mp4', '.mkv', '.avi', '.mov', '.webm', '.flv', '.wmv', '.m4v')
$AudioExtensions = @('.mp3', '.wav', '.flac', '.aac', '.ogg', '.m4a', '.wma', '.opus')
$AllExtensions = $VideoExtensions + $AudioExtensions
# Registry paths
$MenuName = "ConvertWithFFmpeg"
$MenuLabel = "Convert with FFmpeg"
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Install-ContextMenu {
Write-Host "Installing FFmpeg context menu..." -ForegroundColor Green
# Check if converter script exists
if (-not (Test-Path $ConverterScript)) {
throw "Converter script not found: $ConverterScript"
}
# Build the command
$command = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$ConverterScript`" `"%1`""
foreach ($ext in $AllExtensions) {
$regPath = "HKCU:\Software\Classes\SystemFileAssociations\$ext\shell\$MenuName"
Write-Host " Registering $ext..." -ForegroundColor Cyan
# Create the menu entry
if (-not (Test-Path $regPath)) {
New-Item -Path $regPath -Force | Out-Null
}
Set-ItemProperty -Path $regPath -Name "(Default)" -Value $MenuLabel
Set-ItemProperty -Path $regPath -Name "Icon" -Value "shell32.dll,145"
# Create the command subkey
$commandPath = "$regPath\command"
if (-not (Test-Path $commandPath)) {
New-Item -Path $commandPath -Force | Out-Null
}
Set-ItemProperty -Path $commandPath -Name "(Default)" -Value $command
}
Write-Host ""
Write-Host "Installation complete!" -ForegroundColor Green
Write-Host "Right-click any supported media file to see 'Convert with FFmpeg'" -ForegroundColor Yellow
}
function Uninstall-ContextMenu {
Write-Host "Uninstalling FFmpeg context menu..." -ForegroundColor Yellow
foreach ($ext in $AllExtensions) {
$regPath = "HKCU:\Software\Classes\SystemFileAssociations\$ext\shell\$MenuName"
if (Test-Path $regPath) {
Write-Host " Removing $ext..." -ForegroundColor Cyan
Remove-Item -Path $regPath -Recurse -Force
}
}
Write-Host ""
Write-Host "Uninstallation complete!" -ForegroundColor Green
}
# Main
if ($Uninstall) {
Uninstall-ContextMenu
}
else {
Install-ContextMenu
}
Write-Host ""
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")