#Requires -Version 5.1
<#
.SYNOPSIS
  Remove CCS PDF Editor file associations from HKCU.
#>
$ErrorActionPreference = "Continue"

$keys = @(
    "HKCU:\Software\Classes\CCS.PdfEditor.ccspdf",
    "HKCU:\Software\Classes\CCS.PdfEditor.pdf",
    "HKCU:\Software\Classes\Applications\CcsPdfEditor.exe"
)

foreach ($k in $keys) {
    if (Test-Path $k) {
        Remove-Item -LiteralPath $k -Recurse -Force
        Write-Host "Removed $k"
    }
}

# Clear .ccspdf default if it pointed at us
$ccspdf = "HKCU:\Software\Classes\.ccspdf"
if (Test-Path $ccspdf) {
    $def = (Get-ItemProperty -Path $ccspdf -ErrorAction SilentlyContinue)."(default)"
    if ($def -eq "CCS.PdfEditor.ccspdf") {
        Remove-ItemProperty -Path $ccspdf -Name "(default)" -ErrorAction SilentlyContinue
        Write-Host "Cleared .ccspdf default ProgId"
    }
    $ow = Join-Path $ccspdf "OpenWithProgids"
    if (Test-Path $ow) {
        Remove-ItemProperty -Path $ow -Name "CCS.PdfEditor.ccspdf" -ErrorAction SilentlyContinue
    }
}

$pdfOw = "HKCU:\Software\Classes\.pdf\OpenWithProgids"
if (Test-Path $pdfOw) {
    Remove-ItemProperty -Path $pdfOw -Name "CCS.PdfEditor.pdf" -ErrorAction SilentlyContinue
    Write-Host "Removed .pdf OpenWithProgids entry"
}

try {
    Add-Type -Namespace Win32 -Name Native2 -MemberDefinition @'
[System.Runtime.InteropServices.DllImport("shell32.dll")]
public static extern void SHChangeNotify(int wEventId, uint uFlags, System.IntPtr dwItem1, System.IntPtr dwItem2);
'@ -ErrorAction SilentlyContinue
    [Win32.Native2]::SHChangeNotify(0x08000000, 0, [IntPtr]::Zero, [IntPtr]::Zero)
} catch { }

Write-Host "Unregister complete." -ForegroundColor Green
