65 lines
2.7 KiB
PowerShell
65 lines
2.7 KiB
PowerShell
param (
|
|
[string]$instanceName
|
|
)
|
|
|
|
$global:LDPlayerPath ="C:\Ldplayer\LDplayer9"
|
|
$global:instanceNameglobal=$instanceName
|
|
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
|
|
foreach ( $inst in $instanceList) {
|
|
$instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config)
|
|
$convertedData = $instanceData | ConvertFrom-Json
|
|
$name = $convertedData."statusSettings.playerName"
|
|
if ($global:instanceNameglobal -eq $name){
|
|
$count = $inst
|
|
break
|
|
}
|
|
}
|
|
#if(-not $instanceName){$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 + "${global:instanceNameglobal} -instanceID: ${count} -${scriptName} -PID: ${PID}-:" + $logMessage
|
|
#$timestampedLogMessage
|
|
$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()
|
|
}
|
|
}
|
|
|
|
[int]$cnt=0
|
|
while($true){
|
|
if($cnt -gt 100) {break}
|
|
#if(($cnt%15 -eq 0) -and ($cnt -ne 0)) { logger("$cnt iterations passed starting ld instance again..."); rm "C:\Ldplayer\Ldplayer9\runningName.txt"; & $global:LDPlayerPath\startLDPlayerByName.ps1 -instanceName $instanceName}
|
|
|
|
if($cnt -lt 2){logger("Waiting for adb device to appear")}
|
|
|
|
$adbResponse = (adb connect 10.0.211.125) 2>null
|
|
$adbResponse
|
|
$instanceIP = "10.0.211.125"
|
|
if($adbResponse -like "*connected to 10.0.211.125:5555*"){
|
|
logger("adb connected successfuly to 10.0.211.125 at iteration $cnt")
|
|
$isOnline = adb devices 2> $null
|
|
$pattern = [regex]::Escape($instanceIP) + ':\d+\s+device'
|
|
if($isOnline -match $pattern){
|
|
break
|
|
|
|
} else { return $true}
|
|
}
|
|
$instanceIP | Out-File -FilePath "C:\Ldplayer\Ldplayer9\restartADB.txt"
|
|
$cnt+=1
|
|
start-sleep -milliseconds 1000
|
|
}
|
|
|