diff --git a/lib/utils/io.dart b/lib/utils/io.dart index dc6df55..d5ec62b 100644 --- a/lib/utils/io.dart +++ b/lib/utils/io.dart @@ -35,19 +35,9 @@ class FilePath { } extension FileSystemEntityExt on FileSystemEntity { + /// Get the base name of the file or directory. String get name { - var path = this.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); + return p.basename(path); } Future deleteIgnoreError({bool recursive = false}) async { @@ -83,6 +73,10 @@ extension FileExtension on File { // Stream is not usable since [AndroidFile] does not support [openRead]. await newFile.writeAsBytes(await readAsBytes()); } + + String get basenameWithoutExt { + return p.basenameWithoutExtension(path); + } } extension DirectoryExtension on Directory { diff --git a/lib/utils/pdf.dart b/lib/utils/pdf.dart index 9ce0493..48da584 100644 --- a/lib/utils/pdf.dart +++ b/lib/utils/pdf.dart @@ -30,14 +30,14 @@ Future _createPdfFromComic({ files.removeWhere( (element) => element is! File || element.path.startsWith('cover')); files.sort((a, b) { - var aName = (a as File).name; - var bName = (b as File).name; + var aName = (a as File).basenameWithoutExt; + var bName = (b as File).basenameWithoutExt; var aNumber = int.tryParse(aName); var bNumber = int.tryParse(bName); if (aNumber != null && bNumber != null) { return aNumber.compareTo(bNumber); } - return aName.compareTo(bName); + return a.name.compareTo(b.name); }); }