Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Services/PowerPlanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PowerPlanService : IPowerPlanService
private static readonly Lazy<string> powerPlansPath = new(GetPowerPlansPath);
private static readonly string powerCfgExecutablePath = Path.Combine(Environment.SystemDirectory, "powercfg.exe");
private static readonly TimeSpan powerCfgTimeout = TimeSpan.FromSeconds(20);
private static readonly Regex powerSchemeRegex = new(@"^Power Scheme GUID:\s*([0-9a-fA-F-]+)[ \t]+\((.*)\)[ \t]*(\*)?[ \t]*\r?$", RegexOptions.Multiline | RegexOptions.Compiled);
private static readonly Regex powerSchemeRegex = new(@"^.*?\b([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})[ \t]+\((.*)\)[ \t]*(\*)?[ \t]*\r?$", RegexOptions.Multiline | RegexOptions.Compiled);
private static readonly Regex pathTraversalRegex = new(@"(^|[\\/])\.\.([\\/]|$)", RegexOptions.Compiled);

private static string PowerPlansPath => powerPlansPath.Value;
Expand Down
22 changes: 22 additions & 0 deletions Tests/ThreadPilot.Core.Tests/PowerPlanServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ public async Task GetPowerPlansAsync_ParsesActiveMarkerWithOnePowerCfgCall()
Assert.Equal(new[] { "/list" }, Assert.Single(runner.Invocations).Arguments);
}

[Fact]
public async Task GetPowerPlansAsync_ParsesLocalizedOutput()
{
const string activeGuid = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c";
var runner = new RecordingProcessRunner
{
ResultFactory = _ => new ProcessRunResult(
0,
"Modes de gestion de l’alimentation existants (* Actif)\n" +
"GUID du mode de gestion de l’alimentation : 381b4222-f694-41f0-9685-ff5bb260df2e (Utilisation normale)\n" +
$"GUID du mode de gestion de l’alimentation : {activeGuid} (Haute performance) *",
string.Empty),
};
var service = CreateService(runner);

var plans = await service.GetPowerPlansAsync();

Assert.Equal(2, plans.Count);
Assert.Equal("Haute performance", plans.Single(plan => plan.Guid == activeGuid).Name);
Assert.True(plans.Single(plan => plan.Guid == activeGuid).IsActive);
}

[Fact]
public async Task SetActivePowerPlanByGuidAsync_SkipsChange_WhenAlreadyActive()
{
Expand Down
Loading