using System;
using System.IO;
using System.Text;
using RobloxFiles.BinaryFormat;
using RobloxFiles.XmlFormat;
namespace RobloxFiles
{
///
/// Interface which represents a RobloxFile implementation.
///
public interface IRobloxFile
{
Instance Contents { get; }
void ReadFile(byte[] buffer);
}
///
/// Represents a loaded *.rbxl/*.rbxm Roblox file.
/// All of the surface-level Instances are stored in the RobloxFile's Trunk property.
///
public class RobloxFile : IRobloxFile
{
public bool Initialized { get; private set; }
public IRobloxFile InnerFile { get; private set; }
public Instance Contents => InnerFile.Contents;
public void ReadFile(byte[] buffer)
{
if (!Initialized)
{
if (buffer.Length > 14)
{
string header = Encoding.UTF7.GetString(buffer, 0, 14);
IRobloxFile file = null;
if (header == BinaryRobloxFile.MagicHeader)
file = new BinaryRobloxFile();
else if (header.StartsWith("
/// Treats the provided string as if you were indexing a specific child or descendant of the `RobloxFile.Contents` folder.
/// The provided string can either be:
/// - The name of a child that is parented to RobloxFile.Contents ( Example: RobloxFile["Workspace"] )
/// - A period (.) separated path to a descendant of RobloxFile.Contents ( Example: RobloxFile["Workspace.Terrain"] )
/// This will throw an exception if any instance in the traversal is not found.
///
public Instance this[string accessor] => Contents[accessor];
}
}