# install-host.ps1 # Registers rclonex native-messaging host so Brave can launch it. # # Usage: .\install-host.ps1 -ExtensionId # # Writes manifest to host\com.rcjav.host.json with the correct path + extension ID baked in, # then registers it in HKLM (requires admin - script self-elevates if needed) AND HKCU. # HKLM is required on some Brave installs; HKCU alone is not always honored. param( [Parameter(Mandatory = $true)] [string]$ExtensionId ) $ErrorActionPreference = "Stop" $hostDir = $PSScriptRoot $batPath = Join-Path $hostDir "rcjav-host.bat" if (-not (Test-Path $batPath)) { throw "Host bat not found: $batPath" } $manifestPath = Join-Path $hostDir "com.rcjav.host.json" $template = Join-Path $hostDir "com.rcjav.host.json.template" if (-not (Test-Path $template)) { throw "Template not found: $template" } $content = Get-Content $template -Raw $content = $content.Replace("__HOST_BAT__", ($batPath -replace "\\", "\\")) $content = $content.Replace("__EXTENSION_ID__", $ExtensionId) # UTF-8 WITHOUT BOM - Chrome/Brave rejects manifests with a BOM. [System.IO.File]::WriteAllText($manifestPath, $content, [System.Text.UTF8Encoding]::new($false)) Write-Host "Manifest written: $manifestPath" # Self-elevate for HKLM if not already admin. $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "Not running as admin - relaunching elevated to write HKLM..." Start-Process pwsh -Verb RunAs -ArgumentList @( "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", $PSCommandPath, "-ExtensionId", $ExtensionId ) exit } # Register in HKLM - required on some Brave installs. $keys = @( 'HKLM:\Software\BraveSoftware\Brave-Browser\NativeMessagingHosts\com.rcjav.host', 'HKLM:\Software\Google\Chrome\NativeMessagingHosts\com.rcjav.host', 'HKLM:\Software\WOW6432Node\Google\Chrome\NativeMessagingHosts\com.rcjav.host', 'HKLM:\Software\Chromium\NativeMessagingHosts\com.rcjav.host', # HKCU as belt-and-suspenders for installs that prefer it 'HKCU:\Software\BraveSoftware\Brave-Browser\NativeMessagingHosts\com.rcjav.host', 'HKCU:\Software\Google\Chrome\NativeMessagingHosts\com.rcjav.host', 'HKCU:\Software\Chromium\NativeMessagingHosts\com.rcjav.host' ) foreach ($k in $keys) { try { New-Item -Path $k -Force -ErrorAction Stop | Out-Null Set-Item -Path $k -Value $manifestPath Write-Host " Set: $k" } catch { Write-Host " FAILED: $k ($($_.Exception.Message))" } } Write-Host "" Write-Host "Manifest contents:" Write-Host "-------------------" Write-Host $content Write-Host "-------------------" Write-Host "" Write-Host "Fully restart Brave (kill all brave.exe processes, then reopen) for the registry" Write-Host "entries to be picked up. Then click rclonex toolbar > Ping host." Read-Host "Press Enter to close"