mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(S25.Reader): dispose of underlying stream when needed.
This commit is contained in:
@@ -75,7 +75,7 @@ namespace GameRes.Formats.ShiinaRio
|
|||||||
|
|
||||||
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
public override ImageData Read (IBinaryStream stream, ImageMetaData info)
|
||||||
{
|
{
|
||||||
using (var reader = new Reader (stream, (S25MetaData)info))
|
using (var reader = new Reader (stream, (S25MetaData)info, true))
|
||||||
return reader.Image;
|
return reader.Image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +92,7 @@ namespace GameRes.Formats.ShiinaRio
|
|||||||
uint m_origin;
|
uint m_origin;
|
||||||
byte[] m_output;
|
byte[] m_output;
|
||||||
bool m_incremental;
|
bool m_incremental;
|
||||||
|
bool m_should_dispose;
|
||||||
ImageMetaData m_info;
|
ImageMetaData m_info;
|
||||||
ImageData m_image;
|
ImageData m_image;
|
||||||
|
|
||||||
@@ -114,7 +115,7 @@ namespace GameRes.Formats.ShiinaRio
|
|||||||
|
|
||||||
public byte[] Data { get { return m_output; } }
|
public byte[] Data { get { return m_output; } }
|
||||||
|
|
||||||
public Reader (IBinaryStream file, S25MetaData info)
|
public Reader (IBinaryStream file, S25MetaData info, bool leave_open = false)
|
||||||
{
|
{
|
||||||
m_width = (int)info.Width;
|
m_width = (int)info.Width;
|
||||||
m_height = (int)info.Height;
|
m_height = (int)info.Height;
|
||||||
@@ -123,6 +124,7 @@ namespace GameRes.Formats.ShiinaRio
|
|||||||
m_origin = info.FirstOffset;
|
m_origin = info.FirstOffset;
|
||||||
m_incremental = info.Incremental;
|
m_incremental = info.Incremental;
|
||||||
m_info = info;
|
m_info = info;
|
||||||
|
m_should_dispose = !leave_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] Unpack ()
|
public byte[] Unpack ()
|
||||||
@@ -369,8 +371,17 @@ namespace GameRes.Formats.ShiinaRio
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region IDisposable Members
|
#region IDisposable Members
|
||||||
|
bool m_disposed = false;
|
||||||
public void Dispose ()
|
public void Dispose ()
|
||||||
{
|
{
|
||||||
|
if (!m_disposed)
|
||||||
|
{
|
||||||
|
if (m_should_dispose)
|
||||||
|
{
|
||||||
|
m_input.Dispose();
|
||||||
|
}
|
||||||
|
m_disposed = true;
|
||||||
|
}
|
||||||
GC.SuppressFinalize (this);
|
GC.SuppressFinalize (this);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user