Esempio n. 1
0
        private static void TestFile(string filename)
        {
            PoeFilterFile poeFile;

            using (TextReader reader = File.OpenText(filename)) {
                PoeFilterParser parser = new PoeFilterParser();
                poeFile = parser.Parse(reader);
            }
            foreach (RuleBlock filter in poeFile.Blocks)
            {
                for (int i = 0; i < filter.Rules.Count; i++)
                {
                    IFilterRule rule = filter.Rules[i];
                    if (rule.Type == FilterType.ParseError)
                    {
                        throw new InvalidOperationException(rule.Type + ": " + rule.Text);
                    }
                    if (rule.Type == FilterType.WhiteSpace)
                    {
                        continue;
                    }
                    if (rule is DisabledBlock disabledBlock)
                    {
                        rule = disabledBlock.Rule;
                        // Disabled blocks are commented rules
                    }
                    if (rule.Type == FilterType.Show || rule.Type == FilterType.Hide)
                    {
                        continue;
                    }
                    if (rule is IFilterCriteria _)
                    {
                        continue;
                    }
                    if (rule is IFilterAction _)
                    {
                        continue;
                    }
                    throw new InvalidOperationException();                     // must be show/hide, action, or criteria
                }
            }
        }
Esempio n. 2
0
        private static void PrintBlocks(string filename, int maxRuleLength = 80)
        {
            PoeFilterFile poeFile;

            using (TextReader reader = File.OpenText(filename)) {
                PoeFilterParser parser = new PoeFilterParser();
                poeFile = parser.Parse(reader);
            }

            for (int i = 0; i < poeFile.Blocks.Count; i++)
            {
                RuleBlock block = poeFile.Blocks[i];
                // A FilterBlock includes a group of rules after a Show/Hide.
                // It will also include some comments before and after the rule

                foreach (IFilterRule rule in block.Rules)
                {
                    string text = rule.ToString();
                    switch (rule.Type)
                    {
                    case FilterType.DisabledBlock:
                    case FilterType.WhiteSpace:
                    case FilterType.Show:
                    case FilterType.Hide:
                        text = "  " + text;
                        break;

                    default:
                        text = "\t  " + text;
                        break;
                    }
                    if (text.Length > maxRuleLength)
                    {
                        text = text.Substring(0, maxRuleLength - 3) + "...";
                    }
                    Console.WriteLine(text);
                }
                Console.WriteLine("-");
            }
        }
Esempio n. 3
0
        private static void PrintSortedBlocks(string filename, int maxRuleLength = 80)
        {
            PoeFilterFile poeFile;

            using (TextReader reader = File.OpenText(filename)) {
                PoeFilterParser parser = new PoeFilterParser();
                poeFile = parser.Parse(reader);
            }

            foreach (RuleBlock block in poeFile.Blocks)
            {
                // Rules can be categorized into WhiteSpace, Blocks, Criteria, Actions, and Errors
                // See: https://www.pathofexile.com/item-filter/about
                List <IFilterRule> rules = block.Rules;
                if (block.IsDisabled)
                {
                    rules = rules.Where(r => r.Type != FilterType.WhiteSpace).Select(r => ((DisabledBlock)r).Rule)
                            .Where(r => r.Type != FilterType.WhiteSpace).OrderBy(r => r.Type).ToList();
                }
                else
                {
                    rules = block.Rules.Where(r => r.Type != FilterType.WhiteSpace).OrderBy(r => r.Type).ToList();
                }

                foreach (string line in rules.Select(r => r.Type == FilterType.Show || r.Type == FilterType.Hide ? r.ToString() : "\t" + r.ToString()))
                {
                    string text = line;
                    if (text.Length > maxRuleLength)
                    {
                        text = line.Substring(0, maxRuleLength - 3) + "...";
                    }
                    if (block.IsDisabled)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine(text);
                }
                Console.WriteLine();
            }
        }