Game/ReplayReactionArchive.cs

Internal static helper that reads a trusted legacy JSON archive of replay reactions from reactions/legacy.json and returns stored ReplayReactionRequests.Entry arrays by replay key. It caches the deserialized archive in a private static field.

File Access
using System;
using System.Collections.Generic;
using System.Text.Json;
using Sandbox;

namespace BlockParty;

/// <summary>Trusted export of the old service. New player-owned database records take precedence.</summary>
internal static class ReplayReactionArchive
{
	private sealed class Archive
	{
		public int Version { get; set; }
		public Dictionary<string, ReplayReactionRequests.Entry[]> Replays { get; set; }
	}
	private static Archive _archive;
	internal static IReadOnlyList<ReplayReactionRequests.Entry> Read( string replay )
	{
		if ( _archive is null )
		{
			var archive = JsonSerializer.Deserialize<Archive>( FileSystem.Mounted.ReadAllText( "reactions/legacy.json" ) );
			if ( archive?.Version != 1 || archive.Replays is null ) throw new InvalidOperationException( "Invalid reaction archive." );
			_archive = archive;
		}
		return _archive.Replays.TryGetValue( replay, out var entries ) ? entries : Array.Empty<ReplayReactionRequests.Entry>();
	}
}