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