public static void AddConfig(Config config) { if (!configs.Contains(config)) { configs.Add(config); } }
public bool CheckForUpdates() { Config c = DataHolder.GetConfig(configNode); if (c == null) { c = new Config(configNode); //ADD CONFIG ITEMS DataHolder.AddConfig(c); } bool auto = !((bool)DataHolder.GetConfig().Get("autoupdate")); if (!c.Has("Auto Update")) { c.Set("Auto Update", Config.Type.Bool, true); } if ((bool)c.Get("Auto Update") || auto) { WebClient wc = new WebClient(); string version = wc.DownloadString("https://raw.github.com/Jenjen1324/MCM-Plugins/master/MCM-Plugins/ver.txt"); string localversion = LocalVersion; return version != localversion; } else { return false; } }
public static void LoadConfigs() { FileStream xmlfs = new FileStream(Data.configpath, FileMode.Open); XmlReader xmlr = XmlReader.Create(xmlfs); Config current = null; while (xmlr.Read()) { if (xmlr.Name == "config" && xmlr.NodeType == XmlNodeType.Element) { } else if (xmlr.Name == "node" && xmlr.NodeType == XmlNodeType.Element) { string nodename = xmlr.GetAttribute("name"); current = new Config(nodename); configs.Add(current); } else if (xmlr.Name == "item" && xmlr.NodeType == XmlNodeType.Element) { string itemName = xmlr.GetAttribute("key"); string itemType = xmlr.GetAttribute("type"); Config.Type iType = (Config.Type)Enum.Parse(typeof(Config.Type), itemType); object data = null; try { if (iType == Config.Type.Bool) { data = Convert.ToBoolean(xmlr.ReadElementContentAsString()); } else if (iType == Config.Type.Decimal) { data = Convert.ToDouble(xmlr.ReadElementContentAsString()); } else if (iType == Config.Type.Integer) { data = Convert.ToInt32(xmlr.ReadElementContentAsString()); } else if (iType == Config.Type.Text) { data = xmlr.ReadElementContentAsString(); } } catch (Exception e) { throw new Exception("XML Parse Error: ", e); } if (current != null) { if (data != null) { current.Set(itemName, iType, data); } } } } xmlr.Close(); xmlfs.Close(); if (configs.FindAll(p => p.GetName() == "main").Count != 1) { configs.Add(new Config("main")); } }
private Dictionary<string, object> MapConfig(Config config) { Dictionary<string, object> result = new Dictionary<string, object>(); foreach (KeyValuePair<string,Tuple<Config.Type,object>> item in config.GetAll()) { result.Add(item.Key, item.Value.Item2); } return result; }