Skip to content

Commit

Permalink
Filtering files according to supported image types
Browse files Browse the repository at this point in the history
  • Loading branch information
ptedeschi committed Feb 19, 2022
1 parent e639575 commit e655781
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/NFT.net/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Constants
public const char WeightDelimiter = '+';
public const string ImagesFolderName = "images";
public const int MaxDuplicateDnaRetries = 100;
public static readonly string[] SupportedImageFormats = new[] { "*.jpg", "*.jpeg", "*.png" };

public static class About
{
Expand Down
2 changes: 1 addition & 1 deletion src/NFT.net/NFT.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>Tedeschi.NFT</RootNamespace>
<AssemblyName>NFT.net</AssemblyName>
<Version>1.4.0</Version>
<Version>1.5.0</Version>
<Authors>Tedeschi</Authors>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/NFT.net/Services/Layer/LayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private List<Layer> HandleLayers(string[] folders)
throw new InvalidLayerNamingException(folder);
}

var files = Directory.GetFiles(folder);
var files = DirectoryUtil.GetFiles(folder, Constants.SupportedImageFormats, SearchOption.AllDirectories);

var elements = this.HandleElements(files, randomizer);

Expand Down
27 changes: 27 additions & 0 deletions src/NFT.net/Util/DirectoryUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// <copyright file="DirectoryUtil.cs" company="Tedeschi">
// Copyright (c) Tedeschi. All rights reserved.
// </copyright>

namespace Tedeschi.NFT.Util
{
using System.IO;
using System.Linq;

public class DirectoryUtil
{
public static string[] GetFiles(string path, string[] patterns = null, SearchOption options = SearchOption.TopDirectoryOnly)
{
if (patterns == null || patterns.Length == 0)
{
return Directory.GetFiles(path, "*", options);
}

if (patterns.Length == 1)
{
return Directory.GetFiles(path, patterns[0], options);
}

return patterns.SelectMany(pattern => Directory.GetFiles(path, pattern, options)).Distinct().ToArray();
}
}
}

0 comments on commit e655781

Please sign in to comment.