private IntermediateResourceDescriptor ReadIntermediateDescriptor(long baseOffset, BinaryReader memoryReader)
        {
            var intermediate = new IntermediateResourceDescriptor();

            intermediate.FileOffset = baseOffset + memoryReader.BaseStream.Position;
            intermediate.NameOffset = memoryReader.ReadInt32BE();
            intermediate.Size       = memoryReader.ReadInt32BE();

            return(intermediate);
        }
        private ResourceDescriptor ConvertIntermediateResourceToFinalResource(IntermediateResourceDescriptor intermediateResourceDescriptor, CompositeResourceDescriptor compositeDescriptor)
        {
            if (intermediateResourceDescriptor == null)
            {
                return(null);
            }

            intermediateResourceDescriptor.FinalResourceDescriptor = compositeDescriptor;

            return(new ResourceDescriptor()
            {
                Offset = intermediateResourceDescriptor.FileOffset,
                Size = intermediateResourceDescriptor.Size
            });
        }
 private string BuildResourceName(string subDirectory, IntermediateResourceDescriptor descriptor)
 {
     return(subDirectory + @"\" + descriptor.FinalResourceDescriptor.Name);
 }
        private static void ExtractFileFromIntermediateResourceDescriptor(string outputDirectory, MemoryStream completeDecompressedMemoryStream, IntermediateResourceDescriptor descriptor, string resourceName)
        {
            var outputName = outputDirectory + @"\" + resourceName;

            Directory.CreateDirectory(outputName.Substring(0, outputName.LastIndexOf('\\')));

            using (BinaryWriter writer = new BinaryWriter(File.Open(outputName, FileMode.Create)))
            {
                using (BinaryReader reader = new BinaryReader(completeDecompressedMemoryStream, ASCIIEncoding.ASCII, true))
                {
                    writer.Write(reader.ReadBytes(descriptor.Size));
                }
            }
        }
        private static void WriteToLengthsDescriptor(Queue <int> fileLengthsMapping, StreamWriter descriptorWriter, ref int currentTargetLength, ref int subtotalLength, IntermediateResourceDescriptor resourceDescriptor, string resourceName)
        {
            descriptorWriter.Write(resourceName);

            subtotalLength += resourceDescriptor.Size;
            if (subtotalLength == currentTargetLength)
            {
                descriptorWriter.Write("\n");
                subtotalLength      = 0;
                currentTargetLength = fileLengthsMapping.Count > 0 ? fileLengthsMapping.Dequeue() : 0;
            }
            else
            {
                descriptorWriter.Write(",");
            }
        }