Files
winit-helper/lib/invoke-regimport.ps1

35 lines
1.1 KiB
PowerShell

param(
[Parameter(Mandatory=$true)]
[string]$Path
)
try {
# 1. Expand variables in the path.
$ResolvedPath = $ExecutionContext.InvokeCommand.ExpandString($Path)
# 2. Resolve relative paths from the project root.
if (-not (Test-Path $ResolvedPath) -and (Test-Path "$PWD\$ResolvedPath")) {
$ResolvedPath = Join-Path $PWD $ResolvedPath
}
# 3. Make sure the registry file exists.
if (-not (Test-Path $ResolvedPath)) {
Write-Warning "`n[RegImport] [Skip] Cannot find: $ResolvedPath"
return
}
Write-Host "`n[RegImport] Importing: $(Split-Path $ResolvedPath -Leaf)" -ForegroundColor Gray
# 4. Import with reg.exe and capture the exit code.
$proc = Start-Process -FilePath "reg.exe" -ArgumentList "import", "`"$ResolvedPath`"" -Wait -PassThru -NoNewWindow
if ($proc.ExitCode -eq 0) {
Write-Host "`n[RegImport] Successfully imported." -ForegroundColor Green
} else {
Write-Error "`n[RegImport] Failed to import: $($proc.ExitCode)"
}
} catch {
Write-Error "`n[RegImport] Failed to start process: $_"
}