Added write support for binary files!

Holy cow, this took a lot of work. I think I may need to do a few more
things before I consider this a 1.0 release, but I'm glad to have
finally overcome this hurdle!
This commit is contained in:
CloneTrooper1019
2019-06-07 22:43:28 -05:00
parent cb063d1ada
commit 47112242e7
22 changed files with 1405 additions and 222 deletions

View File

@ -18,17 +18,23 @@ namespace RobloxFiles
private Dictionary<string, Property> props = new Dictionary<string, Property>();
public IReadOnlyDictionary<string, Property> Properties => props;
private List<Instance> Children = new List<Instance>();
protected List<Instance> Children = new List<Instance>();
private Instance parent;
/// <summary>The name of this Instance, if a Name property is defined.</summary>
public override string ToString() => Name;
/// <summary>A unique identifier for this instance when being serialized as XML.</summary>
public string XmlReferent { get; internal set; }
/// <summary>A unique identifier for this instance when being serialized.</summary>
public string Referent { get; internal set; }
/// <summary>Indicates whether the parent of this object is locked.</summary>
public bool ParentLocked { get; protected set; }
public bool ParentLocked { get; internal set; }
/// <summary>Indicates whether this Instance is marked as a Service in the binary file format.</summary>
public bool IsService { get; internal set; }
/// <summary>If this instance is a service, this indicates whether the service should be loaded via GetService when Roblox loads the place file.</summary>
public bool IsRootedService { get; internal set; }
/// <summary>Indicates whether this object should be serialized.</summary>
public bool Archivable = true;

View File

@ -1,4 +1,6 @@
using System;
using RobloxFiles.BinaryFormat;
using RobloxFiles.BinaryFormat.Chunks;
namespace RobloxFiles
@ -47,6 +49,8 @@ namespace RobloxFiles
public string XmlToken = "";
public byte[] RawBuffer { get; internal set; }
internal BinaryRobloxFileWriter CurrentWriter;
public bool HasRawBuffer
{
get
@ -83,10 +87,9 @@ namespace RobloxFiles
public Property(string name = "", PropertyType type = PropertyType.Unknown, Instance instance = null)
{
Instance = instance;
Name = name;
Type = type;
Instance = instance;
}
public Property(Instance instance, PROP property)
@ -116,5 +119,28 @@ namespace RobloxFiles
return string.Join(" ", typeName, Name, '=', valueLabel);
}
public T CastValue<T>()
{
T result;
if (Value is T)
result = (T)Value;
else
result = default(T);
return result;
}
internal void WriteValue<T>() where T : struct
{
if (CurrentWriter == null)
throw new Exception("Property.CurrentWriter must be set to use WriteValue<T>");
T value = CastValue<T>();
byte[] bytes = BinaryRobloxFileWriter.GetBytes(value);
CurrentWriter.Write(bytes);
}
}
}