Fix case-sensitivity of `Save-`/`OpenFileDialog` under Mono
also improved caching of gen'd strings, and marked lambdas as `static`
This commit is contained in:
parent
3726cc6291
commit
f8a688d47f
src/BizHawk.Client.Common
|
@ -9,6 +9,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class FilesystemFilter
|
||||
{
|
||||
private string? _ser = null;
|
||||
|
||||
public readonly string Description;
|
||||
|
||||
public readonly IReadOnlyCollection<string> Extensions;
|
||||
|
@ -45,7 +47,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
/// <summary>delegated to <see cref="SerializeEntry"/></summary>
|
||||
/// <remarks>return value is a valid <c>Filter</c> for <c>Save-</c>/<c>OpenFileDialog</c></remarks>
|
||||
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" });
|
||||
|
||||
/// <remarks>return value is a valid <c>Filter</c> for <c>Save-</c>/<c>OpenFileDialog</c></remarks>
|
||||
public static string SerializeEntry(string desc, IEnumerable<string> exts)
|
||||
=> string.Format("{0} ({1})|{1}", desc, string.Join(";", exts.Select(ext => $"*.{ext}")));
|
||||
public static string SerializeEntry(string desc, IReadOnlyCollection<string> 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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed class FilesystemFilterSet
|
||||
{
|
||||
private string? _allSer = null;
|
||||
|
||||
public readonly IReadOnlyCollection<FilesystemFilter> Filters;
|
||||
|
||||
public FilesystemFilterSet(params FilesystemFilter[] filters)
|
||||
|
@ -24,7 +26,10 @@ namespace BizHawk.Client.Common
|
|||
|
||||
/// <remarks>call other overload (omit <paramref name="combinedEntryDesc"/>) to not prepend combined entry, return value is a valid <c>Filter</c> for <c>Save-</c>/<c>OpenFileDialog</c></remarks>
|
||||
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" }));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue