Files
ThreadPilot/Models/ProcessPowerPlanAssociation.cs
T
PrimeBuild-pc 010dee679f Add docs, themes, services and UI updates
Large changeset adding documentation, themes, converters and wiring between UI and services. Key changes:

- Rewrote .gitignore to standardize build, IDE, OS and project-specific ignores.
- Added comprehensive documentation: ADVANCED_CPU_FEATURES.md, API_REFERENCE.md, ARCHITECTURE_GUIDE.md, DEVELOPER_GUIDE.md, GAME_BOOST_VALIDATION.md, CLAUDE.md, PROJECT_STRUCTURE.md, UI_STYLE_GUIDE.md, TRADEMARK.md.
- Added theme resources (Themes/FluentLight.xaml, Themes/FluentDark.xaml) and merged FluentLight into App.xaml resource dictionary.
- Added NullToBoolConverter and registered it in App.xaml.
- Enabled a DEBUG-only console test mode in App.xaml.cs (--test flag) and guarded AllocConsole with #if DEBUG.
- Added new service/support files (AtomicFileWriter, StoragePaths, ThemeService) and numerous updates across Services (CpuTopologyService, CoreMaskService, PowerPlanService, ProcessMonitorManagerService, ProcessService, NotificationService, SystemTrayService, SystemTweaksService, EnhancedLoggingService, etc.).
- Updated many ViewModels and Views to support new functionality (CPU topology, power plan and game-boost features) and tests (Tests/TestRunner.cs).
- Added build-release.ps1 and various project metadata updates.

Overall this commit introduces documentation, theming, new converters and test/debug support, plus extensive service and UI wiring for CPU topology, process monitoring, power plans and game boost features.
2026-04-10 03:58:51 +02:00

181 lines
5.9 KiB
C#

/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using CommunityToolkit.Mvvm.ComponentModel;
using ThreadPilot.Models.Core;
namespace ThreadPilot.Models
{
/// <summary>
/// Represents an association between an executable and a power plan
/// </summary>
public partial class ProcessPowerPlanAssociation : ObservableObject, IModel
{
[ObservableProperty]
private string id = Guid.NewGuid().ToString();
[ObservableProperty]
private string executableName = string.Empty;
[ObservableProperty]
private string executablePath = string.Empty;
[ObservableProperty]
private string powerPlanGuid = string.Empty;
[ObservableProperty]
private string powerPlanName = string.Empty;
/// <summary>
/// Core mask ID to apply to this process (optional)
/// </summary>
[ObservableProperty]
private string? coreMaskId = null;
/// <summary>
/// Core mask name for display (optional)
/// </summary>
[ObservableProperty]
private string? coreMaskName = null;
/// <summary>
/// Process priority to apply (optional)
/// </summary>
[ObservableProperty]
private string? processPriority = null;
[ObservableProperty]
private bool isEnabled = true;
[ObservableProperty]
private DateTime createdAt = DateTime.UtcNow;
[ObservableProperty]
private DateTime updatedAt = DateTime.UtcNow;
// IModel implementation - properties are auto-generated by ObservableProperty
[ObservableProperty]
private string description = string.Empty;
/// <summary>
/// Whether to match by exact executable name or path
/// </summary>
[ObservableProperty]
private bool matchByPath = false;
/// <summary>
/// Priority for this association (higher number = higher priority)
/// Used when multiple associations could match the same process
/// </summary>
[ObservableProperty]
private int priority = 0;
public ProcessPowerPlanAssociation()
{
}
public ProcessPowerPlanAssociation(string executableName, string powerPlanGuid, string powerPlanName)
{
ExecutableName = executableName;
PowerPlanGuid = powerPlanGuid;
PowerPlanName = powerPlanName;
}
/// <summary>
/// Checks if this association matches the given process
/// </summary>
public bool MatchesProcess(ProcessModel process)
{
if (!IsEnabled) return false;
if (MatchByPath && !string.IsNullOrEmpty(ExecutablePath))
{
return string.Equals(process.ExecutablePath, ExecutablePath, StringComparison.OrdinalIgnoreCase);
}
else
{
var processName = NormalizeExecutableName(process.Name);
var associationName = NormalizeExecutableName(ExecutableName);
return string.Equals(processName, associationName, StringComparison.OrdinalIgnoreCase);
}
}
/// <summary>
/// Checks if this association matches the given executable name
/// </summary>
public bool MatchesExecutable(string executableName)
{
if (!IsEnabled) return false;
var associationName = NormalizeExecutableName(ExecutableName);
var inputName = NormalizeExecutableName(executableName);
return string.Equals(associationName, inputName, StringComparison.OrdinalIgnoreCase);
}
private static string NormalizeExecutableName(string? executableName)
{
if (string.IsNullOrWhiteSpace(executableName))
{
return string.Empty;
}
return Path.GetFileNameWithoutExtension(executableName.Trim());
}
public ValidationResult Validate()
{
var errors = new List<string>();
if (string.IsNullOrWhiteSpace(ExecutableName))
errors.Add("Executable name is required");
if (string.IsNullOrWhiteSpace(PowerPlanGuid))
errors.Add("Power plan GUID is required");
if (string.IsNullOrWhiteSpace(PowerPlanName))
errors.Add("Power plan name is required");
return errors.Count == 0 ? ValidationResult.Success() : ValidationResult.Failure(errors.ToArray());
}
public IModel Clone()
{
return new ProcessPowerPlanAssociation
{
id = Guid.NewGuid().ToString(), // New ID for clone
ExecutableName = this.ExecutableName,
ExecutablePath = this.ExecutablePath,
PowerPlanGuid = this.PowerPlanGuid,
PowerPlanName = this.PowerPlanName,
CoreMaskId = this.CoreMaskId,
CoreMaskName = this.CoreMaskName,
ProcessPriority = this.ProcessPriority,
IsEnabled = this.IsEnabled,
Description = this.Description,
MatchByPath = this.MatchByPath,
createdAt = DateTime.UtcNow,
updatedAt = DateTime.UtcNow
};
}
}
}