mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-23 16:14:35 +00:00
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PckStudio.Core.Extensions
|
|
{
|
|
internal static class ZipArchiveEntryExtensions
|
|
{
|
|
public static string ReadAllText(this ZipArchiveEntry entry)
|
|
{
|
|
if (entry == null)
|
|
return string.Empty;
|
|
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("\\"));
|
|
}
|
|
}
|
|
}
|