(IBinaryStream.Name): added setter.

This commit is contained in:
morkt 2016-10-16 16:15:13 +04:00
parent f38f1363a4
commit b197bb77fd

View File

@ -37,7 +37,7 @@ namespace GameRes
/// <summary> /// <summary>
/// Name of the stream (could be name of the underlying file) or an empty string. /// Name of the stream (could be name of the underlying file) or an empty string.
/// </summary> /// </summary>
string Name { get; } string Name { get; get; }
/// <summary> /// <summary>
/// First 4 bytes of the stream as a little-endian integer. /// First 4 bytes of the stream as a little-endian integer.
/// </summary> /// </summary>
@ -115,14 +115,10 @@ namespace GameRes
byte[] m_header; byte[] m_header;
int m_header_size; int m_header_size;
public string Name { get; private set; } public string Name { get; set; }
public uint Signature { get { return m_signature.Value; } } public uint Signature { get { return m_signature.Value; } }
public Stream AsStream { get { return this; } } public Stream AsStream { get { return this; } }
// public BinaryStream (Stream input, bool leave_open = false) : this (input, "", leave_open)
// {
// }
public BinaryStream (Stream input, string name, bool leave_open = false) public BinaryStream (Stream input, string name, bool leave_open = false)
{ {
m_buffer = new byte[0x10]; m_buffer = new byte[0x10];
@ -160,9 +156,12 @@ namespace GameRes
public static IBinaryStream FromStream (Stream input, string filename) public static IBinaryStream FromStream (Stream input, string filename)
{ {
if (input is IBinaryStream) var bin = input as IBinaryStream;
return input as IBinaryStream; if (null == bin)
return new BinaryStream (input, filename); bin = new BinaryStream (input, filename);
else
bin.Name = filename;
return bin;
} }
uint ReadSignature () uint ReadSignature ()
@ -339,14 +338,15 @@ namespace GameRes
{ {
var buffer = new byte[count]; var buffer = new byte[count];
int pos = 0; int pos = 0;
int cached = m_buffer_end - m_buffer_pos; int cached = Math.Min (m_buffer_end - m_buffer_pos, count);
if (cached > 0) if (cached > 0)
{ {
Buffer.BlockCopy (m_buffer, m_buffer_pos, buffer, 0, cached); Buffer.BlockCopy (m_buffer, m_buffer_pos, buffer, 0, cached);
pos = cached; pos = cached;
m_buffer_end = m_buffer_pos = 0; m_buffer_pos += cached;
count -= cached; count -= cached;
} }
if (count > 0)
pos += m_source.Read (buffer, pos, count); pos += m_source.Read (buffer, pos, count);
if (pos < buffer.Length) if (pos < buffer.Length)
{ {
@ -367,8 +367,8 @@ namespace GameRes
get { return m_source.Position - (m_buffer_end - m_buffer_pos); } get { return m_source.Position - (m_buffer_end - m_buffer_pos); }
set set
{ {
m_source.Position = value;
m_buffer_end = m_buffer_pos = 0; m_buffer_end = m_buffer_pos = 0;
m_source.Position = value;
} }
} }
@ -456,7 +456,7 @@ namespace GameRes
int m_position; int m_position;
uint m_signature; uint m_signature;
public string Name { get; private set; } public string Name { get; set; }
public uint Signature { get { return m_signature; } } public uint Signature { get { return m_signature; } }
public Stream AsStream { get { return this; } } public Stream AsStream { get { return this; } }