diff --git a/PckStudio.Core/Extensions/ZipArchiveEntryExtensions.cs b/PckStudio.Core/Extensions/ZipArchiveEntryExtensions.cs index ac0cce22..b58dd1c8 100644 --- a/PckStudio.Core/Extensions/ZipArchiveEntryExtensions.cs +++ b/PckStudio.Core/Extensions/ZipArchiveEntryExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.IO.Compression; using System.Linq; @@ -17,5 +18,21 @@ namespace PckStudio.Core.Extensions using StreamReader reader = new StreamReader(entry.Open()); return reader.ReadToEnd(); } + + public static Image GetImage(this ZipArchiveEntry entry) + { + if (entry == null || (!entry.Name.EndsWith(".png") && !entry.Name.EndsWith(".jpg"))) + return null; + + using Stream stream = entry.Open(); + Image image = Image.FromStream(stream); + stream.Dispose(); + return image; + } + + public static IEnumerable GetDirectoryContent(this ZipArchive zip, string path, string extention = "") + { + return zip.Entries.Where(e => e.FullName.StartsWith(path) && e.Name.EndsWith(extention) && !e.Name.EndsWith("/") && !e.Name.EndsWith("\\")); + } } }