Skip to content

Commit

Permalink
- Fixed a bug where some images would be downloaded again despite bei…
Browse files Browse the repository at this point in the history
…ng already on the disk
  • Loading branch information
sentouki committed Jul 19, 2020
1 parent 9eaf767 commit 763661c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions ArtAPI/IRequestArt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ protected async Task DownloadImagesAsync()
protected async Task DownloadAsync(ImageModel image, string savePath)
{
if (image == null) return;
var specialChars = new List<string>() { @"\", "/", ":", "*", "?", "\"", "<", ">", "|" };
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
Expand Down Expand Up @@ -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}"));
}
/// <summary>
/// remove all the nasty characters that can cause trouble
/// </summary>
/// <returns>normalized file name</returns>
private string NormalizeFileName(string filename)
{
var specialChars = new List<string>() { @"\", "/", ":", "*", "?", "\"", "<", ">", "|" };
specialChars.ForEach(c => filename = filename.Replace(c, ""));
return filename;
}

public void CancelDownload()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 763661c

Please sign in to comment.