private Object ReadAsset(EndianReader 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[{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, Version, Platform, Flags)) { #if !DEBUG try #endif { asset.Read(alignReader); } #if !DEBUG catch { Logger.Instance.Log(LogType.Error, LogCategory.General, $"Version[{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[{Version}] '{Name}'"); } } return(asset); }
private Object ReadAsset(EndianReader 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 (Exception ex) { throw new SerializedFileException($"Error during reading asset type {asset.ClassID}", ex, Version, Name, FilePath); } #endif using (MD5 md5 = MD5.Create()) { byte[] md5Hash = md5.ComputeHash(data); assetInfo.GUID = new EngineGUID(md5Hash); } } else { using (AssetReader alignReader = new AssetReader(reader, Version, Platform, Flags)) { #if !DEBUG try #endif { asset.Read(alignReader); } #if !DEBUG catch (Exception ex) { throw new SerializedFileException($"Error during reading asset type {asset.ClassID}", ex, Version, Name, FilePath); } #endif } long read = reader.BaseStream.Position - offset; if (read != size) { throw new SerializedFileException($"Read {read} but expected {size} for asset type {asset.ClassID}", Version, Name, FilePath); } } return(asset); }
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 !DEBUG try #endif { asset.Read(reader); } #if !DEBUG catch (Exception ex) { throw new SerializedFileException($"Error during reading of asset type {asset.ClassID}", ex, Version, Platform, asset.ClassID, Name, FilePath); } #endif long read = reader.BaseStream.Position - offset; if (read != size) { throw new SerializedFileException($"Read {read} but expected {size} for asset type {asset.ClassID}", Version, Platform, asset.ClassID, Name, FilePath); } return(asset); }