Skip to content

Commit f8a688d

Browse files
committed
Fix case-sensitivity of Save-/OpenFileDialog under Mono
also improved caching of gen'd strings, and marked lambdas as `static`
1 parent 3726cc6 commit f8a688d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/BizHawk.Client.Common/FilesystemFilter.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace BizHawk.Client.Common
99
{
1010
public sealed class FilesystemFilter
1111
{
12+
private string? _ser = null;
13+
1214
public readonly string Description;
1315

1416
public readonly IReadOnlyCollection<string> Extensions;
@@ -45,7 +47,7 @@ public FilesystemFilter(
4547

4648
/// <summary>delegated to <see cref="SerializeEntry"/></summary>
4749
/// <remarks>return value is a valid <c>Filter</c> for <c>Save-</c>/<c>OpenFileDialog</c></remarks>
48-
public override string ToString() => SerializeEntry(Description, Extensions);
50+
public override string ToString() => _ser ??= SerializeEntry(Description, Extensions);
4951

5052
public const string AllFilesEntry = "All Files|*";
5153

@@ -68,7 +70,12 @@ public FilesystemFilter(
6870
public static readonly FilesystemFilter TextFiles = new FilesystemFilter("Text Files", new[] { "txt" });
6971

7072
/// <remarks>return value is a valid <c>Filter</c> for <c>Save-</c>/<c>OpenFileDialog</c></remarks>
71-
public static string SerializeEntry(string desc, IEnumerable<string> exts)
72-
=> string.Format("{0} ({1})|{1}", desc, string.Join(";", exts.Select(ext => $"*.{ext}")));
73+
public static string SerializeEntry(string desc, IReadOnlyCollection<string> exts)
74+
{
75+
var joinedLower = string.Join(";", exts.Select(static ext => $"*.{ext}"));
76+
return OSTailoredCode.IsUnixHost
77+
? $"{desc} ({joinedLower})|{string.Join(";", exts.Select(static ext => $"*.{ext};*.{ext.ToUpperInvariant()}"))}"
78+
: $"{desc} ({joinedLower})|{joinedLower}";
79+
}
7380
}
7481
}

src/BizHawk.Client.Common/FilesystemFilterSet.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace BizHawk.Client.Common
77
{
88
public sealed class FilesystemFilterSet
99
{
10+
private string? _allSer = null;
11+
1012
public readonly IReadOnlyCollection<FilesystemFilter> Filters;
1113

1214
public FilesystemFilterSet(params FilesystemFilter[] filters)
@@ -24,7 +26,10 @@ public string ToString(bool addAllFilesEntry) => addAllFilesEntry
2426

2527
/// <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>
2628
public string ToString(string combinedEntryDesc, bool addAllFilesEntry = true)
27-
=> $"{FilesystemFilter.SerializeEntry(combinedEntryDesc, Filters.SelectMany(filter => filter.Extensions).Distinct().OrderBy(s => s))}|{ToString(addAllFilesEntry)}";
29+
{
30+
_allSer ??= FilesystemFilter.SerializeEntry(combinedEntryDesc, Filters.SelectMany(static filter => filter.Extensions).Distinct().OrderBy(static s => s).ToList());
31+
return $"{_allSer}|{ToString(addAllFilesEntry)}";
32+
}
2833

2934
public static readonly FilesystemFilterSet Screenshots = new FilesystemFilterSet(FilesystemFilter.PNGs, new FilesystemFilter(".bmp Files", new[] { "bmp" }));
3035
}

0 commit comments

Comments
 (0)