Ejemplo n.º 1
0
        /// <summary>
        /// Saves the CONF file
        /// </summary>
        public void Save()
        {
            int line = 0;                                                       // Set the line
            Dictionary <int, object> tmpCONFs = new Dictionary <int, object>(); // Create temporary CONFs
            List <string>            lines    = new List <string>();            // Create the lines list

            while (CONFs.Count > 0)                                             // Loop until both are empty
            {
                if (CONFs.ContainsKey(line))
                {
                    lines.Add(CONFs[line].ToString()); // Add to the list of lines
                    tmpCONFs.Add(line, CONFs[line]);   // Add to tmp CONFs
                    CONFs.Remove(line);                // Remove from the original CONF

                    line++;                            // Add the line
                    continue;                          // Continue
                }

                lines.Add("\n"); // Add new line
                line++;          // Add the line
            }

            CONFs = tmpCONFs;                          // Set the CONFs
            File.WriteAllLines(Path, lines.ToArray()); // Write to file
        }
Ejemplo n.º 2
0
        public static void Serialize <T>(string filepath) => Serialize(filepath, Activator.CreateInstance <T>()); // Create instance and serialize

        #endregion

        #region Public Functions
        /// <summary>
        /// Reloads the CONF file
        /// </summary>
        public void Reload()
        {
            if (CreatedNew)
            {
                return;                               // If it is just created don't bother
            }
            string[] lines = File.ReadAllLines(Path); // Read all the file lines

            for (int i = 0; i < lines.Length; i++)
            {
                switch (lines[i][0])
                {
                case '\n':
                    continue;     // Skip if empty

                case '#':
                    CONFs.Add(i, lines[i].Substring(1, lines[i].Length - 1));     // It's a comment add it
                    continue;
                }

                if (!lines[i].Contains("="))
                {
                    continue;
                }
                string[] spl   = lines[i].Split('='); // Split the CONF
                string   Value = "";                  // Set the value

                for (int a = 1; a < spl.Length; a++)
                {
                    Value += spl[a] + ((a + 1) == spl.Length ? "" : "="); // Add to the value
                }
                CONFs.Add(i, new CONF(Value, spl[0]));                    // Add the CONF
                continue;
            }
        }
Ejemplo n.º 3
0
        public void AddCONF(string key, string value) => CONFs.Add(CONFs.Keys.Max(), new CONF(value, key)); // Add the CONF

        /// <summary>
        /// Adds a CONF to the line
        /// </summary>
        /// <param name="key">The key of the CONF</param>
        /// <param name="value">The value of the CONF</param>
        /// <param name="line">The line to add the CONF to</param>
        public void AddCONF(string key, string value, int line) => CONFs.Add(line, new CONF(value, key)); // Add the CONF
Ejemplo n.º 4
0
        public void RemoveCONF(int line) => CONFs.Remove(line); // Remove the CONF

        /// <summary>
        /// Adds a CONF to the file
        /// </summary>
        /// <param name="key">The key of the CONF</param>
        /// <param name="value">The value of the CONF</param>
        public void AddCONF(string key, string value) => CONFs.Add(CONFs.Keys.Max(), new CONF(value, key)); // Add the CONF
Ejemplo n.º 5
0
        public void EditComment(string comment, int line) => CONFs[line] = comment; // Change to the comment

        /// <summary>
        /// Remove the comment from the line
        /// </summary>
        /// <param name="line">The line to remove</param>
        public void RemoveCONF(int line) => CONFs.Remove(line); // Remove the CONF
Ejemplo n.º 6
0
        public void AddComment(string comment) => CONFs.Add(CONFs.Keys.Max(), comment); // Add the comment

        /// <summary>
        /// Adds a comment to the line
        /// </summary>
        /// <param name="comment">The comment to add</param>
        /// <param name="line">The line position</param>
        public void AddComment(string comment, int line) => CONFs.Add(line, comment); // Add the comment
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a comment to the file
 /// </summary>
 /// <param name="comment">The comment to add</param>
 public void AddComment(string comment) => CONFs.Add(CONFs.Keys.Max(), comment); // Add the comment