fix: support compressed archives and advanced character encoding

Signed-off-by: The one with the braid <info@braid.business>
This commit is contained in:
The one with the braid 2024-07-11 11:52:22 +02:00
parent 6e34b5220c
commit 0863580b23
4 changed files with 70 additions and 33 deletions

View file

@ -12,7 +12,12 @@ abstract class FileMatcher {
}) {
final localized = matchLocale(files: files, name: 'logo', extension: 'png');
if (localized.isEmpty) return null;
final scaled = matchScale(files: localized, name: 'logo', extension: 'png', scale: scale);
final scaled = matchScale(
files: localized,
name: 'logo',
extension: 'png',
scale: scale,
);
final file = files.singleWhere((element) => element == scaled);
return file;
}
@ -23,17 +28,28 @@ abstract class FileMatcher {
required String name,
required String extension,
}) {
files.sort();
files.sort((a, b) {
final aLocalized = a.startsWith(RegExp('^[a-z]+(-[a-z]+)?\\.lproj\\/'));
final bLocalized = b.startsWith(RegExp('^[a-z]+(-[a-z]+)?\\.lproj\\/'));
if (aLocalized && bLocalized) {
return a.compareTo(b);
} else if (aLocalized) {
return -1;
} else {
return 1;
}
});
files = files.reversed.toList();
List<RegExp> expressions = <RegExp>[];
// adding the fallbacks
// - match just *any* language
// - match only unlocalized
// - match the five mostly spoken languages of the world, copied from Wikipedia
// - match just *any* language
expressions.addAll(
[
RegExp(
'^([a-z]+(-[a-z]+)?\\.lproj\\/)?$name(@\\d+x)?\\.$extension\$',
'^[a-z]+(-[a-z]+)?\\.lproj\\/$name(@\\d+x)?\\.$extension\$',
unicode: true,
caseSensitive: false,
),
@ -44,6 +60,11 @@ abstract class FileMatcher {
caseSensitive: false,
),
),
RegExp(
'^$name(@\\d+x)?\\.$extension\$',
unicode: true,
caseSensitive: false,
),
],
);