From e3511cd96b738c516e00915ca419459c846ed929 Mon Sep 17 00:00:00 2001 From: Wizzy69 Date: Fri, 18 Nov 2022 10:45:43 +0200 Subject: [PATCH] --- PluginManager/Others/Functions.cs | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index cac962e..12ae516 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -81,6 +81,39 @@ public static class Functions } } + /// + /// Read content of a packed file as a + /// + /// The file name inside the archive + /// The archive name + public static async Task ReadStreamFromPAKAsync(string fileName, string archFile) + { + + archFile = pakFolder + archFile; + if (!File.Exists(archFile)) + throw new Exception("Failed to load file !"); + + try + { + Stream stream = Stream.Null; + using (var fs = new FileStream(archFile, FileMode.Open)) + using (var zip = new ZipArchive(fs, ZipArchiveMode.Read)) + { + foreach (var entry in zip.Entries) + if (entry.Name == fileName || entry.FullName == fileName) + stream = entry.Open(); + } + + return stream; + } + catch (Exception ex) + { + ex.WriteErrFile(); + await Task.Delay(100); + return await ReadStreamFromPAKAsync(fileName, archFile); + } + } + /// /// Write logs to file