$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 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() } } while($true) { if(Test-Path "C:\Ldplayer\Ldplayer9\launchNow.txt"){ $shouldLaunch = cat C:\Ldplayer\Ldplayer9\launchNow.txt rm C:\Ldplayer\Ldplayer9\launchNow.txt $out = cmd /c "$shouldLaunch" logger("Received and ran launch command $shouldLaunch") logger("$out") } if(Test-Path "C:\Ldplayer\Ldplayer9\launchName.txt"){ $shouldLaunchName = cat C:\Ldplayer\Ldplayer9\launchName.txt rm C:\Ldplayer\Ldplayer9\launchName.txt $out = cmd /c "$shouldLaunchName" logger("Received and ran launch command $shouldLaunchName") logger("$out") #$shouldLaunchName | Out-File -FilePath "C:\Ldplayer\Ldplayer9\runningName.txt" } if(Test-Path "C:\Ldplayer\Ldplayer9\CloseNow.txt") { $shouldClose = cat C:\Ldplayer\Ldplayer9\CloseNow.txt rm C:\Ldplayer\Ldplayer9\CloseNow.txt cmd /c "$shouldClose" logger("Closed $shouldClose") } if(Test-Path "C:\Ldplayer\Ldplayer9\restartADB.txt") { $restartADB = cat C:\Ldplayer\Ldplayer9\restartADB.txt rm C:\Ldplayer\Ldplayer9\restartADB.txt tskill adb *> $null Start-Sleep -Milliseconds 1000 adb connect $restartADB *> $null logger("Closed $restartADB") } if(Test-Path "C:\Ldplayer\Ldplayer9\CloseName.txt") { $shouldCloseName = cat C:\Ldplayer\Ldplayer9\CloseName.txt $instanceName=$shouldCloseName.Split(' ')[-1] start-sleep -seconds 30 rm C:\Ldplayer\Ldplayer9\CloseName.txt cmd /c "$shouldCloseName" logger("Closed $shouldCloseName") $instanceList = Get-Content -Path "$global:LDPlayerPath\instanceList.txt" foreach ( $inst in $instanceList) { $filename = "C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config" $instanceData = (cat C:\Ldplayer\LDplayer9\vms\config\leidian${inst}.config) $convertedData = $instanceData | ConvertFrom-Json $name = $convertedData."statusSettings.playerName" if ($instanceName -eq $name){ $count = $inst $c=$instanceData if($instanceData -match 'networkSettings\.networkAddress\s+10\.0\.211\.125'){ $newData = $instanceData -replace 'networkSettings\.networkAddress\s+10\.0\.211\.125', 'networkSettings\.networkAddress\s+10\.0\.211\.121' Set-Content -Path $filename -Value $filename -Value $newData -Encoding UTF8 } break } } #rm C:\Ldplayer\Ldplayer9\runningName.txt } start-sleep -Milliseconds 500 }