Exemplo n.º 1
0
        private void Read(Stream stream, Action <string> dependencyCallback)
        {
            long startPosition = stream.Position;

            using (EndianReader reader = new EndianReader(stream, stream.Position, EndianType.BigEndian))
            {
                Header.Read(reader);
            }

            EndianType endianess = Header.Endianess ? EndianType.BigEndian : EndianType.LittleEndian;

            using (EndianReader reader = new EndianReader(stream, stream.Position, endianess))
            {
                if (IsTableAtTheEnd(Header.Generation))
                {
                    reader.BaseStream.Position = startPosition + Header.FileSize - Header.MetadataSize;
                    reader.BaseStream.Position++;
                }

                using (SerializedFileReader fileReader = new SerializedFileReader(reader, Header.Generation))
                {
                    Metadata.Read(fileReader);
                }

                foreach (FileIdentifier dependency in Dependencies)
                {
                    dependencyCallback?.Invoke(dependency.FilePath);
                }

                if (RTTIClassHierarchyDescriptor.IsReadSignature(Header.Generation))
                {
                    ReadAssets(reader, startPosition);
                }
                else
                {
                    Logger.Log(LogType.Warning, LogCategory.Import, $"Can't determine file version for generation {Header.Generation} for file '{Name}'");
                    string[] versions = GetGenerationVersions(Header.Generation);
                    for (int i = 0; i < versions.Length; i++)
                    {
                        string version = versions[i];
                        Logger.Log(LogType.Debug, LogCategory.Import, $"Try parse {Name} as {version} version");
                        Version.Parse(version);
                        m_assets.Clear();
                        try
                        {
                            ReadAssets(reader, startPosition);
                            break;
                        }
                        catch
                        {
                            Logger.Log(LogType.Debug, LogCategory.Import, "Faild");
                            if (i == versions.Length - 1)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Read(Stream baseStream)
        {
            using (EndianStream stream = new EndianStream(baseStream, baseStream.Position, EndianType.BigEndian))
            {
                long startPosition = baseStream.Position;
                Header.Read(stream);

                stream.EndianType = Header.Endianess ? EndianType.BigEndian : EndianType.LittleEndian;
                if (IsTableAtTheEnd(Header.Generation))
                {
                    stream.BaseStream.Position = startPosition + Header.FileSize - Header.MetadataSize;
                    stream.BaseStream.Position++;
                }

                using (SerializedFileStream fileStream = new SerializedFileStream(stream, Header.Generation))
                {
                    Metadata.Read(fileStream);
                }

                if (RTTIClassHierarchyDescriptor.IsReadSignature(Header.Generation))
                {
                    ReadAssets(stream, startPosition);
                }
                else
                {
                    Logger.Log(LogType.Warning, LogCategory.Import, $"Can't determine file version for generation {Header.Generation} for file '{Name}'");
                    string[] versions = GetGenerationVersions(Header.Generation);
                    for (int i = 0; i < versions.Length; i++)
                    {
                        string version = versions[i];
                        Logger.Log(LogType.Debug, LogCategory.Import, $"Try parse {nameof(SerializedFile)} as {version} version");
                        Version.Parse(version);
                        try
                        {
                            ReadAssets(stream, startPosition);
                            break;
                        }
                        catch
                        {
                            Logger.Log(LogType.Debug, LogCategory.Import, "Faild");
                            if (i == versions.Length - 1)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public SerializedFileMetadata(string name)
 {
     Hierarchy = new RTTIClassHierarchyDescriptor(name);
 }