private void buttonSave_Click(object sender, EventArgs e)
{
if (checkBox1.Checked && sharpTuner.AvailableDevices.DefDictionary.ContainsKey(comboBoxCopyDef.SelectedItem.ToString()))
{
sharpTuner.AvailableDevices.DefDictionary[comboBoxCopyDef.SelectedItem.ToString()].Populate();
def.CopyTables(sharpTuner.AvailableDevices.DefDictionary[comboBoxCopyDef.SelectedItem.ToString()]);//copy tables
}
//Save the definition XML
try
{
XElement xe = XElement.Parse(textBoxDefXml.Text);
def.ident.ParseEcuFlashXml(xe,comboBoxIncludeDef.SelectedValue.ToString());
StringBuilder path = new StringBuilder();
path.Append(Settings.Default.EcuFlashDefRepoPath + "/");
if (def.ident.model != null)
{
path.Append(def.ident.model.ToString());
if (def.ident.submodel != null)
{
string s = " " + def.ident.submodel;
path.Append(s);
}
path.Append("/");
}
string dirpath = path.ToString();
path.Append(def.calibrationlId.ToString() + ".xml");
if (!Directory.Exists(dirpath))
{
Directory.CreateDirectory(dirpath);
}
else if (File.Exists(path.ToString()))
{
DialogResult dialogResult = MessageBox.Show("Definition already exists at " + path.ToString() + System.Environment.NewLine + "Overwrite it??", "Warning", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.No)
{
MessageBox.Show("Save definition aborted");
return;
}
}
def.filePath = path.ToString();
def.ExportEcuFlashXML();
MessageBox.Show("Successfully saved definition to " + def.filePath);
sharpTuner.PopulateAvailableDevices();
this.Dispose();
}
catch (Exception er)
{
MessageBox.Show("Error: " + er.Message);
return;
}
}