//Konstruktor public Calculator(CalcForm newForm) { this.Form = newForm; }
public static void LoadFile(string fileName, CalcForm form, bool custom) { try { if (!File.Exists(fileName)) { Debug.WriteLine("The settings file '" + fileName + "' does not exist."); return; } XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); LoadSettings(xmlDoc); Data.Load(xmlDoc, custom); Help.Load(xmlDoc); form.LoadSettings(xmlDoc, custom); } catch (Exception ex) { MessageBox.Show("An error occurred when trying to load the settings file '" + fileName + "':\n" + ex.Message + "\n\n" + ex.StackTrace, "Settings Not Loaded"); } }
public static void Save(CalcForm form) { try { string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + Globals.k_appNameIdent; if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); string fileName = appDataPath + Path.DirectorySeparatorChar + Globals.k_settingsFileName; XmlTextWriter xml = new XmlTextWriter(fileName, Encoding.UTF8); try { xml.Formatting = Formatting.Indented; xml.WriteStartDocument(); xml.WriteStartElement(Globals.k_appNameIdent); SaveSettings(xml); Data.Save(xml, true); form.SaveSettings(xml); xml.WriteEndElement(); xml.WriteEndDocument(); } finally { xml.Close(); } } catch (Exception ex) { MessageBox.Show("An error occurred when trying to save the settings:\n" + ex.Message + "\n\n" + ex.StackTrace, "Settings Not Saved"); } }
public static void Load(CalcForm form) { try { string defaultFile = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + Globals.k_defaultSettingsFileName; string userFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + Globals.k_appNameIdent + Path.DirectorySeparatorChar + Globals.k_settingsFileName; Data.SetDefaults(); LoadFile(defaultFile, form, false); LoadFile(userFile, form, true); } catch (Exception ex) { MessageBox.Show("An error occurred when trying to load the settings:\n" + ex.Message + "\n\n" + ex.StackTrace, "Settings Not Loaded"); } }