mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
(PAZ): use MultiFileArchive class.
This commit is contained in:
parent
48d741c37c
commit
61fe953b46
@ -39,48 +39,28 @@ namespace GameRes.Formats.Musica
|
||||
public byte[] Key;
|
||||
}
|
||||
|
||||
internal abstract class PazArchiveBase : ArcFile
|
||||
internal abstract class PazArchiveBase : MultiFileArchive
|
||||
{
|
||||
public readonly int Version;
|
||||
public readonly byte XorKey;
|
||||
|
||||
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;
|
||||
XorKey = key;
|
||||
m_parts = parts;
|
||||
}
|
||||
|
||||
IReadOnlyList<ArcView> m_parts;
|
||||
|
||||
public IEnumerable<ArcView> Parts
|
||||
protected override uint GetEntrySize (Entry entry)
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return File;
|
||||
if (m_parts != null)
|
||||
foreach (var part in m_parts)
|
||||
yield return part;
|
||||
}
|
||||
var pent = entry as PazEntry;
|
||||
if (pent != null)
|
||||
return pent.AlignedSize;
|
||||
else
|
||||
return entry.Size;
|
||||
}
|
||||
|
||||
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
|
||||
@ -290,32 +270,9 @@ namespace GameRes.Formats.Musica
|
||||
if (null == parc || null == pent)
|
||||
return base.OpenEntry (arc, entry);
|
||||
|
||||
Stream input = null;
|
||||
Stream input = parc.OpenStream (entry);
|
||||
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)
|
||||
input = new XoredStream (input, parc.XorKey);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user