Files
KhOS/fix-crlf.ps1
T

40 lines
1.3 KiB
PowerShell

$extensions = @("*.sh", "*.conf", "*.db", "*.c", "*.h", "wpkg", "inittab", "pomoc", "help", "start-hyprland", "start-plasma", "autologin-plasma", "khos-installer", "khos-installer-gui", "setup", "install-os", "rcS", "rcK", "network", "dropbear", "WPKGBUILD", "sudoers", "passwd", "shadow", "group", "mdev.conf", "profile", ".profile", "*.desktop", "*.py")
Get-ChildItem -Recurse -File | Where-Object {
$name = $_.Name
$ext = $_.Extension
$match = $false
foreach ($pat in $extensions) {
if ($name -like $pat -or $ext -like $pat) {
$match = $true
break
}
}
$match
} | ForEach-Object {
$path = $_.FullName
$bytes = [System.IO.File]::ReadAllBytes($path)
$hasCr = $false
for ($i = 0; $i -lt $bytes.Length; $i++) {
if ($bytes[$i] -eq 13) {
$hasCr = $true
break
}
}
if ($hasCr) {
$clean = New-Object byte[] ($bytes.Length)
$pos = 0
for ($i = 0; $i -lt $bytes.Length; $i++) {
if ($bytes[$i] -ne 13) {
$clean[$pos] = $bytes[$i]
$pos++
}
}
$final = New-Object byte[] $pos
[System.Array]::Copy($clean, 0, $final, 0, $pos)
[System.IO.File]::WriteAllBytes($path, $final)
Write-Host "Fixed LF: $($_.FullName)" -ForegroundColor Cyan
}
}