Skip to content

Commit

Permalink
fix #92
Browse files Browse the repository at this point in the history
  • Loading branch information
wgh136 committed Dec 18, 2024
1 parent eb1abfc commit ea973a2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
10 changes: 8 additions & 2 deletions assets/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "首頁",
Expand Down Expand Up @@ -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" : "未找到有效的漫畫"
}
}
5 changes: 4 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> importMethods = [
"Single Comic".tl,
"Multiple Comics".tl,
"A cbz file".tl,
"Multiple cbz files".tl,
"EhViewer downloads".tl
];

Expand Down Expand Up @@ -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) {
Expand Down
27 changes: 27 additions & 0 deletions lib/utils/import_comic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ class ImportComic {
return registerComics(imported, false);
}

Future<bool> multipleCbz() async {
var picker = DirectoryPicker();
var dir = await picker.pickDirectory();
if (dir != null) {
var files = (await dir.list().toList()).whereType<File>().toList();
files.removeWhere((e) => e.extension != 'cbz' && e.extension != 'zip');
Map<String?, List<LocalComic>> imported = {};
var controller = showLoadingDialog(App.rootContext, allowCancel: false);
var comics = <LocalComic>[];
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<bool> ehViewer() async {
var dbFile = await selectFile(ext: ['db']);
final picker = DirectoryPicker();
Expand Down
1 change: 1 addition & 0 deletions lib/utils/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ea973a2

Please sign in to comment.