public bool Save(ServerSettings ss) { bool ret = false; XmlDocument doc = new XmlDocument(); doc.Load(this.settings_path); if (Check(ss, doc.DocumentElement)) { throw new SettingsException(SettingsException.ExceptionTypes.DUPLICATE_ENTRY); } #region xml fragment settings string xmlfrag = @" <server dummy='{10}'> <uid>{0}</uid> <servername>{1}</servername> <server>{2}</server> <username>{3}</username> <password>{4}</password> <description>{5}</description> <colordepth>{6}</colordepth> <desktopwidth>{7}</desktopwidth> <desktopheight>{8}</desktopheight> <fullscreen>{9}</fullscreen> <port>{11}</port> <gid>{12}</gid> </server> "; xmlfrag = string.Format(xmlfrag, ss.UID, ss.ServerName, ss.Server, ss.Username, (ss.Password == string.Empty ? string.Empty : RijndaelSettings.Encrypt(ss.Password)), ss.Description, ss.ColorDepth, ss.DesktopWidth, ss.DesktopHeight, ss.Fullscreen, ss.UID, ss.Port ); #endregion XmlDocumentFragment docFrag = doc.CreateDocumentFragment(); docFrag.InnerXml = xmlfrag; XmlNode curNode = doc.DocumentElement; curNode.InsertAfter(docFrag, curNode.LastChild); doc.Save(this.settings_path); ret = true; return(ret); }
public bool Update(ServerSettings ss, ServerSettings oldSS) { bool ret = false; XmlDocument doc = new XmlDocument(); doc.Load(this.settings_path); // check if the user made some changes on Server Name and Server address if ((ss.ServerName != oldSS.ServerName) || (ss.Server != oldSS.Server)) { // if so, then check if both of these settings has a duplicate on our db if (Check(ss, doc.DocumentElement)) { throw new SettingsException(SettingsException.ExceptionTypes.DUPLICATE_ENTRY); } } #region xml fragment settings string xmlfrag = @" <uid>{0}</uid> <servername>{1}</servername> <server>{2}</server> <username>{3}</username> <password>{4}</password> <description>{5}</description> <colordepth>{6}</colordepth> <desktopwidth>{7}</desktopwidth> <desktopheight>{8}</desktopheight> <fullscreen>{9}</fullscreen> <port>{10}</port> <gid>{11}</gid> "; xmlfrag = string.Format(xmlfrag, oldSS.UID, ss.ServerName, ss.Server, ss.Username, RijndaelSettings.Encrypt(ss.Password), ss.Description, ss.ColorDepth, ss.DesktopWidth, ss.DesktopHeight, ss.Fullscreen, //ss.ServerName, ss.Server, ss.Port ); #endregion XmlElement curNode = doc.DocumentElement; XmlNode oldNode = curNode.SelectSingleNode("/serverlists/server[@dummy=\"" + oldSS.UID + "\"]"); XmlElement newNode = doc.CreateElement("server"); newNode.SetAttribute("dummy", oldSS.UID); newNode.InnerXml = xmlfrag; curNode.ReplaceChild(newNode, oldNode); doc.Save(this.settings_path); ret = true; return(ret); }