From 537ad3a5f88a57e87927fdc9280dced62393675b Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 1 Apr 2024 20:35:47 +0200 Subject: [PATCH] https://github.com/C9Glax/tranga/issues/142 Cleanup old temporary Folders and files --- Tranga/Jobs/JobBoss.cs | 2 +- Tranga/MangaConnectors/MangaConnector.cs | 6 ++++-- Tranga/Tranga.cs | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index f603313..99670b4 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -164,7 +164,7 @@ public class JobBoss : GlobalBase } HashSet coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet(); - foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) + foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers { if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga))) File.Delete(fileName); diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index bd80aed..302a064 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -237,7 +237,7 @@ public abstract class MangaConnector : GlobalBase return HttpStatusCode.Created; //Create a temporary folder to store images - string tempFolder = Directory.CreateTempSubdirectory().FullName; + string tempFolder = Directory.CreateTempSubdirectory("trangatemp").FullName; int chapter = 0; //Download all Images to temporary Folder @@ -260,8 +260,10 @@ public abstract class MangaConnector : GlobalBase progressToken?.Increment(); } - if(comicInfoPath is not null) + if(comicInfoPath is not null){ File.Copy(comicInfoPath, Path.Join(tempFolder, "ComicInfo.xml")); + File.Delete(comicInfoPath); //Delete tmp-file + } Log($"Creating archive {saveArchiveFilePath}"); //ZIP-it and ship-it diff --git a/Tranga/Tranga.cs b/Tranga/Tranga.cs index e146f6f..9dcc387 100644 --- a/Tranga/Tranga.cs +++ b/Tranga/Tranga.cs @@ -26,6 +26,8 @@ public partial class Tranga : GlobalBase new Bato(this), new MangaLife(this) }; + foreach(DirectoryInfo dir in new DirectoryInfo(Path.GetTempPath()).GetDirectories("trangatemp"))//Cleanup old temp folders + dir.Delete(); jobBoss = new(this, this._connectors); StartJobBoss(); this._server = new Server(this);