private plugin ToRoot() { plugin r = this.GetRootForCurrent(); if (r == null) { return(null); } r.profileName = this.ProfileName; r.enabled = this.Enabled; r.minVersion = this.MinVersion; r.version = this.Version; if (r.commands != null) { foreach (var item in r.commands) { if (this.m_Commands.ContainsKey(item.hotkey)) { var c = this.m_Commands[item.hotkey]; item.category = c.Category; item.description = c.Description; item.enabled = c.Enabled; item.hotkey = c.Hotkey; item.name = c.Name; } } } if (r.hotstrings != null) { foreach (var item in r.hotstrings) { if (this.m_Hotstrings.ContainsKey(item.trigger)) { var c = this.m_Hotstrings[item.trigger]; item.category = c.Category; item.description = c.Description; item.enabled = c.Enabled; item.trigger = c.Trigger; item.name = c.Name; } } } return(r); }
public bool Save() { plugin r = this.ToRoot(); if (r == null) { return(false); } System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(plugin)); string path = this.m_File; System.IO.FileStream file = System.IO.File.Create(path); writer.Serialize(file, r); file.Close(); return(true); }
/// <summary> /// Populate the Class from an instace of <typeparamref name="root"/> /// </summary> /// <param name="r">The instance to read value from</param> protected void PopulateFromRoot(plugin r) { this.m_Enabled = r.enabled; this.m_version = r.version; this.m_ProfileName = r.profileName; this.m_MinVersion = r.minVersion; if (r.commands != null) { foreach (var cmd in r.commands) { CommandSimple cs = new CommandSimple(cmd); if (string.IsNullOrEmpty(cs.Hotkey)) { continue; } if (this.m_Commands.ContainsKey(cs.Hotkey)) { continue; } cs.DataStateChanged += this.CommandDataStateEventHandler; this.m_Commands.Add(cs.Hotkey, cs); } } if (r.hotstrings != null) { foreach (var hs in r.hotstrings) { HotstringSimple hss = new HotstringSimple(hs); if (string.IsNullOrEmpty(hs.trigger)) { continue; } if (this.m_Hotstrings.ContainsKey(hs.trigger)) { continue; } hss.DataStateChanged += this.HotStringDataStateEventHandler; this.m_Hotstrings.Add(hss.Trigger, hss); } } if (r.includes != null) { foreach (var inc in r.includes) { if (inc.commands != null) { foreach (var cmd in inc.commands) { includeCommand hsCmd = new includeCommand(cmd); if (string.IsNullOrEmpty(cmd.hotkey)) { continue; } if (this.m_IncCommands.ContainsKey(cmd.hotkey)) { continue; } hsCmd.ParentInclude = inc; this.m_IncCommands.Add(hsCmd.hotkey, hsCmd); } } if (inc.hotstrings != null) { foreach (var hs in inc.hotstrings) { includeHotstring h = new includeHotstring(hs, r.File); if (string.IsNullOrEmpty(hs.trigger)) { continue; } if (this.m_IncHotstrings.ContainsKey(hs.trigger)) { continue; } h.ParentInclude = inc; this.m_IncHotstrings.Add(h.trigger, h); } } } } }