Exemple #1
0
        private void SafeReadAdditionalEntryInfo(IsoTableEntryInfo info)
        {
            try
            {
                if (info.CompressedSize < 4)
                {
                    return;
                }

                byte[] signature;
                using (Stream input = OpenStream(info.Offset, info.CompressedSize))
                    using (MemoryStream output = new MemoryStream(4))
                    {
                        if (!info.IsCompressed)
                        {
                            info.IsCompressed = (input.ReadByte() == 0x01);
                            input.Seek(-1, SeekOrigin.Current);
                        }

                        if (info.IsCompressed)
                        {
                            input.Seek(1, SeekOrigin.Current);
                            int uncompressedSize = input.ReadStruct <int>();
                            if (uncompressedSize < 4)
                            {
                                return;
                            }

                            LZSStream decompressStream = new LZSStream(input, output);
                            decompressStream.Decompress(4);
                            output.Flush();
                            signature = output.ToArray();
                            if (signature.Length == 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            signature = new byte[4];
                            input.EnsureRead(signature, 0, 4);
                        }
                    }
                info.Signature = (FFXFileSignatures)BitConverter.ToInt32(signature, 0);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to read additional info of entry '{0}'", info.GetFileName());
            }
            finally
            {
                ProgressIncrement.NullSafeInvoke(1);
            }
        }
Exemple #2
0
        public void ExtractFile(IsoTableEntryInfo info, string outputPath)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

            using (Stream input = OpenStream(info.Offset, info.CompressedSize))
                using (Stream output = File.Create(outputPath))
                {
                    if (!info.IsCompressed)
                    {
                        input.CopyTo(output);
                    }
                    else
                    {
                        input.Seek(1, SeekOrigin.Current);
                        int uncompressedSize = input.ReadStruct <int>();

                        LZSStream decompressStream = new LZSStream(input, output);
                        decompressStream.Decompress(uncompressedSize);
                    }
                }
        }