Exemple #1
0
        public static List <Pair <FilterType, Regex> > ParseFdf(string fdfPath)
        {
            List <string> fdfPathList = new List <string>();

            if (fdfPath == null)
            {
                return((List <Pair <FilterType, Regex> >)null);
            }
            return(FilterDescription.ParseFdfRecursively(fdfPath, ref fdfPathList));
        }
Exemple #2
0
        private static List <Pair <FilterType, Regex> > ParseFdfRecursively(string fdfPath, ref List <string> fdfPathList)
        {
            fdfPath = FilterDescription.FormatFilePathDelimiterForFilter(fdfPath);
            if (!Path.IsPathRooted(fdfPath) && fdfPathList.Count > 0)
            {
                fdfPath = Path.Combine(Path.GetDirectoryName(fdfPathList[fdfPathList.Count - 1]), fdfPath);
            }
            fdfPath = Path.GetFullPath(fdfPath).TrimEnd('\\');
            if (0 <= fdfPathList.FindIndex((Predicate <string>)(path => string.Compare(path, fdfPath, StringComparison.InvariantCultureIgnoreCase) == 0)))
            {
                return(new List <Pair <FilterType, Regex> >());
            }
            fdfPathList.Add(fdfPath);
            List <Pair <FilterType, Regex> > pairList = new List <Pair <FilterType, Regex> >();

            using (StreamReader streamReader = new StreamReader(fdfPath))
            {
                while (!streamReader.EndOfStream)
                {
                    string path = streamReader.ReadLine();
                    if (!string.IsNullOrEmpty(path) && !path.StartsWith(";"))
                    {
                        string input = FilterDescription.ReplaceEnvironmentVariableKeyword(path);
                        Match  match = FilterDescription.RegexKeywordInclude.Match(input);
                        if (match.Success)
                        {
                            string fdfPath1 = match.Groups["path"].Value;
                            pairList.AddRange((IEnumerable <Pair <FilterType, Regex> >)FilterDescription.ParseFdfRecursively(fdfPath1, ref fdfPathList));
                        }
                        FilterType a;
                        switch (input[0])
                        {
                        case '+':
                            a = FilterType.Exception;
                            break;

                        case '-':
                            a = FilterType.Remove;
                            break;

                        default:
                            continue;
                        }
                        Regex b = new Regex(FilterDescription.FormatFilePathDelimiterForFilterRegex(input.Substring(1).Trim().Trim('"')), RegexOptions.Compiled);
                        pairList.Add(new Pair <FilterType, Regex>(a, b));
                    }
                }
                return(pairList);
            }
        }