Skip to content

Commit

Permalink
Add Idx.IsValid
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed Nov 16, 2019
1 parent a245b58 commit 96c9804
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions OpenKh.Kh2/Idx.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using OpenKh.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -98,6 +99,9 @@ [Data] public int Length

[Data] public List<Entry> Items { get; set; }

public static bool IsValid(Stream stream) =>
stream.Length == new BinaryReader(stream.SetPosition(0)).ReadInt32() * 0x10 + 4;

/// <summary>
/// Deserialize an IDX from a stream
/// </summary>
Expand All @@ -106,14 +110,14 @@ [Data] public int Length
public static Idx Read(Stream stream)
{
BinaryMapping.SetMemberLengthMapping<Idx>(nameof(Items), (o, m) => o.Length);
return BinaryMapping.ReadObject<Idx>(stream);
return BinaryMapping.ReadObject<Idx>(stream.SetPosition(0));
}

/// <summary>
/// Serialize an IDX to a stream
/// </summary>
/// <param name="stream">Writable stream that will contain the IDX data</param>
public void Write(Stream stream) => BinaryMapping.WriteObject(stream, this);
public void Write(Stream stream) => BinaryMapping.WriteObject(stream.SetPosition(0), this);

/// <summary>
/// Try to get an entry form a file name
Expand Down

0 comments on commit 96c9804

Please sign in to comment.