Core(ZipArchiveEntryExtensions) - Add 'GetImage' & 'GetDirectoryContent' extensions

This commit is contained in:
miku-666
2025-12-20 12:11:29 +01:00
parent 1eddf2808a
commit d9e4676b8c

View File

@@ -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<ZipArchiveEntry> 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("\\"));
}
}
}