Battlefield 1942

From LANCommander
Revision as of 00:49, 27 July 2023 by DoctorDalek (talk | contribs) (Created page with "Category:Games {{InfoBox.Game |Cover = cover.jpg |Developers = {{InfoBox.Game.Developer|Digital Illusions CE}} |Publishers = {{InfoBox.Game.Publisher|Electronic Arts}} {{InfoBox.Game.Publisher|Aspyr Media}} |Release Date = {{InfoBox.Game.ReleaseDate|Windows|September 10, 2002}} |Genres = {{InfoBox.Game.Genre|Shooter}} | PCGamingWiki = Battlefield_1942 }} == Name Change Script == A template profile is copied from the base game directory and some files have to be modi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:InfoBox.Game

Name Change Script

A template profile is copied from the base game directory and some files have to be modified to set the primary selected profile.

$NewName = $args[0]
$InstallDir = $PSScriptRoot
$OldName = ""
if ($args[1]) {
	$OldName = $args[1]
}

function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
    $content = (Get-Content $FilePath) -replace $Regex, $Replacement
    [IO.File]::WriteAllLines($FilePath, $content)
}

# Clear out any existing profile with the same name
Remove-Item "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Recurse -ErrorAction Ignore

if ($OldName -ne "") {
    if (Test-Path -Path "$InstallDir\Mods\bf1942\Settings\Profiles\$OldName") {
        # Profile exists with old name
        Move-Item -Path "$InstallDir\Mods\bf1942\Settings\Profiles\$OldName" -Destination "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Force
    } else {
        # Old profile doesn't exist, scaffold a new one
        Copy-Item -Path "$InstallDir\ProfileTemplate" -Destination "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Recurse
    }
} else {
    # New install, scaffold new profile
    Copy-Item -Path "$InstallDir\ProfileTemplate" -Destination "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName" -Recurse
}

Write-ReplaceContentInFile -Regex 'rem \*\* (.+) \*\*' -Replacement "rem ** $NewName **" -FilePath "$InstallDir\Mods\bf1942\Settings\Profile.con"
Write-ReplaceContentInFile -Regex 'game.setProfile "(.+)"' -Replacement "game.setProfile ""$NewName""" -FilePath "$InstallDir\Mods\bf1942\Settings\Profile.con"

Write-ReplaceContentInFile -Regex 'game.setPlayerName "(.+)"' -Replacement "game.setPlayerName ""$NewName""" -FilePath "$InstallDir\Mods\bf1942\Settings\Profiles\$NewName\GeneralOptions.con"