public static UserConfig FromFile(string filename, string directory) { XmlSerializer ser = new XmlSerializer(typeof(UserConfig)); FileStream fs = new FileStream(filename, FileMode.Open); XmlReader reader = XmlReader.Create(fs); UserConfig cfg = (UserConfig)ser.Deserialize(reader); cfg.Path = directory; if (cfg.OpenedTabs != null) { for (int i = 0; i < cfg.OpenedTabs.Count; i++) { cfg.OpenedTabs[i] = PlatformSpecific.CombinePath(cfg.Path, cfg.OpenedTabs[i]); } } fs.Close(); return(cfg); }
public static void ToFile(string filename, UserConfig cfg) { XmlSerializer ser = new XmlSerializer(typeof(UserConfig)); UserConfig config = (UserConfig)cfg.Clone(); for (int i = 0; i < config.OpenedTabs.Count; i++) { config.OpenedTabs[i] = Formatter.MakeRelative(config.OpenedTabs[i], config.Path + PlatformSpecific.NameSeparator); } FileStream fs = new FileStream(filename, FileMode.Create); XmlTextWriter writer = new XmlTextWriter(fs, Encoding.UTF8) { Formatting = Formatting.Indented, Indentation = 4 }; ser.Serialize(writer, config); fs.Close(); }