From 6faaaf413901961e4b03d364560a532ede1b9106 Mon Sep 17 00:00:00 2001 From: Glax Date: Mon, 9 Sep 2024 09:23:25 +0200 Subject: [PATCH] Fix #243 Moving Publication folders, overwrite files, merge folders --- Tranga/Manga.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Tranga/Manga.cs b/Tranga/Manga.cs index 5ebad19..357f940 100644 --- a/Tranga/Manga.cs +++ b/Tranga/Manga.cs @@ -128,10 +128,19 @@ public struct Manga public void MovePublicationFolder(string downloadDirectory, string newFolderName) { string oldPath = Path.Join(downloadDirectory, this.folderName); - this.folderName = newFolderName; + this.folderName = newFolderName;//Create new Path with the new folderName string newPath = CreatePublicationFolder(downloadDirectory); - if(Directory.Exists(oldPath)) - Directory.Move(oldPath, newPath); + if (Directory.Exists(oldPath)) + { + if (Directory.Exists(newPath)) //Move/Overwrite old Files, Delete old Directory + { + IEnumerable newPathFileNames = new DirectoryInfo(newPath).GetFiles().Select(fi => fi.Name); + foreach(FileInfo fileInfo in new DirectoryInfo(oldPath).GetFiles().Where(fi => newPathFileNames.Contains(fi.Name) == false)) + File.Move(fileInfo.FullName, Path.Join(newPath, fileInfo.Name), true); + Directory.Delete(oldPath); + }else + Directory.Move(oldPath, newPath); + } } public void UpdateLatestDownloadedChapter(Chapter chapter)//TODO check files if chapters are all downloaded