#run ldplayer instance 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() } } #$instanceName $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" logger($instanceName) logger($name) if ($instanceName -eq $name){ $count = $inst $c=$instanceData if (($newC=$c -replace '"networkSettings.networkAddress": "10.0.211.121",', '"networkSettings.networkAddress": "10.0.211.125",') -ne $c) { $newC | Set-Content $filename logger("changed IP temporarily to 10.0.211.125") logger(cat $filename | Select-String -Patter "10.0.211.125") } $foundInstance = $true break } } if(-not $foundInstance){ logger("No LDPlayer instance with name: $instanceName") return $false} logger("starting instance $instanceName") #$cnt=0 #while($true) { # if(Test-Path "C:\Ldplayer\Ldplayer9\runningName.txt"){ # if($cnt%10 -eq 0){logger("Antoher reconnection in progress, waiting...")} # Start-Sleep -Seconds 2 # $cnt+=1 # continue # } else { $launchCMD = "ldconsole.exe launch --name $instanceName" $launchCMD | Out-File -FilePath "C:\Ldplayer\Ldplayer9\launchName.txt" # return # } #} <# $number=$number + 1 if($number -eq 23){ $number=0} $number | Out-File -FilePath "c:\ldplayer\ldplayer9\index_count.txt" #>