$InstallDir = $PSScriptRoot
# Accessible via $Display.Width and $Display.Height
Add-Type -AssemblyName System.Windows.Forms
$Display = ([System.Windows.Forms.Screen]::AllScreens | Where-Object Primary).Bounds
function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
$content = (Get-Content $FilePath) -replace $Regex, $Replacement
[IO.File]::WriteAllLines($FilePath, $content)
}
Copy-Item -Path "$InstallDir\ProfileTemplate" -Destination "$($env:USERPROFILE)\Documents\My Games\dhewm3" -Recurse
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^seta r_customHeight "(.+)"' -Replacement "seta r_customHeight ""$($Display.Height)""" -FilePath "$($env:USERPROFILE)\Documents\My Games\dhewm3\base\dhewm.cfg"
Write-ReplaceContentInFile -Regex '^seta r_customWidth "(.+)"' -Replacement "seta r_customWidth ""$($Display.Width)""" -FilePath "$($env:USERPROFILE)\Documents\My Games\dhewm3\base\dhewm.cfg"
Write-ReplaceContentInFile -Regex '^seta r_customHeight "(.+)"' -Replacement "seta r_customHeight ""$($Display.Height)""" -FilePath "$($env:USERPROFILE)\Documents\My Games\dhewm3\d3xp\dhewm.cfg"
Write-ReplaceContentInFile -Regex '^seta r_customWidth "(.+)"' -Replacement "seta r_customWidth ""$($Display.Width)""" -FilePath "$($env:USERPROFILE)\Documents\My Games\dhewm3\d3xp\dhewm.cfg"
$InstallDir = $PSScriptRoot
$NewName = $args[0]
function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
$content = (Get-Content $FilePath) -replace $Regex, $Replacement
[IO.File]::WriteAllLines($FilePath, $content)
}
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^seta ui_name "(.+)"' -Replacement "seta ui_name ""$NewName""" -FilePath "$($env:USERPROFILE)\Documents\My Games\dhewm3\base\dhewm.cfg"
Write-ReplaceContentInFile -Regex '^seta ui_name "(.+)"' -Replacement "seta ui_name ""$NewName""" -FilePath "$($env:USERPROFILE)\Documents\My Games\dhewm3\d3xp\dhewm.cfg"