Example #1
0
        /**
         * Initializes the Cofig Manager
         */
        public static void init()
        {
            if (options != null)
            {
                Console.WriteLine("ERROR: Config.init() : Config has already been initialized..");
                return;
            }

            int lineNumber = 0;
            StreamReader reader = null;
            string temp = null;

            try
            {
                reader = new StreamReader("config.txt");
            }
            catch(FileNotFoundException fnfe)
            {
                MainMethod.die("Error: Config.init() : Unable to find Config file. Exception Method: " + fnfe.Message);
            }

            options = new Trikey();

            while (reader.Peek() > -1)
            {
                temp = getNewLine(reader, ref lineNumber);

                if (String.IsNullOrWhiteSpace(temp) || temp.StartsWith("//") || temp.StartsWith("#"))
                {
                    continue;
                }

                if(!temp.Contains("section"))
                {
                    reader.Close();
                    MainMethod.die("Error: Config.init() : Line number: \"" + lineNumber + "\" is out of place. It does not contain a comment or section start tag. Line Contents:\n" + temp);
                }

                string[] pieces = temp.Split(' ');

                if (!pieces[0].Equals("section"))
                {
                    reader.Close();
                    MainMethod.die("Error: Config.init : Line + \"" + lineNumber + "\" is out of order. \"section\" should be first string a in line. Line Contents:\n" + temp);
                }

                if (pieces.Length == 2)
                {
                    options.addSection(pieces[1]);
                    parseSection(reader, pieces[1], ref lineNumber);
                }
                else
                {
                    if (pieces.Length == 1)
                    {
                        reader.Close();
                        MainMethod.die("Error: Config.init() : Section must be named.");
                    }
                    else
                    {
                        reader.Close();
                        MainMethod.die("Error: Config.init() : This line has to many words on it. Line Number: \"" + lineNumber + "\".");
                    }

                }
            }//End WHile loop

            reader.Close();
        }
Example #2
0
        /**
         * Initializes the Cofig Manager
         */
        public static void init()
        {
            if (options != null)
            {
                Console.WriteLine("ERROR: Config.init() : Config has already been initialized..");
                return;
            }

            int          lineNumber = 0;
            StreamReader reader     = null;
            string       temp       = null;

            try
            {
                reader = new StreamReader("config.txt");
            }
            catch (FileNotFoundException fnfe)
            {
                MainMethod.die("Error: Config.init() : Unable to find Config file. Exception Method: " + fnfe.Message);
            }

            options = new Trikey();

            while (reader.Peek() > -1)
            {
                temp = getNewLine(reader, ref lineNumber);

                if (String.IsNullOrWhiteSpace(temp) || temp.StartsWith("//") || temp.StartsWith("#"))
                {
                    continue;
                }

                if (!temp.Contains("section"))
                {
                    reader.Close();
                    MainMethod.die("Error: Config.init() : Line number: \"" + lineNumber + "\" is out of place. It does not contain a comment or section start tag. Line Contents:\n" + temp);
                }

                string[] pieces = temp.Split(' ');

                if (!pieces[0].Equals("section"))
                {
                    reader.Close();
                    MainMethod.die("Error: Config.init : Line + \"" + lineNumber + "\" is out of order. \"section\" should be first string a in line. Line Contents:\n" + temp);
                }

                if (pieces.Length == 2)
                {
                    options.addSection(pieces[1]);
                    parseSection(reader, pieces[1], ref lineNumber);
                }
                else
                {
                    if (pieces.Length == 1)
                    {
                        reader.Close();
                        MainMethod.die("Error: Config.init() : Section must be named.");
                    }
                    else
                    {
                        reader.Close();
                        MainMethod.die("Error: Config.init() : This line has to many words on it. Line Number: \"" + lineNumber + "\".");
                    }
                }
            }//End WHile loop

            reader.Close();
        }//End Method