Beispiel #1
0
        public IList<HostItem> GetHosts()
        {
            if (File.Exists(HostsPath))
            {
                using (StreamReader reader = new StreamReader(HostsPath, Encode))
                {
                    List<HostItem> items = new List<HostItem>();
                    string line;

                    //// Ignore default comments.
                    for (int i = 0; i < 17; i++ )
                    {
                        line = reader.ReadLine();
                    }

                    while (!reader.EndOfStream)
                    {
                        line = reader.ReadLine().Trim();

                        if (string.IsNullOrEmpty(line))
                        {
                            if (items.Count > 0)
                            {
                                items[items.Count - 1].AddLine = true;
                            }

                            continue;
                        }

                        if (line.StartsWith("#"))
                        {
                            HostItem item = new HostItem(line);
                            items.Add(item);

                            continue;
                        }

                        Match match = RegItem.Match(line);
                        if (match.Success)
                        {
                            string ip = match.Result("$1");
                            string name = match.Result("$2");
                            string desc = match.Result("$3");

                            HostItem item = new HostItem(ip, name, desc, false);
                            items.Add(item);
                        }
                    }
                    return items;
                }
            }
            return null;
        }