protected override void InternalGuardedExecute(MigrationParameters parameters)
        {
            System.Console.WriteLine();

            using(StreamReader streamReader = new BufferedStreamReader(parameters.MdlFileName, true))
                ServiceProvider.GetService<IMigrationService>().Migrate(parameters.ConnectionString, parameters.VersionOrStep.Value, streamReader);
        }
        internal JavaScriptDeserializer(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            Stream incomingStream = stream;
            if (!stream.CanSeek)
            {
                //Incoming stream if not seekable then read it in to memory.
                incomingStream = new BufferedStreamReader(stream);
            }

            Encoding streamEncoding = DetectEncoding(incomingStream.ReadByte(), incomingStream.ReadByte());
            //Move the stream back to 0
            incomingStream.Position = 0;
            //If the stream contains a BOM, StreamReader will detect it and override our encoding setting
            string input = new StreamReader(incomingStream, streamEncoding, true/*detectEncodingFromByteOrderMarks*/).ReadToEnd();

            if (string.IsNullOrEmpty(input))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExpectingElement, XmlDictionaryString.Empty, "root")));
            }

            _deserializer = new JavaScriptObjectDeserializer(input);
        }
 // Methods
 public JavaScriptDeserializer(Stream stream)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     Stream stream2 = stream;
     if (!stream.CanSeek)
     {
         stream2 = new BufferedStreamReader(stream);
     }
     Encoding encoding = DetectEncoding(stream2.ReadByte(), stream2.ReadByte());
     stream2.Position = 0L;
     string input = new StreamReader(stream2, encoding, true).ReadToEnd();
     this.deserializer = new JavaScriptObjectDeserializer(input);
 }
Ejemplo n.º 4
0
 public void BufferedStreamReaderGetStruct(BufferedStreamReader bufferedStreamReader, out Quadnode randomQuadnode)
 {
     bufferedStreamReader.Read(out randomQuadnode);
 }
Ejemplo n.º 5
0
 private static EndianStreamReader GetStreamFromEndian(Stream stream, bool bigEndian, int bufferSize, out BufferedStreamReader streamReader)
 {
     streamReader = new BufferedStreamReader(stream, bufferSize);
     return(bigEndian ? new BigEndianStreamReader(streamReader) : new LittleEndianStreamReader(streamReader));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns true if the current archive is an entry for the specified archive name.
 /// </summary>
 public bool IsFirstEntry(BufferedStreamReader streamReader, Func <int, int> memoryToRawAddress, DatFileEntry nextEntry, string expectedArchiveName)
 {
     return(Sector == 0 && (GetName(streamReader, memoryToRawAddress) == expectedArchiveName) &&
            SizeBytes == nextEntry.SizeBytes &&
            SizeMulBy16 == nextEntry.SizeMulBy16);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Reads an archive from a stream.
        /// </summary>
        /// <param name="stream">Stream pointing to the start of the archive.</param>
        /// <param name="archiveSize">Size of the archive file.</param>
        public ArchiveReader(Stream stream, int archiveSize)
        {
            _stream   = stream;
            _startPos = stream.Position;

            // Extract Data.
            using var streamReader = new BufferedStreamReader(stream, 2048);
            streamReader.Read(out int binCount);
            Groups = new Group[binCount];

            // Get group item counts.
            for (int x = 0; x < Groups.Length; x++)
            {
                Groups[x].Files = new Structs.Parser.File[streamReader.Read <byte>()];
            }

            // Alignment
            streamReader.Seek(Utilities.Utilities.RoundUp((int)streamReader.Position(), 4) - streamReader.Position(), SeekOrigin.Current);

            // Skip section containing first item for each group.
            streamReader.Seek(sizeof(short) * Groups.Length, SeekOrigin.Current);

            // Populate IDs
            for (int x = 0; x < Groups.Length; x++)
            {
                Groups[x].Id = streamReader.Read <ushort>();
            }

            // Populate offsets.
            int[] offsets = new int[Groups.Select(x => x.Files.Length).Sum()];
            for (int x = 0; x < offsets.Length; x++)
            {
                offsets[x] = streamReader.Read <int>();
            }

            int offsetIndex = 0;

            for (int x = 0; x < Groups.Length; x++)
            {
                var fileCount = Groups[x].Files.Length;
                for (int y = 0; y < fileCount; y++)
                {
                    // Do not fill if no more elements left.
                    if (offsetIndex >= offsets.Length)
                    {
                        break;
                    }

                    var offset          = (int)offsets[offsetIndex];
                    int nextOffsetIndex = offsetIndex;
                    offsetIndex += 1;

                    // Find next non-zero value within array; if not found, use archive size..
                    do
                    {
                        nextOffsetIndex += 1;
                    }while (nextOffsetIndex < offsets.Length && offsets[nextOffsetIndex] == 0);

                    var nextOffset = nextOffsetIndex < offsets.Length ? offsets[nextOffsetIndex] : archiveSize;

                    // Set offsets
                    Groups[x].Files[y].Offset = offset;
                    Groups[x].Files[y].Size   = nextOffset - offset;
                }
            }
        }
Ejemplo n.º 8
0
 public void BufferedStreamReaderGetStruct(BufferedStreamReader bufferedStreamReader, out RandomIntStruct randomIntStruct)
 {
     bufferedStreamReader.Read(out randomIntStruct);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a <see cref="L20n.IO.CharStream"/> instance based on a given string buffer.
 /// </summary>
 public CharStream(StreamReader stream, string path = null)
 {
     m_Stream      = new BufferedStreamReader(stream);
     m_Buffer      = new List <char>();
     m_BufferBlock = new char[8];
 }
Ejemplo n.º 10
0
        public static void ReadFrom(BufferedStreamReader input, Action <PDU> readAction)
        {
            var pdu = ReadHeaderFrom(input);

            input.Read(pdu.Length, () => readAction.Invoke(pdu));
        }
Ejemplo n.º 11
0
        private RunInfo GatherNextRun(BufferedStreamReader reader)
        {
            int runLength = 0;

            return(m_runInfoFactory.GetRunInfo(runLength));
        }
 /// <summary>
 /// Constructs a <see cref="EndianStreamReader"/> given an existing stream reader.
 /// </summary>
 protected EndianStreamReader(BufferedStreamReader streamReader) => Reader = streamReader;
 /// <summary>
 /// Constructs a <see cref="EndianStreamReader"/> given an existing stream reader.
 /// </summary>
 public BigEndianStreamReader(BufferedStreamReader streamReader) : base(streamReader)
 {
 }
 /// <summary>
 /// Deserializes the BufferedStreamReader to object
 /// </summary>
 /// <typeparam name="TResult">Object type to deserialize to</typeparam>
 /// <param name="inputStream">BufferedStreamReader to use when deserializing</param>
 /// <param name="partOfEnum"></param>
 /// <returns></returns>
 public static TResult Deserialize <TResult>(BufferedStreamReader inputStream, bool partOfEnum = false)
     where TResult : class
 {
     if (inputStream.EndOfStream)
     {
         return(default);
 /// <summary>
 /// Uses file stream to deserialize fixed width file to object
 /// </summary>
 /// <typeparam name="TResult">Object type to deserialize file to</typeparam>
 /// <param name="fileStream">FileStream to use when deserializing</param>
 /// <returns></returns>
 public static TResult Deserialize <TResult>(FileStream fileStream) where TResult : class
 {
     using (var sr = new BufferedStreamReader(fileStream))
         return(Deserialize <TResult>(sr));
 }
Ejemplo n.º 16
0
 internal BitReader(BufferedStreamReader input)
 {
     _input = input;
 }
Ejemplo n.º 17
0
        static void DumpFpk(string filePath)
        {
            var fileDict  = new Dictionary <int, string>();
            var storeDict = new Dictionary <int, byte[]>();
            var luaFiles  = new List <string>();
            var refText   = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6), "FpkTool.txt");

            //Get name references if they exist
            if (File.Exists(refText))
            {
                Console.WriteLine("FpkTool.txt exists");
                using (StreamReader reader = File.OpenText(refText))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] fileKey = line.Split(' ');
                        fileDict.Add(int.Parse(fileKey[0], System.Globalization.NumberStyles.HexNumber), fileKey[1]);
                    }
                }
            }
            else
            {
                Console.WriteLine("FpkTool.txt does not exist");
            }

            //Extract files and apply names if applicable
            Console.WriteLine("Proceeding...");
            if (File.Exists(filePath))
            {
                var fpk = File.ReadAllBytes(filePath);
                using (var fileStream = new FileStream(filePath, FileMode.Open))
                    using (var streamReader = new BufferedStreamReader(fileStream, 8192))
                    {
                        List <FileEntry> table = new List <FileEntry>();

                        streamReader.Seek(0xC, SeekOrigin.Begin);
                        streamReader.Read <UInt32>(out UInt32 entryCount);

                        for (int i = 0; i < entryCount; i++)
                        {
                            streamReader.Read(out FileEntry value);
                            table.Add(value);
                        }
                        long tableEnd = streamReader.Position();

                        foreach (FileEntry entry in table)
                        {
                            storeDict.Add(entry.Hash, streamReader.ReadBytes(entry.Offset + tableEnd, (int)entry.Length));
                        }
                    }

                var outputDirectory = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));
                Directory.CreateDirectory(outputDirectory + "_");
                using (StreamWriter fpkList = new StreamWriter(outputDirectory + ".txt"))
                {
                    foreach (var file in storeDict)
                    {
                        string name;
                        if (fileDict.ContainsKey(file.Key))
                        {
                            name = fileDict[file.Key];
                        }
                        else
                        {
                            name = file.Key.ToString("X") + ".lua";
                        }
                        var fileOutput = Path.Combine(outputDirectory + "_", $"{name}");
                        File.WriteAllBytes(fileOutput, file.Value);
                        fpkList.WriteLine(file.Key.ToString("X") + " " + name);
                    }
                }
            }
        }
Ejemplo n.º 18
0
#pragma warning disable 1591

        public void ReadEncapsulatedPixelDataFrame(Action <BufferedStreamReader> decodeFrame)
        {
            if (!TryReadItemTagOfSequenceWithUndefinedLength())
            {
                throw new Exception($"Expected fragment {DicomTag.Item} but got {CurrentTag}");
            }

            if (ValueLength == UndefinedLength)
            {
                throw new Exception($"Fragment {DicomTag.Item} may not have undefined length");
            }

            if (ValueLength > Input.BytesRemaining)
            {
                throw new Exception($"Fragment {DicomTag.Item} length exceeds input");
            }

            if (ValueLength == Input.BytesRemaining)
            {
                Input.Read(ValueLength, () =>
                {
                    decodeFrame(Input);

                    // Pixel data decoding may end at an uneven byte boundary.
                    // In this case there will be one padding byte left to read

                    if (Input.BytesRemaining == 1)
                    {
                        Input.SkipRemainingBytes();
                    }
                });
            }
            else
            {
                if (Input.BytesRemaining > int.MaxValue)
                {
                    throw new NotSupportedException($"Multi-fragment frame length {Input.BytesRemaining} not supported");
                }

                var buffer = ArrayPool <byte> .Shared.Rent((int)Input.BytesRemaining);

                try
                {
                    var n = 0;
                    do
                    {
                        var fragmentLength = checked ((int)ValueLength);
                        Input.ReadAll(buffer.AsSpan(n, fragmentLength));
                        EndReadValue();
                        n += fragmentLength;
                    }while (TryReadItemTagOfSequenceWithUndefinedLength());

                    var bufferReader = new BufferedStreamReader(buffer, n);
                    decodeFrame.Invoke(bufferReader);
                }
                finally
                {
                    ArrayPool <byte> .Shared.Return(buffer, clearArray : true);
                }
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates a new Json entry given a DAT file entry.
 /// </summary>
 public JsonFileEntry(DatFileEntry entry, BufferedStreamReader stream, Func <int, int> memoryToRawAddress)
 {
     Name      = entry.GetName(stream, memoryToRawAddress);
     SizeBytes = entry.SizeBytes;
     Offset    = entry.Sector * DatFileEntry.SECTOR_SIZE_BYTES;
 }
Ejemplo n.º 20
0
 public LexerContext(Lexer prod, BufferedStreamReader reader) : base(prod)
 {
     this.reader = reader;
 }
Ejemplo n.º 21
0
        /// <summary>Creates a DicomStreamReader for reading DICOM data elements from a stream using the given transfer syntax</summary>
        public static DicomStreamReader Create(BufferedStreamReader input, DicomUID transferSyntaxUID)
        {
            var transferSyntax = new DicomTransferSyntax(transferSyntaxUID);

            return(new DicomStreamReader(input, transferSyntax));
        }
Ejemplo n.º 22
0
 public ConcreteSolver(BufferedStreamReader reader, FormattedStreamWriter writer)
 {
     this.reader = reader;
     this.writer = writer;
 }
Ejemplo n.º 23
0
        //Takes in bytes of a *n.rel file from PSO
        //To convert to PSO2's units, we set the scale to 1/10th scale
        public PSONRelConvert(byte[] file, string fileName = null, float scale = 0.1f, string outFolder = null)
        {
            fileSize  = file.Length;
            rootScale = scale;
            List <dSection> dSections = new List <dSection>();

            streamReader = new BufferedStreamReader(new MemoryStream(file), 8192);

            //Get header offset
            streamReader.Seek(file.Length - 0x10, SeekOrigin.Begin);

            //Check Endianness. No offset should ever come close to half of the int max value.
            be = streamReader.PeekBigEndianPrimitiveUInt32() < streamReader.Peek <uint>();
            if (be)
            {
                MessageBox.Show("Sorry, Gamecube n.rel files are not supported at this time.");
            }
            uint tableOfs = streamReader.ReadBE <uint>(be);

            //Read header
            streamReader.Seek(tableOfs, SeekOrigin.Begin);
            var header = ReadRelHeader(streamReader, be);

            //Read draw Sections
            streamReader.Seek(header.drawOffset, SeekOrigin.Begin);
            for (int i = 0; i < header.drawCount; i++)
            {
                dSection section = new dSection();
                section.id  = streamReader.ReadBE <int>(be);
                section.pos = streamReader.ReadBEV3(be);
                var rotX = streamReader.ReadBE <int>(be);
                var rotY = streamReader.ReadBE <int>(be);
                var rotZ = streamReader.ReadBE <int>(be);
                section.rot            = new Vector3((float)(rotX * BAMSvalue), (float)(rotY * BAMSvalue), (float)(rotZ * BAMSvalue));
                section.radius         = streamReader.ReadBE <float>(be);
                section.staticOffset   = streamReader.ReadBE <uint>(be);
                section.animatedOffset = streamReader.ReadBE <uint>(be);
                section.staticCount    = streamReader.ReadBE <uint>(be);
                section.animatedCount  = streamReader.ReadBE <uint>(be);
                section.end            = streamReader.ReadBE <uint>(be);

                dSections.Add(section);
            }

            //Get texture names
            streamReader.Seek(header.nameInfoOffset, SeekOrigin.Begin);
            var nameOffset = streamReader.ReadBE <uint>(be);
            var nameCount  = streamReader.ReadBE <uint>(be);

            streamReader.Seek(nameOffset, SeekOrigin.Begin);
            List <uint> nameOffsets = new List <uint>();

            for (int i = 0; i < nameCount; i++)
            {
                nameOffsets.Add(streamReader.ReadBE <uint>(be));
                var unk0 = streamReader.ReadBE <uint>(be);
                var unk1 = streamReader.ReadBE <uint>(be);

                if (unk0 != 0)
                {
                    Console.WriteLine($"Iteration {i} unk0 == {unk0}");
                }
                if (unk1 != 0)
                {
                    Console.WriteLine($"Iteration {i} unk1 == {unk1}");
                }
            }
            foreach (uint offset in nameOffsets)
            {
                streamReader.Seek(offset, SeekOrigin.Begin);
                texNames.Add(AquaObjectMethods.ReadCString(streamReader));
            }

            //If there's an .xvm, dump that too with texture names from the .rel
            if (fileName != null)
            {
                //Naming patterns for *n.rel files are *_12n.rel for example or *n.rel  vs *.xvm. We can determine which we have, edit, and proceed
                var    basename = fileName.Substring(0, fileName.Length - 5);
                string xvmName  = null;

                if (basename.ElementAt(basename.Length - 3) == '_')
                {
                    xvmName = basename.Substring(0, basename.Length - 3) + ".xvm";
                }
                else
                {
                    xvmName = basename + ".xvm";
                }

                ExtractXVM(xvmName, texNames, outFolder);
            }



            //Create root AQN node
            NODE aqNode = new NODE();

            aqNode.animatedFlag = 1;
            aqNode.parentId     = -1;
            aqNode.unkNode      = -1;
            aqNode.pos          = new Vector3();
            aqNode.eulRot       = new Vector3();
            aqNode.scale        = new Vector3(1, 1, 1);
            aqNode.m1           = new Vector4(1, 0, 0, 0);
            aqNode.m2           = new Vector4(0, 1, 0, 0);
            aqNode.m3           = new Vector4(0, 0, 1, 0);
            aqNode.m4           = new Vector4(0, 0, 0, 1);
            aqNode.boneName.SetString("RootNode");
            nodes.Add(aqNode);

            //Loop through nodes and parse geometry
            for (int i = 0; i < dSections.Count; i++)
            {
                var matrix = Matrix4x4.Identity;

                matrix *= Matrix4x4.CreateScale(1, 1, 1);

                var rotation = Matrix4x4.CreateRotationX(dSections[i].rot.X) *
                               Matrix4x4.CreateRotationY(dSections[i].rot.Y) *
                               Matrix4x4.CreateRotationZ(dSections[i].rot.Z);

                matrix *= rotation;

                matrix *= Matrix4x4.CreateTranslation(dSections[i].pos * rootScale);

                //Read static meshes
                List <staticMeshOffset> staticMeshOffsets = new List <staticMeshOffset>();
                streamReader.Seek(dSections[i].staticOffset, SeekOrigin.Begin);
                for (int st = 0; st < dSections[i].staticCount; st++)
                {
                    staticMeshOffsets.Add(ReadStaticMeshOffset(streamReader, be));
                }
                for (int ofs = 0; ofs < staticMeshOffsets.Count; ofs++)
                {
                    streamReader.Seek(staticMeshOffsets[ofs].offset, SeekOrigin.Begin);
                    readNode(matrix, 0);
                }


                //Read animated meshes
                List <animMeshOffset> animatedMeshOffsets = new List <animMeshOffset>();
                streamReader.Seek(dSections[i].animatedOffset, SeekOrigin.Begin);
                for (int st = 0; st < dSections[i].animatedCount; st++)
                {
                    animatedMeshOffsets.Add(ReadAnimMeshOffset(streamReader, be));
                }
                for (int ofs = 0; ofs < animatedMeshOffsets.Count; ofs++)
                {
                    streamReader.Seek(animatedMeshOffsets[ofs].offset, SeekOrigin.Begin);
                    readNode(matrix, 0);
                }
            }

            //Set material names
            for (int i = 0; i < aqObj.tempMats.Count; i++)
            {
                aqObj.tempMats[i].matName = $"PSOMat {i}";
            }
        }
Ejemplo n.º 24
0
 public void BufferedStreamReaderGetStructManaged(BufferedStreamReader bufferedStreamReader, out int randomInt)
 {
     bufferedStreamReader.Read(out randomInt, true);
 }
 /// <summary>
 /// Gets the data belonging to an individual file.
 /// </summary>
 /// <param name="file">The file to get the data from.</param>
 public byte[] GetFile(UnpackTextureFile file)
 {
     using var streamReader = new BufferedStreamReader(_stream, 2048);
     return(streamReader.ReadBytes(file.Offset, file.Size));
 }
 /// <summary>
 /// Constructs a <see cref="EndianStreamReader"/> given an existing stream reader.
 /// </summary>
 public LittleEndianStreamReader(BufferedStreamReader streamReader) : base(streamReader)
 {
 }
 /// <summary>
 /// Constructs a <see cref="EndianStreamReader"/> given an existing stream reader.
 /// </summary>
 public LittleEndianStreamReader(BufferedStreamReader streamReader, bool disposeUnderlyingStream = true) : base(streamReader, disposeUnderlyingStream)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Converts the name behind the pointer to a string.
 /// </summary>
 public string GetName(BufferedStreamReader streamReader, Func <int, int> memoryToRawAddress)
 {
     return(Utilities.Utilities.GetString(streamReader, (long)memoryToRawAddress(NamePtr), Encoding.ASCII));
 }