RocksmithToolkitLib.PsarcLoader.PSARC.InflateEntry C# (CSharp) Method

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 void InflateEntry(Entry entry, string destfilepath = "")
        {
            entry.ErrMsg = String.Empty;

            if (entry.Length == 0) return; //skip empty files
            // Decompress Entry
            const int zHeader = 0x78DA;
            uint zChunkID = entry.zIndexBegin;
            int blockSize = (int)_header.BlockSizeAlloc;
            //bool isZlib = _header.CompressionMethod == 2053925218;

            if (destfilepath.Length > 0)
                entry.Data = new FileStream(destfilepath, FileMode.Create, FileAccess.Write, FileShare.Read);
            else
            {
                if (UseMemory)
                    entry.Data = new MemoryStreamExtension();
                else
                    entry.Data = new TempFileStream();
            }
            //Why won't this compile?
            // entry.Data = UseMemory ? new MemoryStream() : new TempFileStream();

            _reader.BaseStream.Position = (long)entry.Offset;

            do
            {
                // check for corrupt CDLC content and catch exceptions
                try
                {
                    if (_zBlocksSizeList[zChunkID] == 0U) // raw. full cluster used.
                    {
                        entry.Data.Write(_reader.ReadBytes(blockSize), 0, blockSize);
                    }
                    else
                    {
                        var num = _reader.ReadUInt16();
                        _reader.BaseStream.Position -= 2L;

                        var array = _reader.ReadBytes((int)_zBlocksSizeList[zChunkID]);
                        if (num == zHeader)
                        {
                            // compressed
                            try
                            {
                                RijndaelEncryptor.Unzip(array, entry.Data, false);
                            }
                            catch (Exception ex) //IOException
                            {
                                // corrupt CDLC zlib.net exception ... try to unpack
                                if (String.IsNullOrEmpty(entry.Name))
                                 entry.ErrMsg = String.Format(@"{1}CDLC contains a zlib exception.{1}Warning: {0}{1}", ex.Message, Environment.NewLine);
                                else
                                    entry.ErrMsg = String.Format(@"{2}CDLC contains a broken datachunk in file '{0}'.{2}Warning: {1}{2}", entry.Name.Split('/').Last(), ex.Message, Environment.NewLine);

                                Console.Write(entry.ErrMsg);
                            }
                        }
                        else // raw. used only for data(chunks) smaller than 64 kb
                        {
                            entry.Data.Write(array, 0, array.Length);
                        }
                    }
                    zChunkID += 1;
                }
                catch (Exception ex) // index is outside the bounds of the array
                {
                    // corrupt CDLC data length ... try to unpack
                    entry.ErrMsg = String.Format(@"{2}CDLC contains a broken datachunk in file '{0}'.{2}Warning: {1}{2}", entry.Name.Split('/').Last(), ex.Message, Environment.NewLine);
                    Console.Write(entry.ErrMsg + Environment.NewLine);
                    break;
                }
            } while (entry.Data.Length < (long)entry.Length);
            entry.Data.Seek(0, SeekOrigin.Begin);
            entry.Data.Flush();
        }

Same methods

PSARC::InflateEntry ( string name ) : void

Usage Example

        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("");
                }
        }
All Usage Examples Of RocksmithToolkitLib.PsarcLoader.PSARC::InflateEntry