diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs index cf1a198..d4ff2ed 100644 --- a/Tranga/Connector.cs +++ b/Tranga/Connector.cs @@ -12,7 +12,7 @@ public abstract class Connector public abstract void DownloadChapter(Publication publication, Chapter chapter); //where to? internal abstract void DownloadImage(string url, string path); - internal void DownloadChapter(string[] imageUrls, string outputFolderPath) + internal void DownloadChapter(string[] imageUrls, string outputFilePath) { string tempFolder = Path.GetTempFileName(); File.Delete(tempFolder); @@ -24,10 +24,16 @@ public abstract class Connector string[] split = imageUrl.Split('.'); string extension = split[split.Length - 1]; DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}")); - } - - ZipFile.CreateFromDirectory(tempFolder, $"{outputFolderPath}.cbz"); + + string[] splitPath = outputFilePath.Split(Path.DirectorySeparatorChar); + string directoryPath = Path.Combine(splitPath.Take(splitPath.Length - 1).ToArray()); + if (!Directory.Exists(directoryPath)) + Directory.CreateDirectory(directoryPath); + + string fullPath = $"{outputFilePath}.cbz"; + File.Delete(fullPath); + ZipFile.CreateFromDirectory(tempFolder, fullPath); } internal class DownloadClient diff --git a/Tranga/Connectors/MangaDex.cs b/Tranga/Connectors/MangaDex.cs index 177fda9..11b63df 100644 --- a/Tranga/Connectors/MangaDex.cs +++ b/Tranga/Connectors/MangaDex.cs @@ -178,9 +178,9 @@ public class MangaDex : Connector foreach (JsonNode image in imageFileNames) imageUrls.Add($"{baseUrl}/data/{hash}/{image!.GetValue()}"); - string fileName = string.Concat(publication.sortName.Split(Path.GetInvalidFileNameChars())); + string seriesFolder = string.Concat(publication.sortName.Split(Path.GetInvalidPathChars())); - DownloadChapter(imageUrls.ToArray(), Path.Join(downloadLocation, fileName)); + DownloadChapter(imageUrls.ToArray(), Path.Join(downloadLocation, seriesFolder, chapter.relativeFilePath)); } internal override void DownloadImage(string url, string path)