Exemplo n.º 1
0
        private ConfigFile SaveConfigFile(bool saveNew = false)
        {
            if (this.CurrentProfile.ECUFile != null)
            {
                Measurements ms = new Measurements();
                foreach (Measurement m in this.CurrentProfile.ECUFile.Measurements.Values.Where(m => m.Selected))
                {
                    ms.AddMeasurement(m);
                }

                if (ms.Values.Count() > 0)
                {
                    if (saveNew || string.IsNullOrEmpty(this.txtConfigFile.Text))
                    {
                        SaveFileDialog d = new SaveFileDialog();
                        d.Title            = "Save Config File As...";
                        d.InitialDirectory =
                            string.IsNullOrWhiteSpace(this.txtConfigFile.Text) ?
                            System.IO.Path.Combine(Program.ME7LoggerDirectory, "logs") :
                            System.IO.Path.GetDirectoryName(this.txtConfigFile.Text);
                        d.FileName = System.IO.Path.GetFileName(this.txtConfigFile.Text);
                        if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return(null);
                        }
                        this.txtConfigFile.Text = d.FileName;
                    }

                    ConfigFile configFile = new ConfigFile(txtConfigFile.Text, this.CurrentProfile.ECUFile.FileName, ms);
                    configFile.Write();
                    return(configFile);
                }
                else
                {
                    MessageBox.Show("No Measurements Selected");
                }
            }
            return(null);
        }