InflateEntry() public method

Inflates selected entry.
public InflateEntry ( Entry entry, string destfilepath = "" ) : void
entry Entry Entry to unpack.
destfilepath string Destination file used instead of the temp file.
return void
        public static string ExtractArchiveFile(string psarcPath, string entryNamePath, string outputDir)
        {
            if (!File.Exists(psarcPath))
            {
                return("");
            }

            using (PSARC archive = new PSARC(true))
                using (var psarcStream = File.OpenRead(psarcPath))
                {
                    archive.Read(psarcStream, true);
                    var tocEntry = archive.TOC.Where(entry => entry.Name.Contains(entryNamePath)).FirstOrDefault();

                    if (tocEntry != null)
                    {
                        if (!Directory.Exists(outputDir))
                        {
                            Directory.CreateDirectory(outputDir);
                        }

                        archive.InflateEntry(tocEntry, Path.Combine(outputDir, Path.GetFileName(tocEntry.ToString())));

                        return(Path.Combine(outputDir, tocEntry.ToString()));
                    }

                    return("");
                }
        }
        // old slower static method
        public static List<Entry> ExtractAudioEntry(string archiveName, string audioName, string previewName)
        {
            bool result = false;
            if (String.IsNullOrEmpty(audioName))
                return null; // false;

            GlobalExtension.ShowProgress("Extracting Audio ...");
            List<Entry> wems;

            using (var archive = new PSARC(true))
            using (var stream = File.OpenRead(archiveName))
            {
                archive.Read(stream, true);
                wems = archive.TOC.Where(entry => entry.Name.StartsWith("audio/windows") && entry.Name.EndsWith(".wem")).ToList();

                if (wems.Count > 1)
                {
                    wems.Sort((e1, e2) =>
                    {
                        if (e1.Length < e2.Length)
                            return 1;
                        if (e1.Length > e2.Length)
                            return -1;
                        return 0;
                    });
                }

                if (wems.Count > 0)
                {
                    var top = wems[0]; // wem audio with internal TOC path
                    archive.InflateEntry(top);
                    top.Data.Position = 0;
                    using (var FS = File.Create(audioName))
                    {
                        WwiseToOgg w2o = new WwiseToOgg(top.Data, FS);
                        result = w2o.ConvertToOgg();
                    }
                }

                if (!String.IsNullOrEmpty(previewName) && result && wems.Count > 0)
                {
                    var bottom = wems.Last();
                    archive.InflateEntry(bottom);
                    bottom.Data.Position = 0;
                    using (var FS = File.Create(previewName))
                    {
                        WwiseToOgg w2o = new WwiseToOgg(bottom.Data, FS);
                        result = w2o.ConvertToOgg();
                    }
                }
            }

            // confirmed this output is same as old exe converter method both are 44KHz VBR
            if (!result)
                return null;

            return wems;
        }
        public static Stream GetData(this PSARC p, Func <Entry, bool> dataEntry)
        {
            var de = p.TOC.Where(dataEntry).FirstOrDefault();

            if (de != null)
            {
                if (de.Data == null)
                {
                    p.InflateEntry(de);
                }

                return(de.Data);
            }
            return(null);
        }
        public static bool ReplaceData(this PSARC p, Func <Entry, bool> dataEntry, Stream newData)
        {
            var de = p.TOC.Where(dataEntry).FirstOrDefault();

            if (de != null)
            {
                if (de.Data != null)
                {
                    de.Data.Dispose();
                    de.Data = null;
                }
                else
                {
                    p.InflateEntry(de);
                }

                de.Data = newData;
                return(true);
            }
            return(false);
        }
        public static Stream ExtractArchiveFile(string psarcPath, string entryNamePath)
        {
            if (!File.Exists(psarcPath))
            {
                return(null);
            }

            using (PSARC archive = new PSARC(true))
                using (var psarcStream = File.OpenRead(psarcPath))
                {
                    archive.Read(psarcStream, true);
                    var tocEntry = archive.TOC.FirstOrDefault(x => (x.Name.Equals(entryNamePath)));

                    if (tocEntry != null)
                    {
                        archive.InflateEntry(tocEntry);
                        return(tocEntry.Data);
                    }
                }

            return(null);
        }
Example #6
0
        public static Stream ExtractPSARCData(this Stream stream, Func <Entry, bool> dataEntry)
        {
            using (PSARC p = new PSARC(true))
            {
                p.Read(stream, true);

                var de = p.TOC.Where(dataEntry).FirstOrDefault();
                if (de != null)
                {
                    MemoryStream ms = new MemoryStream();
                    p.InflateEntry(de);
                    if (de.Data == null)
                    {
                        return(null);
                    }
                    de.Data.Position = 0;
                    de.Data.CopyTo(ms);
                    ms.Position = 0;
                    return(ms);
                }
                return(null);
            }
        }
Example #7
0
        public Stream ExtractEntryData(Func <Entry, bool> entryLINQ)
        {
            var entry = _archive.TOC.Where(entryLINQ).FirstOrDefault();

            if (entry != null)
            {
                MemoryStream ms = new MemoryStream();
                _archive.InflateEntry(entry);
                if (entry.Data == null)
                {
                    return(null);
                }

                entry.Data.Position = 0;
                entry.Data.CopyTo(ms);
                entry.Dispose();
                ms.Position = 0;
                return(ms);
            }
            return(null);
        }
Example #8
0
        // old slower static method
        public static List <Entry> ExtractAudioEntry(string archiveName, string audioName, string previewName)
        {
            bool result = false;

            if (String.IsNullOrEmpty(audioName))
            {
                return(null); // false;
            }
            GlobalExtension.ShowProgress("Extracting Audio ...");
            List <Entry> wems;

            using (var archive = new PSARC(true))
                using (var stream = File.OpenRead(archiveName))
                {
                    archive.Read(stream, true);
                    wems = archive.TOC.Where(entry => entry.Name.StartsWith("audio/windows") && entry.Name.EndsWith(".wem")).ToList();

                    if (wems.Count > 1)
                    {
                        wems.Sort((e1, e2) =>
                        {
                            if (e1.Length < e2.Length)
                            {
                                return(1);
                            }
                            if (e1.Length > e2.Length)
                            {
                                return(-1);
                            }
                            return(0);
                        });
                    }

                    if (wems.Count > 0)
                    {
                        var top = wems[0]; // wem audio with internal TOC path
                        archive.InflateEntry(top);
                        top.Data.Position = 0;
                        using (var FS = File.Create(audioName))
                        {
                            WwiseToOgg w2o = new WwiseToOgg(top.Data, FS);
                            result = w2o.ConvertToOgg();
                        }
                    }

                    if (!String.IsNullOrEmpty(previewName) && result && wems.Count > 0)
                    {
                        var bottom = wems.Last();
                        archive.InflateEntry(bottom);
                        bottom.Data.Position = 0;
                        using (var FS = File.Create(previewName))
                        {
                            WwiseToOgg w2o = new WwiseToOgg(bottom.Data, FS);
                            result = w2o.ConvertToOgg();
                        }
                    }
                }

            // confirmed this output is same as old exe converter method both are 44KHz VBR
            if (!result)
            {
                return(null);
            }

            return(wems);
        }