Skip to content

Commit 58c8990

Browse files
Add new bundled power plans (#34)
1 parent fbfe010 commit 58c8990

53 files changed

Lines changed: 242 additions & 31 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Installer/Installer.iss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#define MyAppPublisher "ThreadPilot"
66
#define MyAppURL "https://github.com/"
77
#define MyAppExeName "ThreadPilot.exe"
8-
#define MyAppVersion "1.4.2"
8+
#define MyAppVersion "1.4.3"
99

1010
#ifndef MyWizardStyle
1111
#define MyWizardStyle "modern dynamic windows11"

‎Installer/ThreadPilot.wxs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Package
88
Name="ThreadPilot"
99
Manufacturer="Prime Build"
10-
Version="1.4.2.0"
10+
Version="1.4.3.0"
1111
UpgradeCode="PUT-GENERATED-UPGRADE-CODE-HERE"
1212
Language="1033">
1313
<SummaryInformation Description="ThreadPilot MSI template" />

‎Installer/setup.iss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#endif
1212

1313
#ifndef MyAppVersion
14-
#define MyAppVersion "1.4.2"
14+
#define MyAppVersion "1.4.3"
1515
#endif
1616

1717
#ifndef MyAppSourceDir

‎Services/PowerPlanService.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class PowerPlanService : IPowerPlanService
1616
private static readonly Lazy<string> powerPlansPath = new(GetPowerPlansPath);
1717
private static readonly string powerCfgExecutablePath = Path.Combine(Environment.SystemDirectory, "powercfg.exe");
1818
private static readonly TimeSpan powerCfgTimeout = TimeSpan.FromSeconds(20);
19-
private static readonly Regex powerSchemeRegex = new(@"Power Scheme GUID: (.*?) \((.*?)\)", RegexOptions.Multiline | RegexOptions.Compiled);
19+
private static readonly Regex powerSchemeRegex = new(@"^Power Scheme GUID: (.*?) \((.*)\)(?:\s+\*)?$", RegexOptions.Multiline | RegexOptions.Compiled);
2020
private static readonly Regex pathTraversalRegex = new(@"(^|[\\/])\.\.([\\/]|$)", RegexOptions.Compiled);
2121

2222
private static string PowerPlansPath => powerPlansPath.Value;
@@ -517,6 +517,12 @@ private bool TryNormalizePowerPlanPath(string filePath, out string normalizedPat
517517
}
518518

519519
var fileInfo = new FileInfo(normalizedPath);
520+
if (fileInfo.Length == 0)
521+
{
522+
error = "Power plan file is empty.";
523+
return false;
524+
}
525+
520526
if (fileInfo.Length > 10 * 1024 * 1024)
521527
{
522528
error = "Power plan file size exceeds 10 MB limit.";
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
namespace ThreadPilot.Core.Tests
2+
{
3+
using System.Security.Cryptography;
4+
using System.Text;
5+
using Microsoft.Extensions.Logging.Abstractions;
6+
using Moq;
7+
using ThreadPilot.Services;
8+
using ThreadPilot.Services.Abstractions;
9+
10+
public sealed class BundledPowerPlanAssetTests
11+
{
12+
private static readonly string[] NewPlanFiles =
13+
[
14+
"0 Synez_Public_Power.pow",
15+
"arsenza low latency (INTEL FIX THREAD-DIRECTOR).pow",
16+
"arsenza low latency.pow",
17+
"AutoOS.pow",
18+
"BEYOND-PERFORMANCE-AMD+INTEL.pow",
19+
"Bitsum Highest Performance.pow",
20+
"cactusOS.pow",
21+
"FPSHEAVEN2026.pow",
22+
"GALA's ultimate performance(AMD).pow",
23+
"Gavot Performance.pow",
24+
"GTweaks Power Plan V3.pow",
25+
"imribiy2026.pow",
26+
"IrisFixed.pow",
27+
"J o k r O S P o w e r P l a n.pow",
28+
"Jackpot2026.pow",
29+
"Kizzimo's Extreme Low Latency.pow",
30+
"KSOS11.pow",
31+
"melody LowestLatency.pow",
32+
"Microsoft High performance.pow",
33+
"Microsoft Ultimate Performance.pow",
34+
"Mitstas IDLE ENABLED.pow",
35+
"n1kobg GPU_Booster_Power_Plan.pow",
36+
"Prodazin Power Plan.pow",
37+
"Reticle v2.pow",
38+
"RevisionPowerPlanV2.8.pow",
39+
"RIP Tweaks Power Plan.pow",
40+
"Rosca Tweaks v2.pow",
41+
"Velo's Power Plan.pow",
42+
"VTRL Optimized.pow",
43+
"XNRL Pro Plan.pow",
44+
];
45+
46+
[Fact]
47+
public void BundledPlans_AreValidUniqueRegistryHives()
48+
{
49+
var directory = GetPowerPlansDirectory();
50+
var files = Directory.GetFiles(directory, "*", SearchOption.TopDirectoryOnly);
51+
52+
Assert.All(files, file => Assert.Equal(".pow", Path.GetExtension(file), ignoreCase: true));
53+
Assert.Equal(files.Length, files.Select(Path.GetFileNameWithoutExtension).Distinct(StringComparer.OrdinalIgnoreCase).Count());
54+
55+
foreach (var file in files)
56+
{
57+
var info = new FileInfo(file);
58+
Assert.InRange(info.Length, 4, 10 * 1024 * 1024);
59+
Assert.Equal("regf", Encoding.ASCII.GetString(File.ReadAllBytes(file), 0, 4));
60+
Assert.DoesNotContain(Path.GetFileName(file), character => Path.GetInvalidFileNameChars().Contains(character));
61+
Assert.DoesNotContain("#U", Path.GetFileName(file), StringComparison.OrdinalIgnoreCase);
62+
}
63+
}
64+
65+
[Fact]
66+
public async Task NewAndExistingPlans_ArePresentDiscoverableAndNotBinaryDuplicates()
67+
{
68+
var directory = GetPowerPlansDirectory();
69+
var files = Directory.GetFiles(directory, "*.pow", SearchOption.TopDirectoryOnly);
70+
var newPaths = NewPlanFiles.Select(file => Path.Combine(directory, file)).ToArray();
71+
72+
Assert.All(newPaths, path => Assert.True(File.Exists(path), $"Missing bundled power plan: {Path.GetFileName(path)}"));
73+
Assert.All(["Amit.pow", "Beyond.pow", "L1 Final Version.pow"], file => Assert.True(File.Exists(Path.Combine(directory, file))));
74+
75+
var newHashes = newPaths.ToDictionary(path => path, GetSha256);
76+
Assert.Equal(newHashes.Count, newHashes.Values.Distinct(StringComparer.Ordinal).Count());
77+
Assert.All(
78+
newHashes,
79+
entry => Assert.DoesNotContain(files, file => !newPaths.Contains(file, StringComparer.OrdinalIgnoreCase) && GetSha256(file) == entry.Value));
80+
81+
var logger = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
82+
var runner = new Mock<IProcessRunner>(MockBehavior.Strict);
83+
var service = new PowerPlanService(
84+
NullLogger<PowerPlanService>.Instance,
85+
logger.Object,
86+
runner.Object,
87+
() => directory);
88+
89+
var discovered = await service.GetCustomPowerPlansAsync();
90+
Assert.All(NewPlanFiles, file => Assert.Contains(discovered, plan => plan.Name == Path.GetFileNameWithoutExtension(file)));
91+
Assert.Equal(files.Length, discovered.Count);
92+
}
93+
94+
[Fact]
95+
public void Project_ConfiguresAllPowerPlansForBuildAndPublish()
96+
{
97+
var project = File.ReadAllText(Path.Combine(FindRepositoryRoot(), "ThreadPilot.csproj"));
98+
99+
Assert.Contains(@"assets\Powerplans\**\*.pow", project, StringComparison.Ordinal);
100+
Assert.Contains(@"<TargetPath>Powerplans\%(RecursiveDir)%(Filename)%(Extension)</TargetPath>", project, StringComparison.Ordinal);
101+
Assert.Contains("<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>", project, StringComparison.Ordinal);
102+
Assert.Contains("<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>", project, StringComparison.Ordinal);
103+
}
104+
105+
private static string GetPowerPlansDirectory() =>
106+
Path.Combine(FindRepositoryRoot(), "assets", "Powerplans");
107+
108+
private static string GetSha256(string path) =>
109+
Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(path)));
110+
111+
private static string FindRepositoryRoot()
112+
{
113+
var directory = new DirectoryInfo(AppContext.BaseDirectory);
114+
while (directory != null)
115+
{
116+
if (File.Exists(Path.Combine(directory.FullName, "ThreadPilot.csproj")))
117+
{
118+
return directory.FullName;
119+
}
120+
121+
directory = directory.Parent;
122+
}
123+
124+
throw new InvalidOperationException("Repository root could not be located.");
125+
}
126+
}
127+
}

‎Tests/ThreadPilot.Core.Tests/PackagingMetadataTests.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace ThreadPilot.Core.Tests
44

55
public sealed partial class PackagingMetadataTests
66
{
7-
private const string ReleaseVersion = "1.4.2";
8-
private const string ReleaseAssemblyVersion = "1.4.2.0";
7+
private const string ReleaseVersion = "1.4.3";
8+
private const string ReleaseAssemblyVersion = "1.4.3.0";
99

1010
[Fact]
1111
public void InnoInstallers_UseStableDisplayNameAndSeparateVersionMetadata()
@@ -100,7 +100,7 @@ private static string FindRepositoryRoot()
100100
throw new InvalidOperationException("Repository root could not be located.");
101101
}
102102

103-
[GeneratedRegex("#define MyAppVersion \"1\\.4\\.2\"", RegexOptions.CultureInvariant)]
103+
[GeneratedRegex("#define MyAppVersion \"1\\.4\\.3\"", RegexOptions.CultureInvariant)]
104104
private static partial Regex MyAppVersionRegex();
105105
}
106106
}

‎Tests/ThreadPilot.Core.Tests/PowerPlanServiceSecurityTests.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@ public async Task ImportCustomPowerPlan_ReturnsFalse_ForInvalidExtension()
4040
}
4141
}
4242

43+
[Fact]
44+
public async Task ImportCustomPowerPlan_ReturnsFalse_ForEmptyFile()
45+
{
46+
var service = CreateService();
47+
var filePath = Path.Combine(Path.GetTempPath(), $"threadpilot-empty-{Guid.NewGuid():N}.pow");
48+
await File.WriteAllBytesAsync(filePath, []);
49+
50+
try
51+
{
52+
Assert.False(await service.ImportCustomPowerPlan(filePath));
53+
}
54+
finally
55+
{
56+
File.Delete(filePath);
57+
}
58+
}
59+
60+
[Fact]
61+
public async Task ImportCustomPowerPlan_ReturnsFalse_ForMissingFile()
62+
{
63+
var service = CreateService();
64+
var filePath = Path.Combine(Path.GetTempPath(), $"threadpilot-missing-{Guid.NewGuid():N}.pow");
65+
66+
Assert.False(await service.ImportCustomPowerPlan(filePath));
67+
}
68+
4369
[Theory]
4470
[InlineData("")]
4571
[InlineData("invalid-guid")]

‎Tests/ThreadPilot.Core.Tests/PowerPlanServiceTests.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ public async Task GetActivePowerPlan_ParsesPowerCfgOutput()
3131
Assert.True(result.IsActive);
3232
}
3333

34+
[Fact]
35+
public async Task GetActivePowerPlan_PreservesParenthesesInDisplayName()
36+
{
37+
const string guid = "381b4222-f694-41f0-9685-ff5bb260df2e";
38+
var runner = new RecordingProcessRunner
39+
{
40+
ResultFactory = _ => new ProcessRunResult(
41+
0,
42+
$"Power Scheme GUID: {guid} (Ultimate Performance (AMD)) *",
43+
string.Empty),
44+
};
45+
var service = CreateService(runner);
46+
47+
var result = await service.GetActivePowerPlan();
48+
49+
Assert.NotNull(result);
50+
Assert.Equal("Ultimate Performance (AMD)", result.Name);
51+
}
52+
3453
[Fact]
3554
public async Task SetActivePowerPlanByGuidAsync_SkipsChange_WhenAlreadyActive()
3655
{

‎ThreadPilot.csproj‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
<TrimMode>link</TrimMode>
1717
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1818
<NoWarn>CS1998;CS0067;CS0414;WFAC010;IL3000;MVVMTK0034</NoWarn>
19-
<Version>1.4.2</Version>
20-
<AssemblyVersion>1.4.2.0</AssemblyVersion>
21-
<FileVersion>1.4.2.0</FileVersion>
22-
<InformationalVersion>1.4.2</InformationalVersion>
19+
<Version>1.4.3</Version>
20+
<AssemblyVersion>1.4.3.0</AssemblyVersion>
21+
<FileVersion>1.4.3.0</FileVersion>
22+
<InformationalVersion>1.4.3</InformationalVersion>
2323
</PropertyGroup>
2424

2525
<ItemGroup>

‎app.manifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3-
<assemblyIdentity version="1.4.2.0" name="ThreadPilot.app"/>
3+
<assemblyIdentity version="1.4.3.0" name="ThreadPilot.app"/>
44
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
55
<security>
66
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

0 commit comments

Comments
 (0)