private void loadMostRecentDatabases() { try { _mostRecentFile = System.IO.Path.Combine(Core.PluginDataPath, string.Format("{0}.xml", this.GetType().ToString().Replace(".", ""))); if (System.IO.File.Exists(_mostRecentFile)) { Framework.Data.InternalStorageDestination curDatabase = null; if (_recentDatabases.Count > 0) { curDatabase = _recentDatabases[0]; } XmlDocument doc = new XmlDocument(); doc.Load(_mostRecentFile); XmlElement root = doc.DocumentElement; XmlNodeList bmNodes = root.SelectNodes("recent"); if (bmNodes != null) { foreach (XmlNode n in bmNodes) { Framework.Data.InternalStorageDestination bm = new Framework.Data.InternalStorageDestination(); bm.Name = n.SelectSingleNode("Name").InnerText; bm.PluginType = n.SelectSingleNode("PluginType").InnerText; XmlNodeList cNodes = n.SelectSingleNode("infos").SelectNodes("info"); if (cNodes != null) { bm.StorageInfo = new string[cNodes.Count]; for (int i = 0; i < cNodes.Count; i++) { bm.StorageInfo[i] = cNodes[i].InnerText; } } if (curDatabase == null || !curDatabase.SameDestination(bm)) { _recentDatabases.Add(bm); } } } } } catch { } }
private void saveMostRecentDatabases() { //set current to number 1 Framework.Data.InternalStorageDestination curDatabase = ActiveStorageDestination; if (curDatabase != null) { _recentDatabases.Insert(0, curDatabase); //filter out current in list after 1 int i = 1; while (i < _recentDatabases.Count) { if (curDatabase.SameDestination(_recentDatabases[i])) { _recentDatabases.RemoveAt(i); } else { i++; } } //max 9 while (_recentDatabases.Count > 9) { _recentDatabases.RemoveAt(_recentDatabases.Count - 1); } } //save try { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("mostrecent"); doc.AppendChild(root); foreach (Framework.Data.InternalStorageDestination bmi in _recentDatabases) { XmlElement bm = doc.CreateElement("recent"); root.AppendChild(bm); XmlElement el = doc.CreateElement("Name"); XmlText txt = doc.CreateTextNode(bmi.Name); el.AppendChild(txt); bm.AppendChild(el); el = doc.CreateElement("PluginType"); txt = doc.CreateTextNode(bmi.PluginType); el.AppendChild(txt); bm.AppendChild(el); el = doc.CreateElement("infos"); bm.AppendChild(el); if (bmi.StorageInfo != null) { foreach (string c in bmi.StorageInfo) { XmlElement cel = doc.CreateElement("info"); txt = doc.CreateTextNode(c); cel.AppendChild(txt); el.AppendChild(cel); } } } doc.Save(_mostRecentFile); } catch { } //rebuild menu according new order SetMostRecentDatabasesMenu(); }