-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindGamePath.ps1
38 lines (37 loc) · 1.83 KB
/
FindGamePath.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
function findGamePath {
$steamPath = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Valve\Steam').steamPath
$lines = Get-Content "$steamPath\steamapps\libraryfolders.vdf"
$newLines = New-Object -TypeName 'System.Collections.Generic.List[string]' -ArgumentList $lines.Count
$newLines.Add("{") | Out-Null
foreach ($line in $lines) {
$matchCollection = [regex]::Matches($line, '\s*(\".*?\")')
if ($matchCollection.Count -eq 2) {
$line = $line.Replace($matchCollection[0].Groups[1].Value, ("{0}:" -f $matchCollection[0].Groups[1].Value))
$secondVal = $matchCollection[1].Groups[1].Value.Clone()
[int64]$tryLongVal = 0
if ([int64]::TryParse($secondVal.Replace('"', ''), [ref] $tryLongVal)) {
$secondVal = $secondVal.Replace('"', '')
}
$newLines.Add($line.Replace($matchCollection[1].Groups[1].Value, ("{0}," -f $secondVal))) | Out-Null
} elseif ($matchCollection.Count -eq 1) {
$newLines.Add($line.Replace($matchCollection[0].Groups[1].Value, ("{0}:" -f $matchCollection[0].Groups[1].Value))) | Out-Null
} else {
$newLines.Add($line) | Out-Null
}
}
$newLines.Add("}") | Out-Null
$joinedLine = $newLines -join "`n"
$joinedLine = [regex]::Replace($joinedLine, '\}(\s*\n\s*\")', '},$1', "Multiline")
$joinedLine = [regex]::Replace($joinedLine, '\"\,(\n\s*\})', '"$1', "Multiline")
$joinedLine = $joinedLine -replace ',(\s*[\]}])', '$1'
$libaryfolders = ($joinedLine | ConvertFrom-Json)
for ($i = 0; $true; $i++) {
$gamePath = "$($libaryfolders.libraryfolders.$i.path)\steamapps\common\Get To The Orange Door\"
if (!(Test-Path $gamePath)) {
break
}
if (Test-Path $gamePath) {
return $gamePath.Replace("\", "/")
}
}
}