From 763661c59f86697df573209e491496c6d9dcf163 Mon Sep 17 00:00:00 2001 From: sentouki Date: Mon, 20 Jul 2020 00:38:15 +0200 Subject: [PATCH] - Fixed a bug where some images would be downloaded again despite being already on the disk --- ArtAPI/IRequestArt.cs | 16 ++++++++++++---- README.md | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ArtAPI/IRequestArt.cs b/ArtAPI/IRequestArt.cs index 5f1d52c..95281dd 100644 --- a/ArtAPI/IRequestArt.cs +++ b/ArtAPI/IRequestArt.cs @@ -174,9 +174,7 @@ protected async Task DownloadImagesAsync() protected async Task DownloadAsync(ImageModel image, string savePath) { if (image == null) return; - var specialChars = new List() { @"\", "/", ":", "*", "?", "\"", "<", ">", "|" }; - var imageName = image.Name; - specialChars.ForEach(c => imageName = imageName.Replace(c, "")); // remove all the nasty characters that can cause trouble + var imageName = NormalizeFileName(image.Name); var imageSavePath = Path.Combine(savePath, $"{imageName}_{image.ID}.{image.FileType}"); const int tries = NumberOfDLAttempts; try @@ -228,7 +226,17 @@ private void Clear() private void CheckLocalImages() { var localImages = Directory.GetFiles(ArtistDirSavepath).Select(Path.GetFileNameWithoutExtension).ToArray(); - ImagesToDownload.RemoveAll(image => localImages.Contains($"{image.Name}_{image.ID}")); + ImagesToDownload.RemoveAll(image => localImages.Contains($"{NormalizeFileName(image.Name)}_{image.ID}")); + } + /// + /// remove all the nasty characters that can cause trouble + /// + /// normalized file name + private string NormalizeFileName(string filename) + { + var specialChars = new List() { @"\", "/", ":", "*", "?", "\"", "<", ">", "|" }; + specialChars.ForEach(c => filename = filename.Replace(c, "")); + return filename; } public void CancelDownload() diff --git a/README.md b/README.md index 032ac4b..c6d9e7e 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Press ***ESC*** to select another platform #### Running the app - [.NET Core 3.1 Runtime](https://dotnet.microsoft.com/download/visual-studio-sdks) -- or download the [self-contained version](https://github.com/sentouki/Artify/releases/download/v1.1.0/Artify.selfcontained.zip) +- or download the [self-contained version](https://github.com/sentouki/Artify/releases/download/v1.2.0/Artify.selfcontained.zip) #### Building the app - [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/visual-studio-sdks)