private void LoadFile(object sender, EventArgs e) { using (OpenFileDialog ofdFile = new OpenFileDialog()) { ofdFile.Filter = GAP.filemask; ofdFile.FilterIndex = 2; ofdFile.RestoreDirectory = true; if (ofdFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { GAP.AllTlogData.Clear(); foreach (string logfile in ofdFile.FileNames) { string extension = Path.GetExtension(logfile); if (String.Equals(extension.ToLower(), ".tlog")) { progressbar1.Visibility = Visibility.Visible; GAP.FilePath = Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(logfile) + ".csv"; GAP.FileName = Path.GetFileName(logfile); using (PacketExtractor mine = new PacketExtractor()) { try { mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read)); } catch (Exception ex) { return; } mine.logreadmode = true; while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { int percent = (int) ((float)mine.logplaybackfile.BaseStream.Position / (float)mine.logplaybackfile.BaseStream.Length * 100.0f); if (progressbar1.Value != percent) { progressbar1.Dispatcher.Invoke(() => progressbar1.Value = percent, DispatcherPriority.Background); } MAVLinkMessage packet = mine.ReadPacket(); string text = ""; mine.DebugPacket(packet, ref text, false, ","); Parser.addMessage("* " + mine.lastlogread.ToString("yyyy-MM-dd HH:mm:ss.fff")); Parser.addMessage(text); } Parser.parseMessages(); ArrayList headers = Parser.GetHeaders(); foreach (string header in headers) { GlobalAppData.TlogData data = new GlobalAppData.TlogData(); data.HeaderName = header; data.Name = RM.GetString(header); GAP.AddTlogData(data); } progressbar1.Value = 100; EnableSettings(); FileLabel.Visibility = Visibility.Visible; mine.logreadmode = false; mine.logplaybackfile.Close(); mine.logplaybackfile = null; } } else if (String.Equals(extension.ToLower(), ".bin")) { DialogResult Result = System.Windows.Forms.MessageBox.Show("The .bin file does not display any data parameters." + Environment.NewLine + "We will be exporting the .bin file into a .csv file. Are you fine with that?", ".Bin Message", System.Windows.Forms.MessageBoxButtons.YesNo); if (Result == System.Windows.Forms.DialogResult.Yes) { try { using (BinaryReader br = new BinaryReader(new BufferedStream(File.OpenRead(logfile), 1024 * 1024))) { DateTime displaytimer = DateTime.MinValue; var length = br.BaseStream.Length; while (br.BaseStream.Position < length) { string data = BL.ReadMessage(br.BaseStream, length); BP.InputContent(data); } } BP.ParseBIN(); ArrayList OutputMessages = BP.GetMessages(); if (sw != null) { sw.Dispose(); } sw = new StreamWriter(Path.GetDirectoryName(logfile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(logfile) + ".csv"); foreach (string message in OutputMessages) { sw.WriteLine(message); } sw.Close(); System.Windows.Forms.MessageBox.Show("You have successfully converted " + Path.GetFileName(logfile) + " into a .csv file"); DisableSettings(); } catch { System.Windows.MessageBox.Show("You currently have the .csv open. Please close your .csv file and retry.", "Open File Error"); } } } else { System.Windows.MessageBox.Show("You've selected the wrong file type.", "Wrong File Type Error"); } } } } }