From 263d0e603620eebdf70665fc242eee446e8a07aa Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 12 Nov 2023 12:39:32 +0100 Subject: [PATCH] Fix #82 Tranga crashes when cover is missing from imageCache. Retrying download of cover and copy --- Tranga/MangaConnectors/MangaConnector.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index 4b1b3fb..037a938 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -150,7 +150,8 @@ public abstract class MangaConnector : GlobalBase /// Copies the already downloaded cover from cache to downloadLocation /// /// Publication to retrieve Cover for - public void CopyCoverFromCacheToDownloadLocation(Manga manga) + /// Number of times to retry to copy the cover (or download it first) + public void CopyCoverFromCacheToDownloadLocation(Manga manga, int? retries = 1) { Log($"Copy cover {manga}"); //Check if Publication already has a Folder and cover @@ -163,6 +164,18 @@ public abstract class MangaConnector : GlobalBase } string fileInCache = Path.Join(settings.coverImageCache, manga.coverFileNameInCache); + if (!File.Exists(fileInCache)) + { + Log($"Cloníng cover failed: File missing {fileInCache}."); + if (retries > 0 && manga.coverUrl is not null) + { + Log($"Trying {retries} more times"); + SaveCoverImageToCache(manga.coverUrl, 0); + CopyCoverFromCacheToDownloadLocation(manga, --retries); + } + + return; + } string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" ); Log($"Cloning cover {fileInCache} -> {newFilePath}"); File.Copy(fileInCache, newFilePath, true);