BitServer.INI.completeINI C# (CSharp) Method

completeINI() public static method

public static completeINI ( string FileName ) : INIPart[]
FileName string
return INIPart[]
        public static INIPart[] completeINI(string FileName)
        {
            List<INIPart> parts = new List<INIPart>();
            if (File.Exists(FileName))
            {
                INIPart p = new INIPart();
                foreach (string Line in File.ReadAllLines(FileName))
                {
                    //Filter invalid Lines
                    if (Line.Length > 0 && !Line.StartsWith(";"))
                    {
                        //New Section
                        if (Line.StartsWith("[") && Line.EndsWith("]"))
                        {
                            if (p.Section != null)
                            {
                                parts.Add(p);
                                p = new INIPart();
                            }
                            p.Section = Line.Substring(1, Line.Length - 2);
                            p.Settings = new NameValueCollection();
                        }
                        else
                        {
                            //New Setting
                            if (p.Section != null && Line.Contains("="))
                            {
                                p.Settings.Add(Line.Split('=')[0].Trim(), Line.Split(new char[] { '=' }, 2)[1]);
                            }
                        }
                    }
                }
                if (p.Section != null)
                {
                    parts.Add(p);
                }
                return parts.ToArray();
            }
            return null;
        }