forked from SteamGridDB/steamgriddb-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBnetHelper.ps1
41 lines (33 loc) · 1.23 KB
/
BnetHelper.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
param (
[Parameter(Mandatory=$True)][string]$bnet, # Path to the Battle.net executable
[Parameter(Mandatory=$True)][string]$launchid # Battle.net launch id to launch
)
Write-Host 'Starting Battle.net'
Start-Process $bnet
# Wait to be sure log file gets created (just to be safe, usually gets created instantly)
Start-Sleep -Seconds 3
# Get latest log file
$log = Get-ChildItem -Path "$env:LOCALAPPDATA\Battle.net\Logs" -Filter "battle.net-*.log" | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$bnetStarted = $False
Write-Host 'Waiting for Battle.net to start completely'
# Get current system date
$currentDate = Get-Date
Do {
# Check log file until we find this string
$launchedCompletely = Select-String -path $log -pattern 'GameController initialization complete'
If (!($launchedCompletely)) {
# Timeout after 1 minute
If ($currentDate.AddMinutes(1) -lt (Get-Date))
{
Write-Host 'Could not find successful launch'
exit
}
Start-Sleep -Seconds 1
} Else {
Write-Host 'Bnet started!'
$bnetStarted = $True
}
} Until ($bnetStarted)
# Launch
Write-Host "Starting game ($launchid)"
Start-Process $bnet "--exec=`"launch $launchid`""