Files
adbAutomation/ifPlus.ps1
2025-12-02 18:18:14 +00:00

62 lines
2.3 KiB
PowerShell

param (
[Parameter(Mandatory=$true)]
[string]$operator,
[Parameter(Mandatory=$true)]
[string[]]$conditions
)
$global:LDPlayerPath ="C:\Ldplayer\LDplayer9"
function logger($logMessage) {
[int]$number = (get-content -path "$global:LDPlayerPath\index_count.txt")
if($number -gt 21){ $number=0}
$instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt"
$instanceNumber = $instanceList[$number]
$instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${instanceNumber}.config)
$convertedData = $instanceData | ConvertFrom-Json
$name = $convertedData."statusSettings.playerName"
$count = $number+1
$scriptName = Split-Path -Leaf $PSCommandPath
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
$timestampedLogMessage = $timestamp + "-$name, ($count/22)-$scriptName-PID: ${PID}-:" + $logMessage
$logFilePath = "$global:LDPlayerPath\LDAutoLog.txt"
$fs = New-Object System.IO.FileStream($logFilePath, [System.IO.FileMode]::Append, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Read)
$sw = New-Object System.IO.StreamWriter($fs)
try {
$sw.WriteLine($timestampedLogMessage)
} finally {
$sw.Close()
$fs.Close()
}
}
$xml = (get-content -path C:\LDPlayer\LDPlayer9\screen.xml)
if (-not $conditions) { return $false }
$allConditions = $conditions
switch ($operator) {
"OR" {
foreach ($condition in $allConditions) { if ($xml | select-string $condition) {
$textInfo = (Get-Culture).TextInfo
$titleCaseString = $textInfo.ToTitleCase($condition)
$conditionMet = $titleCaseString -replace '\s', ''
return $conditionMet
} }
return
}
"AND" {
foreach ($condition in $allConditions) { if (-not (($xml | select-string $condition))) { return } }
$textInfo = (Get-Culture).TextInfo
$titleCaseString = $textInfo.ToTitleCase($allConditions[0])
$conditionMet = $titleCaseString -replace '\s', ''
return $conditionMet
}
"NOT" {
foreach ($condition in $allConditions) { if (-not (($xml | select-string $condition))) {return $true }}
return $false
}
}