-
Notifications
You must be signed in to change notification settings - Fork 6
Add custom ignore rules #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: poe1
Are you sure you want to change the base?
Changes from all commits
651635b
5693a7c
c6ab272
cf9a576
0f90a9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using ExileCore.Shared.Attributes; | ||
| using ExileCore.Shared.Interfaces; | ||
| using ExileCore.Shared.Nodes; | ||
|
|
||
| namespace MinimapIcons.IgnoreRules; | ||
|
|
||
| public class CustomIgnoreSettings : ISettings | ||
| { | ||
| [Menu("Enable Custom Ignore Rules")] | ||
| public ToggleNode EnableCustomIgnoreRules { get; set; } = new ToggleNode(true); | ||
|
|
||
| [Menu("New Rule Type")] | ||
| public ListNode NewRuleType { get; set; } = new ListNode | ||
| { | ||
| Values = new System.Collections.Generic.List<string> | ||
| { | ||
| "Metadata Exact", | ||
| "Metadata Starts With", | ||
| "Metadata Contains", | ||
| "Name Exact", | ||
| "Name Contains" | ||
| }, | ||
| Value = "Metadata Starts With" | ||
| }; | ||
|
|
||
| [Menu("New Rule Pattern")] | ||
| public TextNode NewRulePattern { get; set; } = new TextNode(""); | ||
|
|
||
| [Menu("Add Rule")] | ||
| public ButtonNode AddRule { get; set; } = new ButtonNode(); | ||
|
|
||
| [Menu("Reload Rules from File")] | ||
| public ButtonNode ReloadRules { get; set; } = new ButtonNode(); | ||
|
|
||
| [Menu("Open Config Folder")] | ||
| public ButtonNode OpenConfigFolder { get; set; } = new ButtonNode(); | ||
|
|
||
| public ToggleNode Enable { get; set; } = new ToggleNode(true); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System; | ||
|
|
||
| namespace MinimapIcons.IgnoreRules; | ||
|
|
||
| public class IgnoreRule | ||
| { | ||
| public IgnoreRuleType Type { get; set; } | ||
| public string Pattern { get; set; } | ||
| public bool IsEnabled { get; set; } = true; | ||
|
|
||
| public IgnoreRule() | ||
| { | ||
| } | ||
|
|
||
| public IgnoreRule(IgnoreRuleType type, string pattern, bool isEnabled = true) | ||
| { | ||
| Type = type; | ||
| Pattern = pattern; | ||
| IsEnabled = isEnabled; | ||
| } | ||
|
|
||
| public bool Matches(string metadata, string renderName) | ||
| { | ||
| if (!IsEnabled || string.IsNullOrWhiteSpace(Pattern)) | ||
| return false; | ||
|
|
||
| return Type switch | ||
| { | ||
| IgnoreRuleType.MetadataExact => metadata.Equals(Pattern, StringComparison.OrdinalIgnoreCase), | ||
| IgnoreRuleType.MetadataStartsWith => metadata.StartsWith(Pattern, StringComparison.OrdinalIgnoreCase), | ||
| IgnoreRuleType.MetadataContains => metadata.Contains(Pattern, StringComparison.OrdinalIgnoreCase), | ||
| IgnoreRuleType.NameExact => renderName.Equals(Pattern, StringComparison.OrdinalIgnoreCase), | ||
| IgnoreRuleType.NameContains => renderName.Contains(Pattern, StringComparison.OrdinalIgnoreCase), | ||
| _ => false | ||
| }; | ||
| } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| var prefix = Type switch | ||
| { | ||
| IgnoreRuleType.MetadataExact => "[META=]", | ||
| IgnoreRuleType.MetadataStartsWith => "[META^]", | ||
| IgnoreRuleType.MetadataContains => "[META*]", | ||
| IgnoreRuleType.NameExact => "[NAME=]", | ||
| IgnoreRuleType.NameContains => "[NAME*]", | ||
| _ => "[???]" | ||
| }; | ||
| return $"{prefix} {Pattern}"; | ||
| } | ||
| } | ||
|
|
||
| public enum IgnoreRuleType | ||
| { | ||
| MetadataExact, // Exact metadata match | ||
| MetadataStartsWith, // Metadata starts with | ||
| MetadataContains, // Metadata contains | ||
| NameExact, // Exact name match | ||
| NameContains // Name contains | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,181 @@ | ||||||
| using System.Collections.Generic; | ||||||
| using System.IO; | ||||||
|
|
||||||
| namespace MinimapIcons.IgnoreRules; | ||||||
|
|
||||||
| public class IgnoreRulesManager | ||||||
| { | ||||||
| private readonly List<IgnoreRule> _customRules = new(); | ||||||
| private readonly Dictionary<string, bool> _cache = new(); | ||||||
| private readonly string _customRulesFilePath; | ||||||
|
|
||||||
| public IReadOnlyList<IgnoreRule> CustomRules => _customRules.AsReadOnly(); | ||||||
|
|
||||||
| public IgnoreRulesManager(string directoryFullName) | ||||||
| { | ||||||
| var configDir = Path.Combine(directoryFullName, "config"); | ||||||
| if (!Directory.Exists(configDir)) | ||||||
| Directory.CreateDirectory(configDir); | ||||||
|
|
||||||
| _customRulesFilePath = Path.Combine(configDir, "custom_ignore_rules.txt"); | ||||||
| LoadCustomRules(); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| public void LoadCustomRules() | ||||||
| { | ||||||
| _customRules.Clear(); | ||||||
| ClearCache(); | ||||||
|
|
||||||
| if (!File.Exists(_customRulesFilePath)) | ||||||
| { | ||||||
| SaveCustomRules(); // Create default file | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| try | ||||||
| { | ||||||
| var lines = File.ReadAllLines(_customRulesFilePath); | ||||||
| foreach (var line in lines) | ||||||
| { | ||||||
| var trimmedLine = line.Trim(); | ||||||
| if (string.IsNullOrWhiteSpace(trimmedLine) || trimmedLine.StartsWith("#")) | ||||||
| continue; | ||||||
|
|
||||||
| var rule = ParseRule(trimmedLine); | ||||||
| if (rule != null) | ||||||
| _customRules.Add(rule); | ||||||
| } | ||||||
| } | ||||||
| catch | ||||||
| { | ||||||
| // Silent fail - error will be handled by caller | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public void SaveCustomRules() | ||||||
| { | ||||||
| try | ||||||
| { | ||||||
| var lines = new List<string> | ||||||
| { | ||||||
| "# Custom Ignore Rules for MinimapIcons", | ||||||
| "# Format examples:", | ||||||
|
||||||
| "# Format examples:", | |
| "# Rule formats:", |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching all exceptions without logging prevents debugging of file save issues. Consider logging the exception details to help users diagnose permission or disk space problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching all exceptions without logging prevents debugging of file parsing issues. Consider logging the exception details or at minimum the exception type to help users diagnose configuration file problems.