Fix in alignment errors

This commit is contained in:
2026-08-28 12:11:00 +03:00
parent 6b5d558fa2
commit 2ee5238944
3 changed files with 28 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"OriginalSchemeGuid": "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c",
"HibernateEnabled": false,
"SavedAt": "2026-08-28T12:08:21.4260829+03:00"
}
+17 -7
View File
@@ -196,12 +196,12 @@ Add-Type -Namespace Native -Name Power -MemberDefinition @'
public static extern uint SetThreadExecutionState(uint esFlags); public static extern uint SetThreadExecutionState(uint esFlags);
'@ '@
$ES_CONTINUOUS = 0x80000000 $ES_CONTINUOUS = [Convert]::ToUInt32('80000000', 16)
$ES_SYSTEM_REQUIRED = 0x00000001 $ES_SYSTEM_REQUIRED = [Convert]::ToUInt32('00000001', 16)
$ES_DISPLAY_REQUIRED = 0x00000002 $ES_DISPLAY_REQUIRED = [Convert]::ToUInt32('00000002', 16)
function Set-StayAwake { function Set-StayAwake {
[Native.Power]::SetThreadExecutionState($ES_CONTINUOUS -bor $ES_SYSTEM_REQUIRED -bor $ES_DISPLAY_REQUIRED) | Out-Null [Native.Power]::SetThreadExecutionState([uint32]($ES_CONTINUOUS -bor $ES_SYSTEM_REQUIRED -bor $ES_DISPLAY_REQUIRED)) | Out-Null
} }
function Clear-StayAwake { function Clear-StayAwake {
@@ -283,6 +283,19 @@ function Get-BatteryInfo {
#region Main #region Main
try { try {
# Validate/prepare the log path up front so a bad path fails fast, before power settings or
# the CPU load are touched. Falls back to the script folder if the requested location is invalid.
$logDir = Split-Path -Path $LogPath -Parent
if ($logDir -and -not (Test-Path -Path $logDir)) {
try {
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
} catch {
$fallbackPath = Join-Path -Path $PSScriptRoot -ChildPath (Split-Path -Path $LogPath -Leaf)
Write-Warning "Could not create log directory '$logDir' ($($_.Exception.Message)). Falling back to '$fallbackPath'."
$LogPath = $fallbackPath
}
}
if (-not $SkipPowerSettingsChanges) { if (-not $SkipPowerSettingsChanges) {
Set-PowerSettingsForBatteryTest Set-PowerSettingsForBatteryTest
} else { } else {
@@ -295,9 +308,6 @@ try {
Write-Host "Starting synthetic CPU load targeting ~$TargetLoadPercent% across $cores logical processors..." -ForegroundColor Cyan Write-Host "Starting synthetic CPU load targeting ~$TargetLoadPercent% across $cores logical processors..." -ForegroundColor Cyan
$loadJobs = Start-CpuLoad -Percent $TargetLoadPercent -Cores $cores $loadJobs = Start-CpuLoad -Percent $TargetLoadPercent -Cores $cores
if (-not (Test-Path (Split-Path -Path $LogPath -Parent))) {
New-Item -ItemType Directory -Path (Split-Path -Path $LogPath -Parent) -Force | Out-Null
}
"Timestamp,PercentRemaining,Status,Charging,EstimatedRunTimeMinutes" | Out-File -FilePath $LogPath -Encoding UTF8 "Timestamp,PercentRemaining,Status,Charging,EstimatedRunTimeMinutes" | Out-File -FilePath $LogPath -Encoding UTF8
Write-Host "Logging battery status every $SampleIntervalSeconds s to $LogPath" -ForegroundColor Cyan Write-Host "Logging battery status every $SampleIntervalSeconds s to $LogPath" -ForegroundColor Cyan
+6
View File
@@ -0,0 +1,6 @@
Timestamp,PercentRemaining,Status,Charging,EstimatedRunTimeMinutes
2026-08-28T12:08:25.6435909+03:00,78,Discharging,False,23
2026-08-28T12:08:55.6829249+03:00,77,Discharging,False,27
2026-08-28T12:09:25.7024303+03:00,75,Discharging,False,26
2026-08-28T12:09:55.7546137+03:00,74,Discharging,False,26
2026-08-28T12:10:25.7804244+03:00,72,Discharging,False,24
1 Timestamp PercentRemaining Status Charging EstimatedRunTimeMinutes
2 2026-08-28T12:08:25.6435909+03:00 78 Discharging False 23
3 2026-08-28T12:08:55.6829249+03:00 77 Discharging False 27
4 2026-08-28T12:09:25.7024303+03:00 75 Discharging False 26
5 2026-08-28T12:09:55.7546137+03:00 74 Discharging False 26
6 2026-08-28T12:10:25.7804244+03:00 72 Discharging False 24