mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-30 14:41:51 +00:00
Core(ZipArchiveEntryExtensions) - Add 'GetImage' & 'GetDirectoryContent' extensions
This commit is contained in:
@@ -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("\\"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user