示例#1
0
        /// <summary>
        /// Contructor with 1 param - the ID
        /// Does inits and instantiates the hotkeyset field
        /// </summary>
        /// <param name="ID"></param>
        public HotkeySetForm(int ID)
        {
            InitializeComponent(); // VS inits
            InitializeGUI(); // My own inits

            m_hotkeyset = new HotkeySet(ID); // Creates a new hotkeyset from the param ID
        }
示例#2
0
        /// <summary>
        /// Adds a new set element with the xml
        /// </summary>
        public void XMLAddSet(HotkeySet setInput)
        {
            XMLCreateFile(); // Creates an XML file if it doesnt exist
            XDocument xmlDoc = XDocument.Load("HotkeySets.xml"); // Opens up the xml file

            // In the root element (<sets>) add a <set> with all the values from param
            xmlDoc.Element("sets").Add(
                new XElement("set",
                    new XElement("id", setInput.ID),
                    new XElement("voc", (int)setInput.Voc),
                    new XElement("info", setInput.Info)));

            xmlDoc.Save("HotkeySets.xml"); // Saves all changes to the xml file
        }
示例#3
0
        /// <summary>
        /// Removes the set with the ID from the param object
        /// Adds set from the same param object
        /// </summary>
        /// <param name="setInput">The set to be modified</param>
        public void XMLChangeSet(HotkeySet setInput)
        {
            XMLCreateFile(); // Creates an XML file if it doesnt exist
            XDocument xmlDoc = XDocument.Load("HotkeySets.xml"); // Opens the xml file for modification

            var sets = xmlDoc.Element("sets") // <sets>
                .Elements("set") // <set>
                .Where(elem => (string)elem.Element("id").Value == setInput.ID.ToString()); // Chooses the element (or elements) with the same id as param object's ID

            foreach (var set in sets) // Loops through the sets and updates the matches
            {
                set.Element("voc").Value = ((int)setInput.Voc).ToString(); // Updates the nodevalue to the voc casted into an int, and then turned into a string
                set.Element("info").Value = setInput.Info; // Updates the nodevalue to the info string from param
            }

            xmlDoc.Save("HotkeySets.xml"); // Saves modifications to the xml
        }
示例#4
0
        /// <summary>
        /// Reads a set with a specific ID and outputs that set as an out HotkeySet
        /// </summary>
        /// <param name="ID">The ID of the element that will be read from XML</param>
        /// <param name="setOutput">Out param for the hotkeyset output</param>
        /// <returns>True/false depending on if the read was successful or not</returns>
        public bool XMLReadSet(int ID, out HotkeySet setOutput)
        {
            XMLCreateFile(); // Creates an XML file if it doesnt exist
            XDocument xmlDoc = XDocument.Load("HotkeySets.xml"); // Opens up the xml file

            // Selects all sets with the given ID
            var sets = from set in xmlDoc.Descendants("set")
                       where set.Element("id").Value == ID.ToString()
                       select new
                       {
                           ID = set.Element("id").Value,
                           Voc = set.Element("voc").Value,
                           Info = set.Element("info").Value,
                       };

            // If the first element is "sets" is not null (at least one element was found with that ID)
            if (sets.FirstOrDefault() != null)
            {
                // Sets the setOutput to a new hotkeyset based on the values read from xml
                setOutput = new HotkeySet(ID, (CharacterClass)int.Parse(sets.First().Voc), sets.First().Info);
                return true; // Returns true, the read was successful
            }
            else // If no element with that ID was found
            {
                setOutput = null; // Sets the output to null (wont be used for anything)
                return false; // Returns false, the read failed
            }
        }