using System;
using System.IO;
namespace pkNX.Containers;
public static class Container
{
///
/// Gets a new for the provided and type.
///
/// File location
/// File type
public static IFileContainer GetContainer(string path, ContainerType t)
{
return t switch
{
ContainerType.GARC => new GARC(path),
ContainerType.Mini => MiniUtil.GetMini(path),
ContainerType.SARC => new SARC(path),
ContainerType.Folder => new FolderContainer(path),
ContainerType.SingleFile => new SingleFileContainer(path),
ContainerType.GFPack => new GFPack(path),
_ => throw new ArgumentOutOfRangeException(nameof(t), t, null),
};
}
///
/// Gets a for the stream.
///
/// Path to the binary data
public static IFileContainer? GetContainer(string path)
{
var fs = new FileStream(path, FileMode.Open);
var container = GetContainer(fs);
if (container is not LargeContainer) // not kept
fs.Dispose();
if (container == null)
return null;
container.FilePath = path;
return container;
}
///
/// Gets a for the stream.
///
/// Stream for the binary data
public static IFileContainer? GetContainer(Stream stream)
{
var br = new BinaryReader(stream);
var container = GetContainer(br);
if (container is not LargeContainer) // not kept
br.Dispose();
return container;
}
///
/// Gets a for the stream within the .
///
/// Reader for the binary data
public static IFileContainer? GetContainer(BinaryReader br)
{
IFileContainer? container;
if ((container = GARC.GetGARC(br)) != null)
return container;
if ((container = MiniUtil.GetMini(br)) != null)
return container;
if ((container = SARC.GetSARC(br)) != null)
return container;
return null;
}
}