Files
ThreadPilot/Services/PersistentRuleResolution.cs
T
PrimeBuild-pc 2102724b8f feat: back up persistent rules and resolve rule precedence deterministically
- Configuration export now includes persistent process rules (schema 3.0),
  stays compatible with 2.0 bundles, validates before writing, previews
  what an import replaces and rolls back on failure.
- Matching rules apply broad-to-specific (name, wildcard path, exact path,
  then most recently edited), shared by the engine and the process summary,
  which now lists the apply order and flags conflicting values.
- Localized the new strings in all seven languages.
2026-10-14 17:05:41 +02:00

27 lines
1.6 KiB
C#

namespace ThreadPilot.Services
{
using ThreadPilot.Helpers;
using ThreadPilot.Models;
public static class PersistentRuleResolution
{
// Apply broad rules first; more specific and then more recently edited rules win per setting.
public static IReadOnlyList<PersistentProcessRule> MatchInApplyOrder(
IEnumerable<PersistentProcessRule> rules, ProcessModel process, IPersistentProcessRuleMatcher matcher) =>
rules.Where(rule => matcher.IsMatch(rule, process))
.OrderBy(rule => string.IsNullOrWhiteSpace(rule.ExecutablePath) ? 0 : PathPatternMatcher.HasWildcard(rule.ExecutablePath) ? 1 : 2)
.ThenBy(rule => rule.ExecutablePath?.Count(character => character is not ('*' or '?')) ?? 0)
.ThenBy(rule => rule.UpdatedAt)
.ThenBy(rule => rule.Id, StringComparer.Ordinal)
.ToArray();
public static bool HasConflicts(IReadOnlyList<PersistentProcessRule> rules) =>
rules.Where(r => r.ApplyPriorityOnStart).Select(r => r.Priority).Distinct().Skip(1).Any() ||
rules.Where(r => r.ApplyMemoryPriorityOnStart).Select(r => r.MemoryPriority).Distinct().Skip(1).Any() ||
rules.Where(r => r.ApplyIoPriorityOnStart).Select(r => r.IoPriority).Distinct().Skip(1).Any() ||
rules.Where(r => r.ApplyAffinityOnStart)
.Select(r => $"{r.CpuAssignmentMode}:{r.LegacyAffinityMask}:{string.Join(",", (r.CpuSelection?.GlobalLogicalProcessorIndexes ?? []).Order())}")
.Distinct().Skip(1).Any();
}
}