namespace ThreadPilot.Services { using System; using System.Collections.Generic; using System.IO; using System.Linq; /// /// Deterministic lists Game Boost decides with. Audio and voice (Discord), capture (OBS) and /// peripheral software are deliberately in none of the built-in lists. /// public static class GameBoostProcessLists { /// Background moved off the game's cores in Automatic; the user can edit this list. public static readonly IReadOnlyList DefaultBackgroundProcesses = [ // Browsers "chrome", "msedge", "firefox", "opera", "brave", "vivaldi", // Sync clients "OneDrive", "Dropbox", "GoogleDriveFS", "iCloudDrive", "MEGAsync", "nextcloud", // Updaters "GoogleUpdate", "MicrosoftEdgeUpdate", "AdobeARM", // Launchers, once the game is running "steam", "steamwebhelper", "EpicGamesLauncher", "EpicWebHelper", "EADesktop", "GalaxyClient", "upc", "Battle.net", ]; /// Added to the user's list in Isolation: processes that are certainly secondary while gaming. public static readonly IReadOnlyList IsolationExtraProcesses = [ "Widgets", "WidgetService", "PhoneExperienceHost", "Spotify", "vlc", "WINWORD", "EXCEL", "POWERPNT", "OUTLOOK", "olk", "ONENOTE", "Acrobat", "AcroRd32", "Code", "devenv", "Notion", "Obsidian", ]; private static readonly string[] GameLibraryPathFragments = [ @"\steamapps\common\", @"\Epic Games\", @"\XboxGames\", @"\GOG Games\", @"\GOG Galaxy\Games\", @"\EA Games\", @"\Ubisoft Game Launcher\games\", @"\Riot Games\", ]; // Executables that live in game folders but are not the game. private static readonly string[] NonGameNameFragments = [ "launcher", "update", "crash", "report", "setup", "install", "unins", "redist", "prereq", "easyanticheat", "battleye", "beservice", "vanguard", "riotclient", "helper", "overlay", "bootstrap", "cefsharp", "service", ]; public static bool IsGame( string? processName, string? executablePath, IReadOnlyCollection? manualGames, IReadOnlyCollection? excludedGames) { var name = Normalize(processName); if (name.Length == 0) { return false; } if (Matches(excludedGames, name, executablePath)) { return false; } if (Matches(manualGames, name, executablePath)) { return true; } return !string.IsNullOrWhiteSpace(executablePath) && GameLibraryPathFragments.Any(fragment => executablePath.Contains(fragment, StringComparison.OrdinalIgnoreCase)) && !NonGameNameFragments.Any(fragment => name.Contains(fragment, StringComparison.OrdinalIgnoreCase)); } public static bool IsListedBackground(string? processName, string? executablePath, GameBoostMode mode, IReadOnlyCollection? userBackground) { var name = Normalize(processName); return name.Length > 0 && (Matches(userBackground, name, executablePath) || (mode == GameBoostMode.Isolation && IsolationExtraProcesses.Any(entry => Normalize(entry).Equals(name, StringComparison.OrdinalIgnoreCase)))); } /// Every name can match (path entries by file name): a cheap prefilter, not the decision. public static HashSet BackgroundNames(GameBoostMode mode, IReadOnlyCollection? userBackground) => new HashSet( (userBackground ?? []).Concat(mode == GameBoostMode.Isolation ? IsolationExtraProcesses : []).Select(Normalize).Where(name => name.Length > 0), StringComparer.OrdinalIgnoreCase); /// Process name without directory and ".exe", so "C:\x\Game.exe", "Game.exe" and "game" all match. public static string Normalize(string? processName) { var name = Path.GetFileName((processName ?? string.Empty).Trim()); return name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ? name[..^4] : name; } // An entry with a directory matches that exact executable; a bare name matches any path. private static bool Matches(IReadOnlyCollection? entries, string normalizedName, string? executablePath) => entries != null && entries.Any(entry => !string.IsNullOrWhiteSpace(entry) && (entry.Contains('\\') ? string.Equals(entry.Trim(), executablePath, StringComparison.OrdinalIgnoreCase) : Normalize(entry).Equals(normalizedName, StringComparison.OrdinalIgnoreCase))); } }