示例#1
0
        private void but_dflogtokml_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog1 = new OpenFileDialog())
            {
                openFileDialog1.Filter = "Log Files|*.log;*.bin";
                openFileDialog1.FilterIndex = 2;
                openFileDialog1.RestoreDirectory = true;
                openFileDialog1.Multiselect = true;
                try
                {
                    openFileDialog1.InitialDirectory = Settings.Instance.LogDir + Path.DirectorySeparatorChar;
                }
                catch
                {
                } // incase dir doesnt exist

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    foreach (string logfile in openFileDialog1.FileNames)
                    {
                        LogOutput lo = new LogOutput();
                        try
                        {
                            StreamReader tr;

                            if (logfile.ToLower().EndsWith(".bin"))
                            {
                                using (tr = new StreamReader(logfile))
                                {
                                    GC.Collect();
                                    CollectionBuffer temp = new CollectionBuffer(tr.BaseStream);

                                    uint a = 0;
                                    foreach (var line in temp)
                                    {
                                        lo.processLine(line);
                                        a++;

                                        if ((a % 100000) == 0)
                                            Console.WriteLine(a);
                                    }

                                    temp.Dispose();
                                }
                            }
                            else
                            {
                                using (tr = new StreamReader(logfile))
                                {
                                    while (!tr.EndOfStream)
                                    {
                                        lo.processLine(tr.ReadLine());
                                    }

                                    tr.Close();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            CustomMessageBox.Show("Error processing file. Make sure the file is not in use.\n" + ex);
                        }

                        lo.writeKML(logfile + ".kml");
                    }
                }
            }
        }