From 389403c11dffd94af8fe9a4dbf8ac7b57b436d57 Mon Sep 17 00:00:00 2001 From: pkuislm <69719051+pkuislm@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:48:15 +0800 Subject: [PATCH] Ignore files starting with a dot when fetching local comic images, and improve local comic delete logic. --- lib/foundation/local.dart | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/foundation/local.dart b/lib/foundation/local.dart index 8876b84..cc2fde8 100644 --- a/lib/foundation/local.dart +++ b/lib/foundation/local.dart @@ -5,6 +5,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:sqlite3/sqlite3.dart'; import 'package:venera/foundation/comic_source/comic_source.dart'; import 'package:venera/foundation/comic_type.dart'; +import 'package:venera/foundation/favorites.dart'; import 'package:venera/foundation/log.dart'; import 'package:venera/network/download.dart'; import 'package:venera/pages/reader/reader.dart'; @@ -346,6 +347,10 @@ class LocalManager with ChangeNotifier { comic.cover) { continue; } + //Hidden file in some file system + if(entity.name.startsWith('.')) { + continue; + } files.add(entity); } } @@ -439,9 +444,20 @@ class LocalManager with ChangeNotifier { downloadingTasks.first.resume(); } - void deleteComic(LocalComic c) { - var dir = Directory(FilePath.join(path, c.directory)); - dir.deleteIgnoreError(recursive: true); + void deleteComic(LocalComic c, [bool removeFileOnDisk = true]) { + if(removeFileOnDisk) { + var dir = Directory(FilePath.join(path, c.directory)); + dir.deleteIgnoreError(recursive: true); + } + //Deleting a local comic means that it's nolonger available, thus both favorite and history should be deleted. + if(HistoryManager().findSync(c.id, c.comicType) != null) { + HistoryManager().remove(c.id, c.comicType); + } + assert(c.comicType == ComicType.local); + var folders = LocalFavoritesManager().find(c.id, c.comicType); + for (var f in folders) { + LocalFavoritesManager().deleteComicWithId(f, c.id, c.comicType); + } remove(c.id, c.comicType); notifyListeners(); }