$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)
}
# Trim a string down to a specified amount of characters
if ($NewName.Length -gt 15) {
$NewName = $NewName.Substring(0, 15);
}
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^name "(.+)"' -Replacement "name ""$NewName""" -FilePath "$InstallDir\config\config.cfg"
Write-ReplaceContentInFile -Regex '^newname \[.+\]' -Replacement "name ""$NewName""" -FilePath "$InstallDir\config\config.cfg"
$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)
}
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^scr_w (.+)' -Replacement "scr_w $($Display.Width)" -FilePath "$InstallDir\config\init.cfg"
Write-ReplaceContentInFile -Regex '^scr_h (.+)' -Replacement "scr_h $($Display.Height)" -FilePath "$InstallDir\config\init.cfg"