From d9e4676b8c7382ebfd825dd34fbf2fff396727c4 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 20 Dec 2025 12:11:29 +0100 Subject: [PATCH] Core(ZipArchiveEntryExtensions) - Add 'GetImage' & 'GetDirectoryContent' extensions --- .../Extensions/ZipArchiveEntryExtensions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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("\\")); + } } }