@echo off
setlocal EnableExtensions
title Helper Diagnostics

for /f "usebackq delims=" %%I in (`powershell.exe -NoProfile -Command "[Environment]::GetFolderPath('Desktop')"`) do set "DESKTOP_DIR=%%I"
if not defined DESKTOP_DIR set "DESKTOP_DIR=%USERPROFILE%\Desktop"
set "REPORT=%DESKTOP_DIR%\Helper-Diagnostics.txt"

powershell.exe -NoProfile -Command "$report=$env:REPORT; $loader='C:\Program Files\Helper\Helper-loader.exe'; $data=Join-Path $env:LOCALAPPDATA 'Helper'; $os=Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue; $lines=@('Helper diagnostics',('Generated: '+(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')),'',('Windows: '+$(if($os){$os.Caption}else{[Environment]::OSVersion.VersionString})),('Version: '+$(if($os){$os.Version}else{[Environment]::OSVersion.Version.ToString()})),('Build: '+$(if($os){$os.BuildNumber}else{'unknown'})),('Architecture: '+$env:PROCESSOR_ARCHITECTURE),('LocalAppData: '+$env:LOCALAPPDATA),'',('Installed loader: '+$loader)); if(Test-Path -LiteralPath $loader -PathType Leaf){$file=Get-Item -LiteralPath $loader; $lines+='Loader exists: yes'; $lines+=('File version: '+$file.VersionInfo.FileVersion); $lines+=('SHA-256: '+(Get-FileHash -LiteralPath $loader -Algorithm SHA256).Hash)}else{$lines+='Loader exists: no'}; $lines+=''; if(Test-Path -LiteralPath $data -PathType Container){$lines+='Helper data directory: present'; $files=Get-ChildItem -LiteralPath $data -File -ErrorAction SilentlyContinue; if($files){foreach($item in $files){$lines+=('File: '+$item.Name)}}else{$lines+='Files: none'}}else{$lines+='Helper data directory: absent'}; $lines+=''; $lines+='Running loader process:'; $processes=Get-Process -Name 'Helper-loader' -ErrorAction SilentlyContinue; if($processes){foreach($process in $processes){$lines+=('Status: running; PID: '+$process.Id)}}else{$lines+='Status: not running'}; Set-Content -LiteralPath $report -Value $lines -Encoding UTF8"

if errorlevel 1 (
  echo ERROR: Could not create the diagnostic report.
  pause
  exit /b 1
)

echo Diagnostic report created:
echo %REPORT%
echo.
echo The report contains no account credentials.
if /I "%~1"=="/quiet" exit /b 0
start "" notepad.exe "%REPORT%"
pause
