From 1ae33c43b1cfc132b8fbef4cb3bb7146826081f9 Mon Sep 17 00:00:00 2001 From: nyne Date: Thu, 26 Dec 2024 10:32:15 +0800 Subject: [PATCH] fix #115 --- lib/utils/import_comic.dart | 2 +- lib/utils/io.dart | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/utils/import_comic.dart b/lib/utils/import_comic.dart index 05ac47a..6904fcc 100644 --- a/lib/utils/import_comic.dart +++ b/lib/utils/import_comic.dart @@ -39,7 +39,7 @@ class ImportComic { Future multipleCbz() async { var picker = DirectoryPicker(); - var dir = await picker.pickDirectory(); + var dir = await picker.pickDirectory(directAccess: true); if (dir != null) { var files = (await dir.list().toList()).whereType().toList(); files.removeWhere((e) => e.extension != 'cbz' && e.extension != 'zip'); diff --git a/lib/utils/io.dart b/lib/utils/io.dart index 307e6a5..79020d4 100644 --- a/lib/utils/io.dart +++ b/lib/utils/io.dart @@ -197,7 +197,7 @@ class DirectoryPicker { static const _methodChannel = MethodChannel("venera/method_channel"); - Future pickDirectory() async { + Future pickDirectory({bool directAccess = false}) async { IO._isSelectingFiles = true; try { String? directory; @@ -205,6 +205,16 @@ class DirectoryPicker { directory = await file_selector.getDirectoryPath(); } else if (App.isAndroid) { directory = (await AndroidDirectory.pickDirectory())?.path; + if (directory != null && directAccess) { + // Native library does not have access to the directory. Copy it to cache. + var cache = FilePath.join(App.cachePath, "selected_directory"); + if (Directory(cache).existsSync()) { + Directory(cache).deleteSync(recursive: true); + } + Directory(cache).createSync(); + await copyDirectoryIsolate(Directory(directory), Directory(cache)); + directory = cache; + } } else { // ios, macos directory =