private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) { Regex rx = new Regex(@"[\w\W]+\.opf"); MatchCollection matches = rx.Matches(this.saveFileDialog1.FileName); try { if (matches.Count == 1) { TreeNode node = treeView1.SelectedNode; if (node == rootNode || node == null) { profiler.WriteOffViewFormat(this.saveFileDialog1.FileName); } else { NativeProfilerUnit unit = (NativeProfilerUnit)treeNodes[treeView1.SelectedNode]; profiler.WriteOffViewFormat(this.saveFileDialog1.FileName, unit); } } else { Stream newFile = new FileStream(this.saveFileDialog1.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); m_tOutput.Seek(0, SeekOrigin.Begin); NativeProfiler.ReadWriteStream(m_tOutput, newFile); m_tOutput.Seek(0, SeekOrigin.End); newFile.Close(); } } catch (Exception localException) { System.Windows.Forms.MessageBox.Show(localException.ToString()); } this.saveFileDialog1.FileName = ""; }
private void button1_Click(object sender, EventArgs e) { // Check if fileName exists; try { FileStream testOpen = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.ReadWrite, FileShare.Read); testOpen.Close(); if (receivingData == false) { try { Stop_Connection(); if (m_tOutput != null) { m_tOutput.Close(); } tempFileName = @"temp.raw"; m_tOutput = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); port = new SerialPort(textBox3.Text, 115200, Parity.None, 8, StopBits.One); if (port.IsOpen == false) { for (uint index = 0; index < 2; index++) { try { Stop_Connection(); port.Open(); port.DiscardInBuffer(); port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived); timeStart = DateTime.Now; receivingData = true; this.button1.Text = "Disconnect"; break; } catch (Exception exception1) { if (index == 1) { MessageBox.Show("Cannot connect to device: " + this.textBox3.Text + " " + exception1.ToString()); } } } } } catch (Exception exception2) { MessageBox.Show("Cannot connect to device: " + this.textBox3.Text + " " + exception2.ToString()); } } else { Stop_Connection(); this.button1.Text = "Connect to Device"; try { localStream = new MemoryStream((int)(m_tOutput.Length)); NativeProfiler.ReadWriteStream(m_tOutput, localStream); if (m_tOutput != null) { m_tOutput.Close(); } m_tOutput = localStream; } catch (OutOfMemoryException) { } LoadRootTree(); } } catch { MessageBox.Show("Cannot not open function names map file " + this.textBox1.Text); } }