Fix invalid image order when exporting comic as pdf.

This commit is contained in:
2025-02-08 19:37:04 +08:00
parent f0b1135eb7
commit ce50812857
2 changed files with 9 additions and 15 deletions

View File

@@ -35,19 +35,9 @@ class FilePath {
} }
extension FileSystemEntityExt on FileSystemEntity { extension FileSystemEntityExt on FileSystemEntity {
/// Get the base name of the file or directory.
String get name { String get name {
var path = this.path; return p.basename(path);
if (path.endsWith('/') || path.endsWith('\\')) {
path = path.substring(0, path.length - 1);
}
int i = path.length - 1;
while (i >= 0 && path[i] != '\\' && path[i] != '/') {
i--;
}
return path.substring(i + 1);
} }
Future<void> deleteIgnoreError({bool recursive = false}) async { Future<void> deleteIgnoreError({bool recursive = false}) async {
@@ -83,6 +73,10 @@ extension FileExtension on File {
// Stream is not usable since [AndroidFile] does not support [openRead]. // Stream is not usable since [AndroidFile] does not support [openRead].
await newFile.writeAsBytes(await readAsBytes()); await newFile.writeAsBytes(await readAsBytes());
} }
String get basenameWithoutExt {
return p.basenameWithoutExtension(path);
}
} }
extension DirectoryExtension on Directory { extension DirectoryExtension on Directory {

View File

@@ -30,14 +30,14 @@ Future<void> _createPdfFromComic({
files.removeWhere( files.removeWhere(
(element) => element is! File || element.path.startsWith('cover')); (element) => element is! File || element.path.startsWith('cover'));
files.sort((a, b) { files.sort((a, b) {
var aName = (a as File).name; var aName = (a as File).basenameWithoutExt;
var bName = (b as File).name; var bName = (b as File).basenameWithoutExt;
var aNumber = int.tryParse(aName); var aNumber = int.tryParse(aName);
var bNumber = int.tryParse(bName); var bNumber = int.tryParse(bName);
if (aNumber != null && bNumber != null) { if (aNumber != null && bNumber != null) {
return aNumber.compareTo(bNumber); return aNumber.compareTo(bNumber);
} }
return aName.compareTo(bName); return a.name.compareTo(b.name);
}); });
} }