154 lines
6.3 KiB
PowerShell
154 lines
6.3 KiB
PowerShell
param (
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$operator,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]$screenshot,
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
[string[]]$conditions,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[string[]]$instanceIP
|
|
)
|
|
|
|
if(-not $instanceIP){$instanceIP = "10.0.211.121"}
|
|
|
|
$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()
|
|
}
|
|
}
|
|
|
|
function Fetch-ScreenShot(){
|
|
adb connect $instanceIP *>$null
|
|
adb -s $instanceIP exec-out screencap -p > $global:LDPlayerPath\screenshot.png *>$null
|
|
|
|
& "C:\Program Files\Tesseract-OCR\tesseract.exe" "$global:LDPlayerPath\screenshot.png" "$global:LDPlayerPath\tesseract" -l eng tsv *>$null
|
|
}
|
|
|
|
function Get-ScreenshotData($text) {
|
|
|
|
|
|
|
|
$tsvFile = "$global:LDPlayerPath\tesseract.tsv"
|
|
|
|
$wordCoords = Get-Content $tsvFile | ConvertFrom-Csv -Delimiter "`t"
|
|
$wordCoords | Where-Object ($_.level -eq 5) | Select-Object text, left, top, width, height
|
|
|
|
|
|
$Data = $wordCoords | ForEach-Object {
|
|
$x1 =[int]$_._left
|
|
$y1 =[int]$_.top
|
|
$width = [int]$_.width
|
|
$height = [int]$_.height
|
|
|
|
$midX =[math]::Round($x1+$width/2)
|
|
$midY =[math]::Round($y1+$height/2)
|
|
|
|
[PSCustomObject]@{
|
|
Text = $_.text
|
|
Coords = "$midX $midY"
|
|
}
|
|
}
|
|
$Element = $Data | Where-Object {$_.Text -and $_.Text.ToLower() -eq $text}
|
|
|
|
$coordsForText=$Element.Coords
|
|
return $coordsForText
|
|
}
|
|
|
|
& "$global:LDPlayerPath\test.ps1 -instanceIP ${instanceIP}"
|
|
$xml = (get-content -path C:\LDPlayer\LDPlayer9\screen.xml)
|
|
|
|
if (-not $conditions) { return $false }
|
|
|
|
if (-not $screenshot){
|
|
logger("usando xml")
|
|
$allConditions = $conditions
|
|
switch ($operator) {
|
|
"OR" {
|
|
logger("OR operator selected to find any of these: $allConditions")
|
|
foreach ($condition in $allConditions) { if ($xml | select-string $condition) { logger("$condition found");return $true } }
|
|
logger("$condition not found");return $false
|
|
}
|
|
"AND" {
|
|
logger("AND operator selected to find all of these: $allConditions")
|
|
foreach ($condition in $allConditions) { if (-not (($xml | select-string $condition))) { logger("$condition not found");return $false } }
|
|
logger("$condition found");return $true
|
|
}
|
|
"NAND" {
|
|
logger("NAND operator selected to return true if any one of these are NOT present: $allConditions")
|
|
foreach ($condition in $allConditions) { if (-not ($xml | select-string $condition)) { logger("at least $condition is not present, so returning TRUE since NAND operator was specified");return $true }}
|
|
logger("All conditions are present, so returning false since NAND operator was specified");return $false
|
|
}
|
|
"NOR" {
|
|
logger("NOR operator selected to return TRUE only when all of the conditions are present: $allConditions")
|
|
foreach($condition in $allConditions){
|
|
if($xml | Select-String $condition) {
|
|
logger("$condition is present so returning false since all have to be absent");return $false}
|
|
}
|
|
logger("None of the conditions are present so returning TRUE (since neither this NOR that condition was present");return $true
|
|
}
|
|
}
|
|
} else {
|
|
logger("screnshot Data being observed (not xml)")
|
|
Fetch-ScreenShot
|
|
|
|
if (-not $conditions) { return $false }
|
|
|
|
$allConditions = $conditions
|
|
switch ($operator) {
|
|
"OR" {
|
|
logger("OR operator selected to find any of these: $allConditions")
|
|
|
|
foreach ($condition in $allConditions) {
|
|
$coords=""
|
|
$coords=Get-ScreenshotData($condition)
|
|
if ($coords) { logger("$condition found");return $true } }
|
|
logger("$condition not found");return $false
|
|
}
|
|
"AND" {
|
|
logger("AND operator selected to find all of these: $allConditions")
|
|
foreach ($condition in $allConditions) {
|
|
$coords=Get-ScreenshotData($condition)
|
|
if (-not $coords) { logger("$condition not found");return $false } }
|
|
logger("$condition found");return $true
|
|
}
|
|
"NAND" {
|
|
logger("NAND operator selected to return true if any one of these are NOT present: $allConditions")
|
|
foreach ($condition in $allConditions) {
|
|
$coords=Get-ScreenshotData($condition)
|
|
if (-not $coords) { logger("at least $condition is not present, so returning TRUE since NAND operator was specified");return $true }}
|
|
logger("All conditions are present, so returning false since NAND operator was specified");return $false
|
|
}
|
|
"NOR" {
|
|
logger("NOR operator selected to return TRUE only when all of the conditions are present: $allConditions")
|
|
foreach($condition in $allConditions){
|
|
$coords=Get-ScreenshotData($condition)
|
|
if($coords) {
|
|
logger("$condition is present so returning false since all have to be absent");return $false}
|
|
}
|
|
logger("None of the conditions are present so returning TRUE (since neither this NOR that condition was present");return $true
|
|
}
|
|
}
|
|
} |