public static SerializedRule FromRule(PvRuleItem rule) { var srlRule = CreateInstance <SerializedRule>(); srlRule.rule = rule.ShallowCopy(); return(srlRule); }
private static bool DoesPathMatchRule(string path, PvRuleItem rule) { bool didMatch = false; switch (rule.ruleType) { case PvRuleType.Name: string folderName = Path.GetFileName(path); if (rule.ruleString == folderName) { didMatch = true; } break; case PvRuleType.Path: if (rule.ruleString == path) { didMatch = true; } break; case PvRuleType.Extension: string extn = Path.GetExtension(path); if (extn == rule.ruleString) { didMatch = true; } break; case PvRuleType.Regex: if (Regex.IsMatch(path, rule.ruleString)) { didMatch = true; } break; } return(didMatch); }
public static bool TryMatchAgainstRules(this PvCustomizerSettings settings, string path, out PvRuleItem matchingRule, bool enabledOnly = true, bool respectPriority = true) { int matchIndex = -1; for (int i = 0; i < settings.Rules.Count; i++) { PvRuleItem rule = settings.Rules[i]; if (!rule.enabled && enabledOnly) { continue; } bool didMatch = false; didMatch = DoesPathMatchRule(path, rule); if (didMatch) { if (matchIndex == -1 || settings.Rules[matchIndex].priority < settings.Rules[i].priority) { matchIndex = i; } if (!respectPriority) { break; } } } if (matchIndex == -1) { matchingRule = null; return(false); } else { matchingRule = settings.Rules[matchIndex]; return(true); } }
public static int GetAllMatchingRules(this PvCustomizerSettings settings, string path, List <PvRuleItem> matchingRules, bool enabledOnly = true) { int matched = 0; for (int i = 0; i < settings.Rules.Count; i++) { PvRuleItem rule = settings.Rules[i]; if (!rule.enabled && enabledOnly) { continue; } if (DoesPathMatchRule(path, rule)) { matched++; matchingRules.Add(rule); } } return(matched); }