Example #1
0
        public void ExtractFile(string directory, RpkgEntry rpkgEntry, RpkgBinaryReader reader)
        {
            if (reader.BaseStream.Position != (long)rpkgEntry.Offset)
            {
                reader.BaseStream.Seek((long)rpkgEntry.Offset, SeekOrigin.Begin);
            }

            string compoundName;

            if (rpkgEntry.Name == null)
            {
                compoundName = directory + @"\" + rpkgEntry.Info.Signature + @"\" + rpkgEntry.Hash.ToString("X") + ".dat";
            }
            else
            {
                compoundName = directory + @"\" + rpkgEntry.Info.Signature + @"\" + rpkgEntry.Name;
                compoundName = compoundName.Substring(0, compoundName.Length > 235 ? 235 : compoundName.Length);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(compoundName));

            if (File.Exists(compoundName))
            {
                compoundName += @"_" + Path.GetFileNameWithoutExtension(((FileStream)reader.BaseStream).Name);
            }

            try
            {
                using (FileStream fileStream = File.Open(compoundName, FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(fileStream))
                    {
                        if (rpkgEntry.IsCompressed)
                        {
                            writer.Write(reader.ReadCompressedBytes(rpkgEntry.CompressedSize, rpkgEntry.Info.DecompressedDataSize));
                        }
                        else
                        {
                            writer.Write(reader.ReadBytes((int)rpkgEntry.Info.DecompressedDataSize));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #2
0
        public void SaveDataEntry(RpkgBinaryReader reader, RpkgBinaryWriter writer, RpkgEntry rpkgEntry)
        {
            long originalOffset = (long)rpkgEntry.Offset;

            rpkgEntry.Offset = (ulong)writer.BaseStream.Position;

            if (rpkgEntry.Import != null)
            {
                ImportNewFile(writer, rpkgEntry);
            }
            else
            {
                if (reader.BaseStream.Position != originalOffset)
                {
                    reader.BaseStream.Seek(originalOffset, SeekOrigin.Begin);
                }
                int size = rpkgEntry.IsCompressed ? (int)rpkgEntry.CompressedSize : (int)rpkgEntry.Info.DecompressedDataSize;
                writer.Write(reader.ReadBytes(size));
            }
        }