# Convert all batch files to DOS format (CRLF) automatically
Write-Host "=== Converting Batch Files to DOS Format ===" -ForegroundColor Cyan
Write-Host ""

# Find all .bat files (excluding git/node_modules)
$batFiles = Get-ChildItem -Recurse -Filter "*.bat" | Where-Object {
    $_.FullName -notlike "*\.git\*" -and
    $_.FullName -notlike "*\node_modules\*"
}

Write-Host "Converting $($batFiles.Count) batch files..." -ForegroundColor Yellow
Write-Host ""

$converted = 0
$errors = 0

foreach ($file in $batFiles) {
    try {
        # Read file content
        $content = Get-Content $file.FullName -Raw

        # Normalize to DOS line endings (CRLF)
        $dosContent = $content -replace "`r?`n", "`r`n"

        # Write back with ASCII encoding (DOS compatible)
        [System.IO.File]::WriteAllText($file.FullName, $dosContent, [System.Text.Encoding]::ASCII)

        Write-Host "[OK] $($file.Name)" -ForegroundColor Green
        $converted++
    } catch {
        Write-Host "[ERROR] $($file.Name): $($_.Exception.Message)" -ForegroundColor Red
        $errors++
    }
}

Write-Host ""
Write-Host "=== Conversion Complete ===" -ForegroundColor Green
Write-Host "Converted: $converted files" -ForegroundColor Green
if ($errors -gt 0) {
    Write-Host "Errors: $errors files" -ForegroundColor Red
}
