(PAZ): use MultiFileArchive class.

This commit is contained in:
morkt 2018-08-09 08:19:08 +04:00
parent 48d741c37c
commit 61fe953b46

View File

@ -39,48 +39,28 @@ namespace GameRes.Formats.Musica
public byte[] Key; public byte[] Key;
} }
internal abstract class PazArchiveBase : ArcFile internal abstract class PazArchiveBase : MultiFileArchive
{ {
public readonly int Version; public readonly int Version;
public readonly byte XorKey; public readonly byte XorKey;
public PazArchiveBase (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, int version, byte key, IReadOnlyList<ArcView> parts = null) public PazArchiveBase (ArcView arc, ArchiveFormat impl, ICollection<Entry> dir, int version, byte key, IReadOnlyList<ArcView> parts = null)
: base (arc, impl, dir) : base (arc, impl, dir, parts)
{ {
Version = version; Version = version;
XorKey = key; XorKey = key;
m_parts = parts;
} }
IReadOnlyList<ArcView> m_parts; protected override uint GetEntrySize (Entry entry)
public IEnumerable<ArcView> Parts
{ {
get var pent = entry as PazEntry;
{ if (pent != null)
yield return File; return pent.AlignedSize;
if (m_parts != null) else
foreach (var part in m_parts) return entry.Size;
yield return part;
}
} }
internal abstract Stream DecryptEntry (Stream input, PazEntry entry); internal abstract Stream DecryptEntry (Stream input, PazEntry entry);
bool _paz_disposed = false;
protected override void Dispose (bool disposing)
{
if (_paz_disposed)
return;
if (disposing && m_parts != null)
{
foreach (var arc in m_parts)
arc.Dispose();
}
_paz_disposed = true;
base.Dispose (disposing);
}
} }
internal class PazArchive : PazArchiveBase internal class PazArchive : PazArchiveBase
@ -290,32 +270,9 @@ namespace GameRes.Formats.Musica
if (null == parc || null == pent) if (null == parc || null == pent)
return base.OpenEntry (arc, entry); return base.OpenEntry (arc, entry);
Stream input = null; Stream input = parc.OpenStream (entry);
try try
{ {
long part_offset = 0;
long entry_start = pent.Offset;
long entry_end = pent.Offset + pent.AlignedSize;
foreach (var part in parc.Parts)
{
long part_end_offset = part_offset + part.MaxOffset;
if (entry_start < part_end_offset)
{
uint part_size = (uint)Math.Min (entry_end - entry_start, part_end_offset - entry_start);
var entry_part = part.CreateStream (entry_start - part_offset, part_size);
if (input != null)
input = new ConcatStream (input, entry_part);
else
input = entry_part;
entry_start += part_size;
if (entry_start >= entry_end)
break;
}
part_offset = part_end_offset;
}
if (null == input)
return Stream.Null;
if (parc.XorKey != 0) if (parc.XorKey != 0)
input = new XoredStream (input, parc.XorKey); input = new XoredStream (input, parc.XorKey);