mirror of
https://github.com/ZenDeuo/WinRepair.git
synced 2026-06-22 01:40:59 +01:00
Initial upload of WinRepair in its current working, fully featured state! + Includes Debugging Scripts.
108 lines
4.8 KiB
PowerShell
108 lines
4.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
WinRepair Debug Launcher
|
|
.DESCRIPTION
|
|
Runs WinRepair.ps1 as a CHILD PROCESS with full transcript logging,
|
|
visible console, and crash detection. The debug console stays open
|
|
even if WinRepair crashes or calls exit.
|
|
Debug log is saved to WinRepair_Debug.log in the same directory.
|
|
.NOTES
|
|
Run this via RunRepair_Debug.bat when troubleshooting issues.
|
|
The console window WILL remain open even after a crash.
|
|
#>
|
|
|
|
# ==============================================================================
|
|
# DEBUG SETUP
|
|
# ==============================================================================
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$debugLog = Join-Path $scriptDir "WinRepair_Debug.log"
|
|
$errorLog = Join-Path $scriptDir "WinRepair_Error.log"
|
|
$mainScript = Join-Path $scriptDir "WinRepair.ps1"
|
|
|
|
# Clear previous logs
|
|
"" | Out-File -FilePath $debugLog -Force
|
|
if (Test-Path $errorLog) { Remove-Item $errorLog -Force }
|
|
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
Write-Host "|| WinRepair - DEBUG MODE ||" -ForegroundColor Cyan
|
|
Write-Host "|| Logging to: WinRepair_Debug.log ||" -ForegroundColor Cyan
|
|
Write-Host "|| This window stays open after crashes ||" -ForegroundColor Cyan
|
|
Write-Host "==========================================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Start transcript
|
|
Start-Transcript -Path $debugLog -Append | Out-Null
|
|
|
|
Write-Host "[DEBUG] Script directory: $scriptDir" -ForegroundColor Yellow
|
|
Write-Host "[DEBUG] Main script: $mainScript" -ForegroundColor Yellow
|
|
Write-Host "[DEBUG] PowerShell version: $($PSVersionTable.PSVersion)" -ForegroundColor Yellow
|
|
Write-Host "[DEBUG] OS: $([System.Environment]::OSVersion.VersionString)" -ForegroundColor Yellow
|
|
Write-Host "[DEBUG] Running as Admin: $(([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))" -ForegroundColor Yellow
|
|
Write-Host "[DEBUG] Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# ==============================================================================
|
|
# LAUNCH WINREPAIR AS A CHILD PROCESS
|
|
# This is the key difference: Start-Process creates a SEPARATE process,
|
|
# so even if WinRepair calls "exit 1", only the child dies.
|
|
# This debug console survives no matter what.
|
|
# ==============================================================================
|
|
Write-Host "[DEBUG] Launching WinRepair.ps1 as child process..." -ForegroundColor Green
|
|
Write-Host "[DEBUG] -----------------------------------------------" -ForegroundColor DarkGray
|
|
Write-Host ""
|
|
|
|
$startTime = Get-Date
|
|
|
|
# Set env var so WinRepair.ps1 skips hiding the console window
|
|
$env:WINREPAIR_DEBUG = "1"
|
|
|
|
$childProc = Start-Process -FilePath "powershell.exe" `
|
|
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$mainScript`" -DebugMode" `
|
|
-PassThru -NoNewWindow
|
|
|
|
# Wait for the child process to finish
|
|
$childProc.WaitForExit()
|
|
|
|
$exitCode = $childProc.ExitCode
|
|
$elapsed = (Get-Date) - $startTime
|
|
|
|
Write-Host ""
|
|
Write-Host "[DEBUG] -----------------------------------------------" -ForegroundColor DarkGray
|
|
|
|
if ($exitCode -eq 0) {
|
|
Write-Host "[DEBUG] WinRepair exited normally (code 0)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "[DEBUG] WinRepair CRASHED with exit code: $exitCode" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host "[DEBUG] Duration: $($elapsed.ToString('mm\:ss'))" -ForegroundColor Yellow
|
|
|
|
# Check for error log from WinRepair's trap handler
|
|
if (Test-Path $errorLog) {
|
|
$errorContent = Get-Content $errorLog -Raw
|
|
if ($errorContent -and $errorContent.Trim() -ne "") {
|
|
Write-Host ""
|
|
Write-Host "==========================================================" -ForegroundColor Red
|
|
Write-Host " CRASH DETAILS (from WinRepair_Error.log) " -ForegroundColor Red
|
|
Write-Host "==========================================================" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host $errorContent -ForegroundColor Yellow
|
|
Write-Host ""
|
|
Write-Host "==========================================================" -ForegroundColor Red
|
|
}
|
|
} else {
|
|
if ($exitCode -ne 0) {
|
|
Write-Host ""
|
|
Write-Host "[DEBUG] No WinRepair_Error.log found. The crash may have" -ForegroundColor Red
|
|
Write-Host "[DEBUG] bypassed the error handler (e.g. .NET exception)." -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "[DEBUG] Full debug log saved to: $debugLog" -ForegroundColor Yellow
|
|
|
|
Stop-Transcript -ErrorAction SilentlyContinue | Out-Null
|
|
|
|
Write-Host ""
|
|
Write-Host "Press any key to close this window..." -ForegroundColor Cyan
|
|
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|