Allow sending files with control bytes
This commit is contained in:
@@ -681,7 +681,7 @@ Public Class Form1
|
||||
Dim fileBytes = Await File.ReadAllBytesAsync(txtFileInvio.Text, token)
|
||||
fileBytes = RemoveUtf8BomIfPresent(fileBytes)
|
||||
LogFirstBytes(fileBytes)
|
||||
ValidateCncTextBytes(fileBytes)
|
||||
LogNonStandardCncBytes(fileBytes)
|
||||
Dim blockPaced = chkInvioBlocchi.Checked
|
||||
Dim terminator = If(blockPaced, Encoding.ASCII.GetBytes("%" & vbCrLf), GetTerminatorBytes())
|
||||
|
||||
@@ -1036,15 +1036,27 @@ Public Class Form1
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub ValidateCncTextBytes(data As Byte())
|
||||
Private Sub LogNonStandardCncBytes(data As Byte())
|
||||
Dim firstInvalidPosition As Integer = -1
|
||||
Dim firstInvalidValue As Byte = 0
|
||||
Dim invalidCount As Integer
|
||||
|
||||
For i = 0 To data.Length - 1
|
||||
Dim value = data(i)
|
||||
Dim isAllowedControl = value = &H9 OrElse value = &HA OrElse value = &HD
|
||||
Dim isPrintableAscii = value >= &H20 AndAlso value <= &H7E
|
||||
If Not isAllowedControl AndAlso Not isPrintableAscii Then
|
||||
Throw New InvalidDataException($"Il file non sembra testo CNC ASCII/7 bit: byte non valido 0x{value:X2} alla posizione {i}.")
|
||||
invalidCount += 1
|
||||
If firstInvalidPosition < 0 Then
|
||||
firstInvalidPosition = i
|
||||
firstInvalidValue = value
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
If invalidCount > 0 Then
|
||||
Log($"Avviso: trovati {invalidCount} byte di controllo/non ASCII. Primo valore 0x{firstInvalidValue:X2} alla posizione {firstInvalidPosition}. Invio comunque.")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SetBusy(isBusy As Boolean)
|
||||
|
||||
Reference in New Issue
Block a user