86 lines
3.5 KiB
PowerShell
86 lines
3.5 KiB
PowerShell
$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
|
|
$out = cmd /c "$shouldLaunch"
|
|
logger("Received and ran launch command $shouldLaunch")
|
|
logger("$out")
|
|
rm C:\Ldplayer\Ldplayer9\launchNow.txt
|
|
}
|
|
if(Test-Path "C:\Ldplayer\Ldplayer9\launchName.txt"){
|
|
$shouldLaunchName = cat C:\Ldplayer\Ldplayer9\launchName.txt
|
|
$out = cmd /c "$shouldLaunchName"
|
|
logger("Received and ran launch command $shouldLaunchName")
|
|
logger("$out")
|
|
rm C:\Ldplayer\Ldplayer9\launchName.txt
|
|
}
|
|
if(Test-Path "C:\Ldplayer\Ldplayer9\CloseNow.txt") {
|
|
$shouldClose = cat C:\Ldplayer\Ldplayer9\CloseNow.txt
|
|
cmd /c "$shouldClose"
|
|
logger("Closed $shouldClose")
|
|
rm C:\Ldplayer\Ldplayer9\CloseNow.txt
|
|
}
|
|
if(Test-Path "C:\Ldplayer\Ldplayer9\CloseName.txt") {
|
|
$shouldCloseName = cat C:\Ldplayer\Ldplayer9\CloseName.txt
|
|
$instanceName=$shouldCloseName.Split(' ')[-1]
|
|
cmd /c "$shouldCloseName"
|
|
logger("Closed $shouldCloseName")
|
|
rm C:\Ldplayer\Ldplayer9\CloseName.txt
|
|
$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 (($newC=$c -replace '"networkSettings.networkAddress": "10.0.211.125",', '"networkSettings.networkAddress": "10.0.211.121",') -ne $c) {
|
|
$newC | Set-Content $filename
|
|
logger("changed IP back to 10.0.211.121 for $name")
|
|
logger(cat $filename | Select-String -Pattern "10.0.211.121")
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
start-sleep -Milliseconds 500
|
|
} |