diff --git a/assets/translation.json b/assets/translation.json index bd5a745..61cb8bc 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -255,7 +255,10 @@ "Click favorite": "点击收藏", "End": "末尾", "None": "无", - "View Detail": "查看详情" + "View Detail": "查看详情", + "Select a directory which contains multiple cbz/zip files." : "选择一个包含多个cbz/zip文件的目录", + "Multiple cbz files" : "多个cbz文件", + "No valid comics found" : "未找到有效的漫画" }, "zh_TW": { "Home": "首頁", @@ -513,6 +516,9 @@ "Click favorite": "點擊收藏", "End": "末尾", "None": "無", - "View Detail": "查看詳情" + "View Detail": "查看詳情", + "Select a directory which contains multiple cbz/zip files." : "選擇一個包含多個cbz/zip文件的目錄", + "Multiple cbz files" : "多個cbz文件", + "No valid comics found" : "未找到有效的漫畫" } } \ No newline at end of file diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index d75d89f..e6cf73b 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -495,12 +495,14 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> { "Select a directory which contains the comic files.".tl, "Select a directory which contains the comic directories.".tl, "Select a cbz/zip file.".tl, + "Select a directory which contains multiple cbz/zip files.".tl, "Select an EhViewer database and a download folder.".tl ][type]; List importMethods = [ "Single Comic".tl, "Multiple Comics".tl, "A cbz file".tl, + "Multiple cbz files".tl, "EhViewer downloads".tl ]; @@ -628,7 +630,8 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> { 0 => await importer.directory(true), 1 => await importer.directory(false), 2 => await importer.cbz(), - 3 => await importer.ehViewer(), + 3 => await importer.multipleCbz(), + 4 => await importer.ehViewer(), int() => true, }; if(result) { diff --git a/lib/utils/import_comic.dart b/lib/utils/import_comic.dart index d2db6ff..05ac47a 100644 --- a/lib/utils/import_comic.dart +++ b/lib/utils/import_comic.dart @@ -37,6 +37,33 @@ class ImportComic { return registerComics(imported, false); } + Future multipleCbz() async { + var picker = DirectoryPicker(); + var dir = await picker.pickDirectory(); + if (dir != null) { + var files = (await dir.list().toList()).whereType().toList(); + files.removeWhere((e) => e.extension != 'cbz' && e.extension != 'zip'); + Map> imported = {}; + var controller = showLoadingDialog(App.rootContext, allowCancel: false); + var comics = []; + for (var file in files) { + try { + var comic = await CBZ.import(file); + comics.add(comic); + } catch (e, s) { + Log.error("Import Comic", e.toString(), s); + } + } + if (comics.isEmpty) { + App.rootContext.showMessage(message: "No valid comics found".tl); + } + imported[selectedFolder] = comics; + controller.close(); + return registerComics(imported, false); + } + return false; + } + Future ehViewer() async { var dbFile = await selectFile(ext: ['db']); final picker = DirectoryPicker(); diff --git a/lib/utils/io.dart b/lib/utils/io.dart index b577eeb..307e6a5 100644 --- a/lib/utils/io.dart +++ b/lib/utils/io.dart @@ -72,6 +72,7 @@ extension FileSystemEntityExt on FileSystemEntity { } extension FileExtension on File { + /// Get the file extension, not including the dot. String get extension => path.split('.').last; /// Copy the file to the specified path using memory.