public RpkgEntry ReadEntry()
        {
            RpkgEntry entry = new RpkgEntry();

            entry.Hash   = ReadUInt64();
            entry.Offset = ReadUInt64();
            entry.CompressedSizeWithFlags = ReadUInt32();

            return(entry);
        }
Beispiel #2
0
        private void ImportNewFile(RpkgBinaryWriter writer, RpkgEntry rpkgEntry)
        {
            var rawData = rpkgEntry.ImportRawData ?? File.ReadAllBytes(rpkgEntry.Import);

            if (rpkgEntry.IsCompressed)
            {
                rpkgEntry.CompressedSize = writer.WriteCompressedBytes(rawData);
            }
            else
            {
                writer.Write(rawData);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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));
            }
        }
Beispiel #5
0
 public void Write(RpkgEntry entry)
 {
     Write(entry.Hash);
     Write(entry.Offset);
     Write(entry.CompressedSizeWithFlags);
 }
Beispiel #6
0
 public void AppendDataEntry(RpkgBinaryWriter writer, RpkgEntry rpkgEntry)
 {
     writer.BaseStream.Seek(0, SeekOrigin.End);
     rpkgEntry.Offset = (ulong)writer.BaseStream.Position;
     ImportNewFile(writer, rpkgEntry);
 }