#nullable enable
using T3.Core.Compilation;
using T3.Core.Logging;
namespace T3.Core.Model;
///
/// Tracks the file format version for .t3 and .t3ui symbol files.
/// Written into each file so older editors can detect and warn about newer formats.
///
public static class SymbolFormatVersion
{
/// Current format version written by this editor.
public const int Current = 3;
/// The TiXL editor version string, written alongside the format version.
public static string TixlVersion => RuntimeAssemblies.Version.ToString();
///
/// Change log for this editor's own migrations (used when reading older formats).
///
public static readonly FormatChange[] Changes =
[
new(1, "4.2.0.1", "Added per-symbol ProjectSettings with PlaybackConfig; RenderExport in .t3ui Settings section"),
new(2, "4.2.0.2","Keyframe interpolation format"),
new(3, "4.2.0.2","Sections (renamed from annotations) with explicit membership"),
];
public sealed record FormatChange(int FormatVersion, string EditorVersion, string Description);
///
/// Checks a file's format version and logs a warning if it was written by a newer editor.
/// The older editor can't know what changed — it just reports the version mismatch.
///
public static void WarnIfNewer(int fileVersion, string? fileTixlVersion, string symbolName)
{
if (fileVersion <= Current)
return;
var savedWith = !string.IsNullOrEmpty(fileTixlVersion)
? $" (saved with TiXL {fileTixlVersion})"
: "";
Log.Warning($"'{symbolName}': file format version {fileVersion}{savedWith} is newer than supported version {Current} (TiXL {TixlVersion}). Opening this file may cause data loss.");
}
}