$NewName = $args[0]
$InstallDir = $PSScriptRoot
function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
$content = (Get-Content $FilePath) -replace $Regex, $Replacement
[IO.File]::WriteAllLines($FilePath, $content)
}
Write-ReplaceContentInFile -Regex '^NAME=(.+)' -Replacement "NAME=$NewName" -FilePath "$InstallDir\TH2_OPT.CFG"
$InstallDir = $PSScriptRoot
Add-Type -AssemblyName System.Windows.Forms
$Display = [System.Windows.Forms.Screen]::AllScreens | Where-Object Primary | Select Bounds
function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
$content = (Get-Content $FilePath) -replace $Regex, $Replacement
[IO.File]::WriteAllLines($FilePath, $content)
}
function Get-43Resolution([int]$Width, [int]$Height) {
$ratio = 4 / 3
if (($Width -gt $Height) -or ($Width -eq $Height)) {
return @{ Width = [math]::Round($ratio * $Height); Height = $Height }
}
if ($Width -lt $Height) {
return @{ Width = $Width; Height = [math]::Round($Width / $ratio) }
}
}
# Accessible via $Resolution.Height, $Resolution.Width
$Resolution = Get-43Resolution -Width $Display.Width -Height $Display.Height
Write-ReplaceContentInFile -Regex '^DATAPATH=(.+)' -Replacement "DATAPATH=$InstallDir" -FilePath "$InstallDir\TH2_OPT.CFG"
Write-ReplaceContentInFile -Regex '^MUSPATH=(.+)' -Replacement "MUSPATH=$InstallDir\Music" -FilePath "$InstallDir\TH2_OPT.CFG"
Write-ReplaceContentInFile -Regex '^MOVPATH=(.+)' -Replacement "MOVPATH=$InstallDir\Movies" -FilePath "$InstallDir\TH2_OPT.CFG"
Write-ReplaceContentInFile -Regex 'h:(\d+), v:(\d+)' -Replacement "h:$($Resolution.Width), v:$($Resolution.Height)" -FilePath "$InstallDir\dgVoodoo.conf"