diff --git a/src/BizHawk.Client.EmuHawk/AVOut/IVideoWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/IVideoWriter.cs index 9d964fd082..4ffc212977 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/IVideoWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/IVideoWriter.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using BizHawk.Client.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk @@ -101,38 +102,24 @@ namespace BizHawk.Client.EmuHawk } [AttributeUsage(AttributeTargets.Class)] - public sealed class VideoWriterAttribute : Attribute + public sealed class VideoWriterAttribute(string shortName, string name, string description) : Attribute { - public string ShortName { get; } - public string Name { get; } - public string Description { get; } - - public VideoWriterAttribute(string shortName, string name, string description) - { - ShortName = shortName; - Name = name; - Description = description; - } + public string ShortName { get; } = shortName; + public string Name { get; } = name; + public string Description { get; } = description; } - public class VideoWriterInfo + public class VideoWriterInfo(VideoWriterAttribute attribs, Type type) { - private static readonly Type[] CTOR_TYPES_A = { typeof(IDialogParent) }; + private static readonly Type[] CTOR_TYPES_A = [ typeof(IDialogParent) ]; - public VideoWriterAttribute Attribs { get; } - private readonly Type _type; - - public VideoWriterInfo(VideoWriterAttribute attribs, Type type) - { - _type = type; - Attribs = attribs; - } + public VideoWriterAttribute Attribs { get; } = attribs; /// parent for if the user is shown config dialog public IVideoWriter Create(IDialogParent dialogParent) => (IVideoWriter) ( - _type.GetConstructor(CTOR_TYPES_A) - ?.Invoke(new object[] { dialogParent }) - ?? Activator.CreateInstance(_type)); + type.GetConstructor(CTOR_TYPES_A) + ?.Invoke([ dialogParent ]) + ?? Activator.CreateInstance(type)); public override string ToString() => Attribs.Name; } @@ -142,11 +129,12 @@ namespace BizHawk.Client.EmuHawk /// public static class VideoWriterInventory { - private static readonly Dictionary VideoWriters = new Dictionary(); + private static readonly Dictionary VideoWriters = [ ]; + private static readonly VideoWriterInfo[] VideoWritersOrdered; static VideoWriterInventory() { - foreach (var t in EmuHawk.ReflectionCache.Types) + foreach (var t in ReflectionCache.Types) { if (!t.IsInterface && typeof(IVideoWriter).IsAssignableFrom(t) @@ -157,9 +145,24 @@ namespace BizHawk.Client.EmuHawk VideoWriters.Add(a.ShortName, new VideoWriterInfo(a, t)); } } + + // we want to keep the FFmpeg writer as the first item + var ffmpegShortName = typeof(FFmpegWriter) + .GetCustomAttributes(typeof(VideoWriterAttribute), false) + .Cast() + .First() + .ShortName; + + var videoWriters = VideoWriters.Values.ToList(); + var ffmpegWriter = videoWriters.Find(vwi => vwi.Attribs.ShortName == ffmpegShortName); + videoWriters.Remove(ffmpegWriter); + VideoWritersOrdered = videoWriters + .OrderBy(vwi => vwi.Attribs.Name) + .Prepend(ffmpegWriter) + .ToArray(); } - public static IEnumerable GetAllWriters() => VideoWriters.Values; + public static IEnumerable GetAllWriters() => VideoWritersOrdered; /// /// find an IVideoWriter by its short name