-
Notifications
You must be signed in to change notification settings - Fork 5
/
BinaryFileWriterGUI.vb
72 lines (60 loc) · 2.34 KB
/
BinaryFileWriterGUI.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'Copyright (c) 2018-2020 Analog Devices, Inc. All Rights Reserved.
'This software is proprietary to Analog Devices, Inc. and its licensors.
'
'File: AppBrowseGUI.vb
'Author: Alex Nolan ([email protected])
'Description: Allows for writing binary data patterns to a file. Might not fit great in here, but I use it, and I didn't want to make an entire tool for it.
Public Class BinaryFileWriterGUI
Inherits FormBase
Private Sub btn_GenFile_Click(sender As Object, e As EventArgs) Handles btn_GenFile.Click
Dim bytes As UInteger
Dim inputData As New List(Of Byte)
Dim writeData As New List(Of Byte)
Dim byteStr As String
Dim index As Integer
Dim saveBrowser As SaveFileDialog
Try
bytes = Convert.ToUInt32(numBytes.Text)
Catch ex As Exception
MsgBox("ERROR: Invalid number of bytes. " + ex.Message())
Exit Sub
End Try
'build input data
If (fillPattern.Text.Length Mod 2 <> 0) Or (fillPattern.Text.Length = 0) Then
MsgBox("ERROR: Invalid fill data. Must be even bytes (multiple of two hex chars)")
Exit Sub
End If
Try
For i As Integer = 0 To fillPattern.Text.Length() - 1 Step 2
byteStr = fillPattern.Text.Substring(i, 2)
inputData.Add(Convert.ToByte(byteStr, 16))
Next
Catch ex As Exception
MsgBox("ERROR: Invalid fill data. " + ex.Message)
Exit Sub
End Try
'build output data array
index = 0
While writeData.Count < bytes
writeData.Add(inputData(index))
index += 1
index = index Mod inputData.Count
End While
'get file location
saveBrowser = New SaveFileDialog()
If saveBrowser.ShowDialog <> DialogResult.OK Then
Exit Sub
End If
Try
My.Computer.FileSystem.WriteAllBytes(saveBrowser.FileName, writeData.ToArray(), False)
Catch ex As Exception
MsgBox("ERROR while writing file. " + ex.Message())
End Try
End Sub
Private Sub ResizeHandler() Handles Me.SizeChanged
fillPattern.Width = Width - 40
End Sub
Private Sub Shutdown() Handles Me.Closing
m_TopGUI.btn_binFile.Enabled = True
End Sub
End Class