Exemplo n.º 1
0
        private Object ReadAsset(AssetStream stream, AssetInfo assetInfo, long offset, int size)
        {
            Object asset = Collection.AssetFactory.CreateAsset(assetInfo);

            if (asset == null)
            {
                return(null);
            }

            stream.BaseStream.Position = offset;
            if (Config.IsGenerateGUIDByContent)
            {
                byte[] data = stream.ReadBytes(size);
                asset.Read(data);

                using (MD5 md5 = MD5.Create())
                {
                    byte[] md5Hash = md5.ComputeHash(data);
                    assetInfo.GUID = new UtinyGUID(md5Hash);
                }
            }
            else
            {
                stream.AlignPosition = offset;
                asset.Read(stream);
                long read = stream.BaseStream.Position - offset;
                if (read != size)
                {
                    throw new Exception($"Read {read} but expected {size} for object {asset.GetType().Name}");
                }
            }
            return(asset);
        }
Exemplo n.º 2
0
        private Object ReadAsset(AssetReader reader, AssetInfo assetInfo, long offset, int size)
        {
            Object asset = Collection.AssetFactory.CreateAsset(assetInfo);

            if (asset == null)
            {
                return(null);
            }

            reader.BaseStream.Position = offset;
            if (Config.IsGenerateGUIDByContent)
            {
                byte[] data = reader.ReadBytes(size);
#if !DEBUG
                try
#endif
                {
                    asset.Read(data);
                }
#if !DEBUG
                catch
                {
                    Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{reader.Version}] '{Name}'");
                    throw;
                }
#endif

                using (MD5 md5 = MD5.Create())
                {
                    byte[] md5Hash = md5.ComputeHash(data);
                    assetInfo.GUID = new EngineGUID(md5Hash);
                }
            }
            else
            {
                using (AssetReader alignReader = new AssetReader(reader, offset))
                {
#if !DEBUG
                    try
#endif
                    {
                        asset.Read(alignReader);
                    }
#if !DEBUG
                    catch
                    {
                        Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{reader.Version}] '{Name}'");
                        throw;
                    }
#endif
                }
                long read = reader.BaseStream.Position - offset;
                if (read != size)
                {
                    throw new Exception($"Read {read} but expected {size} for asset type {asset.ClassID}. Version[{reader.Version}] '{Name}'");
                }
            }
            return(asset);
        }