# Check line endings in BAT files

Write-Host "[INFO] Checking line endings..."
Write-Host ""

# Check original
$Original = Get-Content "DEPLOY.BAT" -Raw
$HasCRLF_Original = $Original -match "`r`n"
$HasLF_Original = $Original -match "[^`r]`n"

Write-Host "DEPLOY.BAT (Original):"
if ($HasCRLF_Original) {
    Write-Host "  [OK] Contains CRLF (DOS-compatible)"
} elseif ($HasLF_Original) {
    Write-Host "  [WARNING] Contains LF only (Unix format)"
} else {
    Write-Host "  [UNKNOWN] No line breaks detected"
}

Write-Host ""

# Check NAS copy
if (Test-Path "DEPLOY_FROM_NAS.BAT") {
    $FromNAS = Get-Content "DEPLOY_FROM_NAS.BAT" -Raw
    $HasCRLF_NAS = $FromNAS -match "`r`n"
    $HasLF_NAS = $FromNAS -match "[^`r]`n"

    Write-Host "DEPLOY_FROM_NAS.BAT (From NAS):"
    if ($HasCRLF_NAS) {
        Write-Host "  [OK] Contains CRLF (DOS-compatible)"
    } elseif ($HasLF_NAS) {
        Write-Host "  [ERROR] Contains LF only (Unix format - DOS won't work!)"
    } else {
        Write-Host "  [UNKNOWN] No line breaks detected"
    }

    # Compare file sizes
    $OrigSize = (Get-Item "DEPLOY.BAT").Length
    $NASSize = (Get-Item "DEPLOY_FROM_NAS.BAT").Length

    Write-Host ""
    Write-Host "File Sizes:"
    Write-Host "  Original: $OrigSize bytes"
    Write-Host "  From NAS: $NASSize bytes"

    if ($OrigSize -ne $NASSize) {
        Write-Host "  [WARNING] Size mismatch - line endings may have been converted"
    } else {
        Write-Host "  [OK] Sizes match"
    }
} else {
    Write-Host "[ERROR] DEPLOY_FROM_NAS.BAT not found"
}
