Exemple #1
0
        public static void Save()
        {
            try {
                Directory.CreateDirectory(SettingsDir);
                var ms = new MemoryStream();
                var xw = new XmlTextWriter(ms, Encoding.UTF8);
                xw.Formatting = Formatting.Indented;
                xw.WriteStartDocument();
                xw.WriteStartElement("settings");

                DataSource?.WriteTo(xw);
                NameMapping.WriteTo(xw);
                xw.WriteElementString("ReadConfigAfterConnect", ReadConfigAfterConnect.ToString());
                xw.WriteElementString("LogPanelExpanded", LogPanelExpanded.ToString());
                xw.WriteElementString("WindowSize", $"{WindowSize.Width}x{WindowSize.Height}");

                xw.WriteEndElement(); // settings
                xw.WriteEndDocument();
                xw.Flush();
                xw.Close();

                File.WriteAllBytes(SettingsFile, ms.ToArray());
                ms.Dispose();
            }
            catch (IOException exc) {
                MessageBox.Show("IO Error while saving: " + exc);
            }
            catch (XmlException exc) {
                MessageBox.Show("XML Error while saving: " + exc);
            }
            catch (Exception exc) {
                MessageBox.Show("Unknown Error while saving: " + exc);
            }
        }