From: Lars Op den Kamp Date: Mon, 16 Apr 2012 14:05:13 +0000 (+0200) Subject: cec-config-gui: persist settings both in the eeprom and in the settings xml file X-Git-Tag: upstream/2.2.0~1^2~31^2~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f939231347e93690a034397a00cfafe917571f4b;p=deb_libcec.git cec-config-gui: persist settings both in the eeprom and in the settings xml file --- diff --git a/src/cec-config-gui/CecConfigGUI.cs b/src/cec-config-gui/CecConfigGUI.cs index adc02e8..8fb066f 100644 --- a/src/cec-config-gui/CecConfigGUI.cs +++ b/src/cec-config-gui/CecConfigGUI.cs @@ -551,100 +551,93 @@ namespace CecConfigGui Config.WakeDevices = WakeDevices; Config.PowerOffDevices = PowerOffDevices; - if (!Lib.CanPersistConfiguration()) + /* save settings in the eeprom */ + Lib.PersistConfiguration(Config); + + /* and in xml */ + if (ActiveProcess == null) { - if (ActiveProcess == null) - { - SetControlsEnabled(false); - string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; - string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + SetControlsEnabled(false); + string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data"; + string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - SaveFileDialog dialog = new SaveFileDialog() + SaveFileDialog dialog = new SaveFileDialog() + { + Title = "Where do you want to store the settings?", + InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir, + FileName = "usb_2548_1001.xml", + Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*", + FilterIndex = 1 + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + FileStream fs = null; + string error = string.Empty; + try { - Title = "Where do you want to store the settings?", - InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir, - FileName = "usb_2548_1001.xml", - Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*", - FilterIndex = 1 - }; - - if (dialog.ShowDialog() == DialogResult.OK) + fs = (FileStream)dialog.OpenFile(); + } + catch (Exception ex) { - FileStream fs = null; - string error = string.Empty; - try - { - fs = (FileStream)dialog.OpenFile(); - } - catch (Exception ex) - { - error = ex.Message; - } - if (fs == null) - { - MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing" + (error.Length > 0 ? ": " + error : string.Empty ), "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - else - { - StreamWriter writer = new StreamWriter(fs); - StringBuilder output = new StringBuilder(); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - - // only supported by 1.5.0+ clients - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - output.AppendLine(""); - - output.Append(""); - - output.Append(""); - - // only supported by 1.5.1+ clients - output.AppendLine(""); - output.AppendLine(""); - - output.AppendLine(""); - writer.Write(output.ToString()); - writer.Close(); - fs.Close(); - fs.Dispose(); - MessageBox.Show("Settings are stored.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); - } + error = ex.Message; + } + if (fs == null) + { + MessageBox.Show("Cannot open '" + dialog.FileName + "' for writing" + (error.Length > 0 ? ": " + error : string.Empty ), "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + StreamWriter writer = new StreamWriter(fs); + StringBuilder output = new StringBuilder(); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + + // only supported by 1.5.0+ clients + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + output.AppendLine(""); + + output.Append(""); + + output.Append(""); + + // only supported by 1.5.1+ clients + output.AppendLine(""); + output.AppendLine(""); + + output.AppendLine(""); + writer.Write(output.ToString()); + writer.Close(); + fs.Close(); + fs.Dispose(); + MessageBox.Show("Settings are stored.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); } - SetControlsEnabled(true); } + SetControlsEnabled(true); } - else - { - if (!Lib.PersistConfiguration(Config)) - MessageBox.Show("Could not persist the new settings.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Error); - else - MessageBox.Show("Settings are stored.", "Pulse-Eight USB-CEC Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - SetControlsEnabled(true); } private void bReloadConfig_Click(object sender, EventArgs e)