From f8a688d47f7d3067ef6cfa97602c72388561069e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 10 Mar 2022 14:29:25 +1000 Subject: [PATCH] Fix case-sensitivity of `Save-`/`OpenFileDialog` under Mono also improved caching of gen'd strings, and marked lambdas as `static` --- src/BizHawk.Client.Common/FilesystemFilter.cs | 13 ++++++++++--- src/BizHawk.Client.Common/FilesystemFilterSet.cs | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.Common/FilesystemFilter.cs b/src/BizHawk.Client.Common/FilesystemFilter.cs index 7f7fc30ff0..dd005b9a7c 100644 --- a/src/BizHawk.Client.Common/FilesystemFilter.cs +++ b/src/BizHawk.Client.Common/FilesystemFilter.cs @@ -9,6 +9,8 @@ namespace BizHawk.Client.Common { public sealed class FilesystemFilter { + private string? _ser = null; + public readonly string Description; public readonly IReadOnlyCollection Extensions; @@ -45,7 +47,7 @@ namespace BizHawk.Client.Common /// delegated to /// return value is a valid Filter for Save-/OpenFileDialog - public override string ToString() => SerializeEntry(Description, Extensions); + public override string ToString() => _ser ??= SerializeEntry(Description, Extensions); public const string AllFilesEntry = "All Files|*"; @@ -68,7 +70,12 @@ namespace BizHawk.Client.Common public static readonly FilesystemFilter TextFiles = new FilesystemFilter("Text Files", new[] { "txt" }); /// return value is a valid Filter for Save-/OpenFileDialog - public static string SerializeEntry(string desc, IEnumerable exts) - => string.Format("{0} ({1})|{1}", desc, string.Join(";", exts.Select(ext => $"*.{ext}"))); + public static string SerializeEntry(string desc, IReadOnlyCollection exts) + { + var joinedLower = string.Join(";", exts.Select(static ext => $"*.{ext}")); + return OSTailoredCode.IsUnixHost + ? $"{desc} ({joinedLower})|{string.Join(";", exts.Select(static ext => $"*.{ext};*.{ext.ToUpperInvariant()}"))}" + : $"{desc} ({joinedLower})|{joinedLower}"; + } } } diff --git a/src/BizHawk.Client.Common/FilesystemFilterSet.cs b/src/BizHawk.Client.Common/FilesystemFilterSet.cs index 1cc436bbba..9437d40f13 100644 --- a/src/BizHawk.Client.Common/FilesystemFilterSet.cs +++ b/src/BizHawk.Client.Common/FilesystemFilterSet.cs @@ -7,6 +7,8 @@ namespace BizHawk.Client.Common { public sealed class FilesystemFilterSet { + private string? _allSer = null; + public readonly IReadOnlyCollection Filters; public FilesystemFilterSet(params FilesystemFilter[] filters) @@ -24,7 +26,10 @@ namespace BizHawk.Client.Common /// call other overload (omit ) to not prepend combined entry, return value is a valid Filter for Save-/OpenFileDialog public string ToString(string combinedEntryDesc, bool addAllFilesEntry = true) - => $"{FilesystemFilter.SerializeEntry(combinedEntryDesc, Filters.SelectMany(filter => filter.Extensions).Distinct().OrderBy(s => s))}|{ToString(addAllFilesEntry)}"; + { + _allSer ??= FilesystemFilter.SerializeEntry(combinedEntryDesc, Filters.SelectMany(static filter => filter.Extensions).Distinct().OrderBy(static s => s).ToList()); + return $"{_allSer}|{ToString(addAllFilesEntry)}"; + } public static readonly FilesystemFilterSet Screenshots = new FilesystemFilterSet(FilesystemFilter.PNGs, new FilesystemFilter(".bmp Files", new[] { "bmp" })); }