Fix in alignment errors
This commit is contained in:
+17
-7
@@ -196,12 +196,12 @@ Add-Type -Namespace Native -Name Power -MemberDefinition @'
|
||||
public static extern uint SetThreadExecutionState(uint esFlags);
|
||||
'@
|
||||
|
||||
$ES_CONTINUOUS = 0x80000000
|
||||
$ES_SYSTEM_REQUIRED = 0x00000001
|
||||
$ES_DISPLAY_REQUIRED = 0x00000002
|
||||
$ES_CONTINUOUS = [Convert]::ToUInt32('80000000', 16)
|
||||
$ES_SYSTEM_REQUIRED = [Convert]::ToUInt32('00000001', 16)
|
||||
$ES_DISPLAY_REQUIRED = [Convert]::ToUInt32('00000002', 16)
|
||||
|
||||
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 {
|
||||
@@ -283,6 +283,19 @@ function Get-BatteryInfo {
|
||||
|
||||
#region Main
|
||||
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) {
|
||||
Set-PowerSettingsForBatteryTest
|
||||
} else {
|
||||
@@ -295,9 +308,6 @@ try {
|
||||
Write-Host "Starting synthetic CPU load targeting ~$TargetLoadPercent% across $cores logical processors..." -ForegroundColor Cyan
|
||||
$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
|
||||
|
||||
Write-Host "Logging battery status every $SampleIntervalSeconds s to $LogPath" -ForegroundColor Cyan
|
||||
|
||||
Reference in New Issue
Block a user