From daba940b456a76b82f3c59a63fa629496ec4faa5 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 22:38:23 +0200 Subject: [PATCH 01/12] Make cachePublications a dictionary with internalId as key. --- Tranga/GlobalBase.cs | 2 +- Tranga/Jobs/JobBoss.cs | 4 ++-- Tranga/MangaConnectors/Bato.cs | 2 +- Tranga/MangaConnectors/MangaDex.cs | 2 +- Tranga/MangaConnectors/MangaKatana.cs | 2 +- Tranga/MangaConnectors/MangaLife.cs | 2 +- Tranga/MangaConnectors/Manganato.cs | 2 +- Tranga/MangaConnectors/Mangasee.cs | 2 +- Tranga/MangaConnectors/Mangaworld.cs | 2 +- Tranga/Tranga.cs | 8 +++++--- 10 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Tranga/GlobalBase.cs b/Tranga/GlobalBase.cs index ce01a79..9258a6e 100644 --- a/Tranga/GlobalBase.cs +++ b/Tranga/GlobalBase.cs @@ -14,7 +14,7 @@ public abstract class GlobalBase protected TrangaSettings settings { get; init; } protected HashSet notificationConnectors { get; init; } protected HashSet libraryConnectors { get; init; } - protected List cachedPublications { get; init; } + protected Dictionary cachedPublications { get; init; } public static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.-]+(:[0-9]+)?"); diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 4380497..77cba2f 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -160,10 +160,10 @@ public class JobBoss : GlobalBase { this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job); if (job is DownloadNewChapters dncJob) - cachedPublications.Add(dncJob.manga); + cachedPublications.Add(dncJob.manga.internalId, dncJob.manga); } - HashSet coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet(); + HashSet coverFileNames = cachedPublications.Select(manga => manga.Value.coverFileNameInCache!).ToHashSet(); foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers { if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga))) diff --git a/Tranga/MangaConnectors/Bato.cs b/Tranga/MangaConnectors/Bato.cs index edc6dc9..58582e7 100644 --- a/Tranga/MangaConnectors/Bato.cs +++ b/Tranga/MangaConnectors/Bato.cs @@ -116,7 +116,7 @@ public class Bato : MangaConnector Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary(), year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga); + cachedPublications.Add(manga.internalId, manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index 550e34f..135261b 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -187,7 +187,7 @@ public class MangaDex : MangaConnector status, websiteUrl: $"https://mangadex.org/title/{publicationId}" ); - cachedPublications.Add(pub); + cachedPublications.Add(pub.internalId, pub); return pub; } diff --git a/Tranga/MangaConnectors/MangaKatana.cs b/Tranga/MangaConnectors/MangaKatana.cs index de59030..5996439 100644 --- a/Tranga/MangaConnectors/MangaKatana.cs +++ b/Tranga/MangaConnectors/MangaKatana.cs @@ -143,7 +143,7 @@ public class MangaKatana : MangaConnector Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga); + cachedPublications.Add(manga.internalId, manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaLife.cs b/Tranga/MangaConnectors/MangaLife.cs index 3f87953..d54454f 100644 --- a/Tranga/MangaConnectors/MangaLife.cs +++ b/Tranga/MangaConnectors/MangaLife.cs @@ -123,7 +123,7 @@ public class MangaLife : MangaConnector Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga); + cachedPublications.Add(manga.internalId, manga); return manga; } diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index f6ff4c1..437f1b9 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -133,7 +133,7 @@ public class Manganato : MangaConnector Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga); + cachedPublications.Add(manga.internalId, manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index f99e108..32053b6 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -179,7 +179,7 @@ public class Mangasee : MangaConnector Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga); + cachedPublications.Add(manga.internalId, manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangaworld.cs b/Tranga/MangaConnectors/Mangaworld.cs index 0f2e80d..fbea159 100644 --- a/Tranga/MangaConnectors/Mangaworld.cs +++ b/Tranga/MangaConnectors/Mangaworld.cs @@ -120,7 +120,7 @@ public class Mangaworld: MangaConnector Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga); + cachedPublications.Add(manga.internalId, manga); return manga; } diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index cd3b3bc..ca01d88 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -56,9 +56,11 @@ public partial class Tranga : GlobalBase public Manga? GetPublicationById(string internalId) { - if (cachedPublications.Exists(publication => publication.internalId == internalId)) - return cachedPublications.First(publication => publication.internalId == internalId); - return null; + return cachedPublications.TryGetValue(internalId, out Manga manga) switch + { + true => manga, + _ => null + }; } public bool TryGetPublicationById(string internalId, out Manga? manga) From 762da4c8598ff5978b3680f4d612ca3f09623fcd Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 22 Apr 2024 22:43:42 +0200 Subject: [PATCH 02/12] Make cachedPublications private with getter-setter --- Tranga/GlobalBase.cs | 25 ++++++++++++++++++++++++- Tranga/Jobs/JobBoss.cs | 4 ++-- Tranga/MangaConnectors/Bato.cs | 2 +- Tranga/MangaConnectors/MangaDex.cs | 2 +- Tranga/MangaConnectors/MangaKatana.cs | 2 +- Tranga/MangaConnectors/MangaLife.cs | 2 +- Tranga/MangaConnectors/Manganato.cs | 2 +- Tranga/MangaConnectors/Mangasee.cs | 2 +- Tranga/MangaConnectors/Mangaworld.cs | 2 +- Tranga/Tranga.cs | 9 +-------- 10 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Tranga/GlobalBase.cs b/Tranga/GlobalBase.cs index 9258a6e..f372f2c 100644 --- a/Tranga/GlobalBase.cs +++ b/Tranga/GlobalBase.cs @@ -14,7 +14,7 @@ public abstract class GlobalBase protected TrangaSettings settings { get; init; } protected HashSet notificationConnectors { get; init; } protected HashSet libraryConnectors { get; init; } - protected Dictionary cachedPublications { get; init; } + private Dictionary cachedPublications { get; init; } public static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.-]+(:[0-9]+)?"); @@ -36,6 +36,29 @@ public abstract class GlobalBase this.cachedPublications = new(); } + protected void AddMangaToCache(Manga manga) + { + if (!this.cachedPublications.TryAdd(manga.internalId, manga)) + { + Log($"Overwriting Manga {manga.internalId}"); + this.cachedPublications[manga.internalId] = manga; + } + } + + protected Manga? GetCachedManga(string internalId) + { + return cachedPublications.TryGetValue(internalId, out Manga manga) switch + { + true => manga, + _ => null + }; + } + + protected IEnumerable GetAllCachedManga() + { + return cachedPublications.Values; + } + protected void Log(string message) { logger?.WriteLine(this.GetType().Name, message); diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 77cba2f..75e01a6 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -160,10 +160,10 @@ public class JobBoss : GlobalBase { this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job); if (job is DownloadNewChapters dncJob) - cachedPublications.Add(dncJob.manga.internalId, dncJob.manga); + AddMangaToCache(dncJob.manga); } - HashSet coverFileNames = cachedPublications.Select(manga => manga.Value.coverFileNameInCache!).ToHashSet(); + HashSet coverFileNames = GetAllCachedManga().Select(manga => manga.coverFileNameInCache!).ToHashSet(); foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers { if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga))) diff --git a/Tranga/MangaConnectors/Bato.cs b/Tranga/MangaConnectors/Bato.cs index 58582e7..f077ea9 100644 --- a/Tranga/MangaConnectors/Bato.cs +++ b/Tranga/MangaConnectors/Bato.cs @@ -116,7 +116,7 @@ public class Bato : MangaConnector Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary(), year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga.internalId, manga); + AddMangaToCache(manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaDex.cs b/Tranga/MangaConnectors/MangaDex.cs index 135261b..6bcf22f 100644 --- a/Tranga/MangaConnectors/MangaDex.cs +++ b/Tranga/MangaConnectors/MangaDex.cs @@ -187,7 +187,7 @@ public class MangaDex : MangaConnector status, websiteUrl: $"https://mangadex.org/title/{publicationId}" ); - cachedPublications.Add(pub.internalId, pub); + AddMangaToCache(pub); return pub; } diff --git a/Tranga/MangaConnectors/MangaKatana.cs b/Tranga/MangaConnectors/MangaKatana.cs index 5996439..4976d28 100644 --- a/Tranga/MangaConnectors/MangaKatana.cs +++ b/Tranga/MangaConnectors/MangaKatana.cs @@ -143,7 +143,7 @@ public class MangaKatana : MangaConnector Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga.internalId, manga); + AddMangaToCache(manga); return manga; } diff --git a/Tranga/MangaConnectors/MangaLife.cs b/Tranga/MangaConnectors/MangaLife.cs index d54454f..b99e0e9 100644 --- a/Tranga/MangaConnectors/MangaLife.cs +++ b/Tranga/MangaConnectors/MangaLife.cs @@ -123,7 +123,7 @@ public class MangaLife : MangaConnector Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga.internalId, manga); + AddMangaToCache(manga); return manga; } diff --git a/Tranga/MangaConnectors/Manganato.cs b/Tranga/MangaConnectors/Manganato.cs index 437f1b9..7fc5bec 100644 --- a/Tranga/MangaConnectors/Manganato.cs +++ b/Tranga/MangaConnectors/Manganato.cs @@ -133,7 +133,7 @@ public class Manganato : MangaConnector Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga.internalId, manga); + AddMangaToCache(manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangasee.cs b/Tranga/MangaConnectors/Mangasee.cs index 32053b6..e1ce0c2 100644 --- a/Tranga/MangaConnectors/Mangasee.cs +++ b/Tranga/MangaConnectors/Mangasee.cs @@ -179,7 +179,7 @@ public class Mangasee : MangaConnector Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga.internalId, manga); + AddMangaToCache(manga); return manga; } diff --git a/Tranga/MangaConnectors/Mangaworld.cs b/Tranga/MangaConnectors/Mangaworld.cs index fbea159..b5c1dc3 100644 --- a/Tranga/MangaConnectors/Mangaworld.cs +++ b/Tranga/MangaConnectors/Mangaworld.cs @@ -120,7 +120,7 @@ public class Mangaworld: MangaConnector Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); - cachedPublications.Add(manga.internalId, manga); + AddMangaToCache(manga); return manga; } diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index ca01d88..5413fa5 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -54,14 +54,7 @@ public partial class Tranga : GlobalBase return _connectors; } - public Manga? GetPublicationById(string internalId) - { - return cachedPublications.TryGetValue(internalId, out Manga manga) switch - { - true => manga, - _ => null - }; - } + public Manga? GetPublicationById(string internalId) => GetCachedManga(internalId); public bool TryGetPublicationById(string internalId, out Manga? manga) { From 783f229a6ac4acf963a9e91dfed863b178bdefe6 Mon Sep 17 00:00:00 2001 From: Glax Date: Tue, 23 Apr 2024 00:48:08 +0200 Subject: [PATCH 03/12] Add LibraryConnector.Test to see if requests can be made to endpoint. --- Tranga/LibraryConnectors/Kavita.cs | 10 +++++++++- Tranga/LibraryConnectors/Komga.cs | 8 ++++++++ Tranga/LibraryConnectors/LibraryConnector.cs | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Tranga/LibraryConnectors/Kavita.cs b/Tranga/LibraryConnectors/Kavita.cs index 3fb8983..4dfb02b 100644 --- a/Tranga/LibraryConnectors/Kavita.cs +++ b/Tranga/LibraryConnectors/Kavita.cs @@ -67,7 +67,15 @@ public class Kavita : LibraryConnector foreach (KavitaLibrary lib in GetLibraries()) NetClient.MakePost($"{baseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", auth, logger); } - + + internal override bool Test() + { + foreach (KavitaLibrary lib in GetLibraries()) + if (NetClient.MakePost($"{baseUrl}/api/Library/scan?libraryId={lib.id}", "Bearer", auth, logger)) + return true; + return false; + } + /// /// Fetches all libraries available to the user /// diff --git a/Tranga/LibraryConnectors/Komga.cs b/Tranga/LibraryConnectors/Komga.cs index 7a0c485..557d934 100644 --- a/Tranga/LibraryConnectors/Komga.cs +++ b/Tranga/LibraryConnectors/Komga.cs @@ -32,6 +32,14 @@ public class Komga : LibraryConnector NetClient.MakePost($"{baseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", auth, logger); } + internal override bool Test() + { + foreach (KomgaLibrary lib in GetLibraries()) + if (NetClient.MakePost($"{baseUrl}/api/v1/libraries/{lib.id}/scan", "Basic", auth, logger)) + return true; + return false; + } + /// /// Fetches all libraries available to the user /// diff --git a/Tranga/LibraryConnectors/LibraryConnector.cs b/Tranga/LibraryConnectors/LibraryConnector.cs index 0a66890..80dd5b2 100644 --- a/Tranga/LibraryConnectors/LibraryConnector.cs +++ b/Tranga/LibraryConnectors/LibraryConnector.cs @@ -30,6 +30,7 @@ public abstract class LibraryConnector : GlobalBase this.libraryType = libraryType; } public abstract void UpdateLibrary(); + internal abstract bool Test(); protected static class NetClient { From 58cff6513aee85e6677edc79d5a06162a7018dda Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 20:46:26 +0200 Subject: [PATCH 04/12] Possible fix #175 --- Tranga/Jobs/UpdateMetadata.cs | 1 + Tranga/Manga.cs | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index 5471685..b855f14 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -35,6 +35,7 @@ public class UpdateMetadata : Job this.manga = manga.WithMetadata(updatedManga); this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); + this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); this.progressToken.Complete(); } else diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 388d02d..4e079c5 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -20,7 +20,7 @@ public struct Manga public string[] tags { get; private set; } // ReSharper disable once UnusedAutoPropertyAccessor.Global public string? coverUrl { get; private set; } - public string? coverFileNameInCache { get; } + public string? coverFileNameInCache { get; private set; } // ReSharper disable once UnusedAutoPropertyAccessor.Global public Dictionary links { get; } // ReSharper disable once MemberCanBePrivate.Global @@ -88,7 +88,8 @@ public struct Manga status = newManga.status, releaseStatus = newManga.releaseStatus, websiteUrl = newManga.websiteUrl, - year = newManga.year + year = newManga.year, + coverFileNameInCache = coverFileNameInCache }; } @@ -103,6 +104,7 @@ public struct Manga this.sortName == compareManga.sortName && this.latestChapterAvailable.Equals(compareManga.latestChapterAvailable) && this.authors.All(a => compareManga.authors.Contains(a)) && + (this.coverFileNameInCache??"").Equals(compareManga.coverFileNameInCache) && (this.websiteUrl??"").Equals(compareManga.websiteUrl) && this.tags.All(t => compareManga.tags.Contains(t)); } From 7ec262a2e493b84c8a5e6be6182f263a2dd82357 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 20:57:46 +0200 Subject: [PATCH 05/12] Possible fix #175 Export jobs when Manga-Metadata is updated. --- Tranga/Jobs/UpdateMetadata.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index b855f14..97464f3 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -36,6 +36,8 @@ public class UpdateMetadata : Job this.manga = manga.WithMetadata(updatedManga); this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); + foreach (Job job in jobBoss.GetJobsLike(publication: manga)) + jobBoss.UpdateJobFile(job); this.progressToken.Complete(); } else From 8b62e2c4671f9d92593f350479074e2ef06aa703 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 20:57:46 +0200 Subject: [PATCH 06/12] Possible fix #175 Export jobs when Manga-Metadata is updated. --- Tranga/Jobs/UpdateMetadata.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index b855f14..97464f3 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -36,6 +36,8 @@ public class UpdateMetadata : Job this.manga = manga.WithMetadata(updatedManga); this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); + foreach (Job job in jobBoss.GetJobsLike(publication: manga)) + jobBoss.UpdateJobFile(job); this.progressToken.Complete(); } else From 4bd1150a0e212cdb085b4566a1baf2f644e9bf5e Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 21:03:44 +0200 Subject: [PATCH 07/12] fix bug Manga.WithMetadata coverfilenameincache not being replaced. --- Tranga/Manga.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 4e079c5..171daad 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -89,7 +89,7 @@ public struct Manga releaseStatus = newManga.releaseStatus, websiteUrl = newManga.websiteUrl, year = newManga.year, - coverFileNameInCache = coverFileNameInCache + coverFileNameInCache = newManga.coverFileNameInCache }; } From 9f9ea569d59cf7cfd84249881b1c4c769183cc6f Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 21:03:44 +0200 Subject: [PATCH 08/12] fix bug Manga.WithMetadata coverfilenameincache not being replaced. --- Tranga/Manga.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 4e079c5..171daad 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -89,7 +89,7 @@ public struct Manga releaseStatus = newManga.releaseStatus, websiteUrl = newManga.websiteUrl, year = newManga.year, - coverFileNameInCache = coverFileNameInCache + coverFileNameInCache = newManga.coverFileNameInCache }; } From 6b91796e5a9b480748e9909dd44ce875e7e9fa6b Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 21:10:26 +0200 Subject: [PATCH 09/12] Update manga in DownloadNewChapters Jobs --- Tranga/Jobs/UpdateMetadata.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index 97464f3..9fab4dc 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -36,8 +36,16 @@ public class UpdateMetadata : Job this.manga = manga.WithMetadata(updatedManga); this.manga.SaveSeriesInfoJson(settings.downloadLocation, true); this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); - foreach (Job job in jobBoss.GetJobsLike(publication: manga)) + foreach (Job job in jobBoss.GetJobsLike(publication: this.manga)) + { + if (job is DownloadNewChapters dc) + dc.manga = this.manga; + else if (job is UpdateMetadata um) + um.manga = this.manga; + else + continue; jobBoss.UpdateJobFile(job); + } this.progressToken.Complete(); } else From d52213002ee370d09714b3455bd156e9ee6736e2 Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 21:24:11 +0200 Subject: [PATCH 10/12] Delete old jobfiles. --- Tranga/Jobs/JobBoss.cs | 29 +++++++++++++++++++++-------- Tranga/Jobs/UpdateMetadata.cs | 9 ++++++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 75e01a6..637b3ae 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -171,18 +171,18 @@ public class JobBoss : GlobalBase } } - internal void UpdateJobFile(Job job) + internal void UpdateJobFile(Job job, string? oldFile = null) { - string jobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); + string newJobFilePath = Path.Join(settings.jobsFolderPath, $"{job.id}.json"); if (!this.jobs.Any(jjob => jjob.id == job.id)) { try { - Log($"Deleting Job-file {jobFilePath}"); - while(IsFileInUse(jobFilePath)) + Log($"Deleting Job-file {newJobFilePath}"); + while(IsFileInUse(newJobFilePath)) Thread.Sleep(10); - File.Delete(jobFilePath); + File.Delete(newJobFilePath); } catch (Exception e) { @@ -191,12 +191,25 @@ public class JobBoss : GlobalBase } else { - Log($"Exporting Job {jobFilePath}"); + Log($"Exporting Job {newJobFilePath}"); string jobStr = JsonConvert.SerializeObject(job); - while(IsFileInUse(jobFilePath)) + while(IsFileInUse(newJobFilePath)) Thread.Sleep(10); - File.WriteAllText(jobFilePath, jobStr); + File.WriteAllText(newJobFilePath, jobStr); } + + if(oldFile is not null) + try + { + Log($"Deleting old Job-file {oldFile}"); + while(IsFileInUse(oldFile)) + Thread.Sleep(10); + File.Delete(oldFile); + } + catch (Exception e) + { + Log(e.ToString()); + } } private void UpdateAllJobFiles() diff --git a/Tranga/Jobs/UpdateMetadata.cs b/Tranga/Jobs/UpdateMetadata.cs index 9fab4dc..4dc3ae7 100644 --- a/Tranga/Jobs/UpdateMetadata.cs +++ b/Tranga/Jobs/UpdateMetadata.cs @@ -38,13 +38,20 @@ public class UpdateMetadata : Job this.mangaConnector.CopyCoverFromCacheToDownloadLocation(manga); foreach (Job job in jobBoss.GetJobsLike(publication: this.manga)) { + string oldFile; if (job is DownloadNewChapters dc) + { + oldFile = dc.id; dc.manga = this.manga; + } else if (job is UpdateMetadata um) + { + oldFile = um.id; um.manga = this.manga; + } else continue; - jobBoss.UpdateJobFile(job); + jobBoss.UpdateJobFile(job, oldFile); } this.progressToken.Complete(); } From c6d0168d2f37097dd06164fb8f4524b3c0bc007a Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 21:29:05 +0200 Subject: [PATCH 11/12] Fix #174 auth not being written to file for ntfy. --- Tranga/NotificationConnectors/Ntfy.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tranga/NotificationConnectors/Ntfy.cs b/Tranga/NotificationConnectors/Ntfy.cs index a7fed50..fef0f90 100644 --- a/Tranga/NotificationConnectors/Ntfy.cs +++ b/Tranga/NotificationConnectors/Ntfy.cs @@ -5,9 +5,9 @@ namespace Tranga.NotificationConnectors; public class Ntfy : NotificationConnector { - // ReSharper disable once MemberCanBePrivate.Global + // ReSharper disable twice MemberCanBePrivate.Global public string endpoint { get; init; } - private string auth { get; init; } + public string auth { get; init; } private const string Topic = "tranga"; private readonly HttpClient _client = new(); From 3d855020eb2706e47180bfc679d70284bfdadbcb Mon Sep 17 00:00:00 2001 From: Glax Date: Thu, 25 Apr 2024 21:32:48 +0200 Subject: [PATCH 12/12] Export job files indented. --- Tranga/Jobs/JobBoss.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 637b3ae..51fdece 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -192,7 +192,7 @@ public class JobBoss : GlobalBase else { Log($"Exporting Job {newJobFilePath}"); - string jobStr = JsonConvert.SerializeObject(job); + string jobStr = JsonConvert.SerializeObject(job, Formatting.Indented); while(IsFileInUse(newJobFilePath)) Thread.Sleep(10); File.WriteAllText(newJobFilePath, jobStr);