Skip to content

Instantly share code, notes, and snippets.

@CaiB
Created February 13, 2025 15:19
Show Gist options
  • Save CaiB/016aacd937d72fe057d851c16ccb5fae to your computer and use it in GitHub Desktop.
Save CaiB/016aacd937d72fe057d851c16ccb5fae to your computer and use it in GitHub Desktop.
Vintage Story Language File Comparer
using namespace System.Management.Automation;
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, Position = 0)] [string] $ReferenceFile,
[Parameter(Mandatory = $true, Position = 1)] [string] $CompareFile
);
$ErrorActionPreference = 'Stop';
[Regex] $FormatRegex = '\{p?(\d+)[^\}]*\}';
[string] $RefFileName = Split-Path -Leaf $ReferenceFile;
[string] $ComFileName = Split-Path -Leaf $CompareFile;
[OrderedHashtable] $ContentRef = Get-Content $ReferenceFile -Raw | ConvertFrom-Json -AsHashtable;
[OrderedHashtable] $ContentCom = Get-Content $CompareFile -Raw | ConvertFrom-Json -AsHashtable;
Write-Host "Searching for keys in '$RefFileName' but not in '$ComFileName'...";
$ContentRef.GetEnumerator() | ForEach-Object `
{
if (!($ContentCom.ContainsKey($_.Key))) { " -> In '$RefFileName' but not in '$ComFileName': key `"$($_.Key)`""; }
}
Write-Host "Searching for keys in '$ComFileName' but not in '$RefFileName'...";
$ContentCom.GetEnumerator() | ForEach-Object `
{
if (!($ContentRef.ContainsKey($_.Key))) { " -> In '$ComFileName' but not in '$RefFileName': key `"$($_.Key)`""; }
}
Write-Host 'Searching for mismatched tags...';
$ContentCom.GetEnumerator() | ForEach-Object `
{
if ($ContentRef.ContainsKey($_.Key))
{
$HereItems = $FormatRegex.Matches($_.Value) | ForEach-Object {$_.Groups[1].Value} | Sort-Object;
$RefItems = $FormatRegex.Matches($ContentRef[$_.Key]) | ForEach-Object {$_.Groups[1].Value} | Sort-Object;
if (($HereItems.Length -NE 0 -AND $RefItems.Length -NE 0) -AND (Compare-Object -ReferenceObject $RefItems -DifferenceObject $HereItems))
{
Write-Host " -> $($HereItems.Count) tags found in '$ComFileName' vs $($RefItems.Count) in '$RefFileName' for key `"$($_.Key)`"";
}
}
}
Write-Host 'Done! :)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment