// Please excuse the fact that I found out it was called 'Wireshark' about half way through and then
// couldn't be bothered fixing the function names
private void btnOpenWireShackFile_Click(object sender, EventArgs e)
{
MessageBox.Show("Remember to select the Wireshark \"K12 Text File\" that you have saved with " +
"the filter 'sap.flags' (no apostrophes) and save \"Packet Range: Displayed\" and \"All packets\"",
"Instructions", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnSave.Enabled = false;
openWireshackTxtFile.Title = "Choose wireshark txt file";
openWireshackTxtFile.Filter = "TXT Files|*.txt";
if (openWireshackTxtFile.ShowDialog(this) == DialogResult.OK)
{
strWireSharkFileLocation = openWireshackTxtFile.FileName;
replaceBigTextBox("");
replaceM3UTextBox("");
Thread threadReadHex
= new Thread
(readHexAndOutputASCII
); threadReadHex.IsBackground = true;
threadReadHex.Start();
}
}
private void readHexAndOutputASCII()
{
if (strWireSharkFileLocation == "VOID")
{
return;
}
try
{
strWireSharkFile = File.ReadAllLines(strWireSharkFileLocation);
}
catch
{
MessageBox.Show("Failed to open Wireshack file", "Fatal error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
replaceM3UTextBox("#EXTM3U\r\n");
int i = 1;
int j = 0;
foreach (string line in strWireSharkFile)
{
if (line.Length > 2 && line.Substring(0, 2) == "|0")
{
string[] characters = line.Split('|');
string completeLine = "";
foreach (string hex in characters)
{
if (hex.Length == 2)
{
try
{
int n = Convert.ToInt32(hex, 16);
if (n >= 32 && n < 255)
{
char c = (char)n;
completeLine += c.ToString();
}
else if (n == 10)
{
completeLine += "|";
}
}
catch
{
// Do we need to do anything here?
}
}
}
addToBigTextBox(completeLine.Replace("|", "\r\n") + "\r\r\n");
string[] partLine = completeLine.Split('|');
foreach (string data in partLine)
{
if (data.Length > 3 && data.Substring(0, 2) == "s=")
{
string channelName = data.Substring(2, data.Length - 2);
addToM3UTextBox("#EXTINF:" + i + "," + channelName + "\r\n");
}
if (data.Length > 3 && data.Substring(0, 2) == "c=")
{
string nospacedata = data.Replace(" ", "");
string[] splitip = nospacedata.Split('/');
string ip = splitip[0].Substring(7, splitip[0].Length - 7);
addToM3UTextBox("udp://" + ip + ":5000" + "\r\n");
}
}
decimal deProgressBar = (((decimal)j + 1) / (decimal)strWireSharkFile.Length) * 100;
intProgressBar = (int)Math.Ceiling(deProgressBar);
changeProgressBar();
i++;
}
j++;
}
intProgressBar = 100;
changeProgressBar();
}