Optimizations and memory leak fixes
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
@ -21,13 +23,15 @@ namespace RobloxFiles.XmlFormat
|
||||
|
||||
public static string CreateReferent()
|
||||
{
|
||||
Guid referentGuid = Guid.NewGuid();
|
||||
var referentGuid = Guid
|
||||
.NewGuid()
|
||||
.ToString();
|
||||
|
||||
string referent = "RBX" + referentGuid
|
||||
.ToString()
|
||||
.ToUpper();
|
||||
.ToUpper(CultureInfo.InvariantCulture)
|
||||
.Replace("-", "");
|
||||
|
||||
return referent.Replace("-", "");
|
||||
return referent;
|
||||
}
|
||||
|
||||
private static string GetEnumName<T>(T item) where T : struct
|
||||
@ -77,7 +81,7 @@ namespace RobloxFiles.XmlFormat
|
||||
case PropertyType.Float:
|
||||
case PropertyType.Int64:
|
||||
case PropertyType.Double:
|
||||
propType = propType.ToLower();
|
||||
propType = propType.ToLower(CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case PropertyType.String:
|
||||
propType = (prop.HasRawBuffer ? "BinaryString" : "string");
|
||||
@ -166,6 +170,7 @@ namespace RobloxFiles.XmlFormat
|
||||
|
||||
public static XmlNode WriteSharedStrings(XmlDocument doc, XmlRobloxFile file)
|
||||
{
|
||||
Contract.Requires(doc != null && file != null);
|
||||
XmlElement sharedStrings = doc.CreateElement("SharedStrings");
|
||||
|
||||
var binaryWriter = XmlPropertyTokens.GetHandler<BinaryStringToken>();
|
||||
|
@ -9,9 +9,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
uint value;
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out value))
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
Axes axes = (Axes)value;
|
||||
prop.Value = axes;
|
||||
|
@ -13,9 +13,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out value))
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out int value))
|
||||
{
|
||||
BrickColor brickColor = BrickColor.FromNumber(value);
|
||||
prop.XmlToken = "BrickColor";
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
{
|
||||
@ -9,9 +11,7 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
uint value;
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out value))
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
uint r = (value >> 16) & 0xFF;
|
||||
uint g = (value >> 8) & 0xFF;
|
||||
@ -28,14 +28,16 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Color3uint8 color = prop.CastValue<Color3uint8>();
|
||||
Color3uint8 color = prop?.CastValue<Color3uint8>();
|
||||
Contract.Requires(node != null);
|
||||
|
||||
|
||||
uint r = color.R,
|
||||
g = color.G,
|
||||
b = color.B;
|
||||
|
||||
uint rgb = (255u << 24) | (r << 16) | (g << 8) | b;
|
||||
node.InnerText = rgb.ToString();
|
||||
node.InnerText = rgb.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
|
||||
@ -10,9 +11,9 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
uint value;
|
||||
Contract.Requires(prop != null);
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out value))
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
Instance inst = prop.Instance;
|
||||
Type instType = inst?.GetType();
|
||||
@ -36,13 +37,13 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Contract.Requires(prop != null && node != null);
|
||||
object rawValue = prop.Value;
|
||||
Type valueType = rawValue.GetType();
|
||||
|
||||
|
||||
int signed = (int)rawValue;
|
||||
uint value = (uint)signed;
|
||||
|
||||
node.InnerText = value.ToString();
|
||||
node.InnerText = value.ToInvariantString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Xml;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Xml;
|
||||
using RobloxFiles.DataTypes;
|
||||
|
||||
namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
@ -9,9 +10,9 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public bool ReadProperty(Property prop, XmlNode token)
|
||||
{
|
||||
uint value;
|
||||
Contract.Requires(prop != null);
|
||||
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out value))
|
||||
if (XmlPropertyTokens.ReadPropertyGeneric(token, out uint value))
|
||||
{
|
||||
Faces faces = (Faces)value;
|
||||
prop.Value = faces;
|
||||
@ -24,6 +25,8 @@ namespace RobloxFiles.XmlFormat.PropertyTokens
|
||||
|
||||
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
||||
{
|
||||
Contract.Requires(prop != null && doc != null && node != null);
|
||||
|
||||
XmlElement faces = doc.CreateElement("faces");
|
||||
node.AppendChild(faces);
|
||||
|
||||
|
@ -33,7 +33,14 @@ namespace RobloxFiles
|
||||
try
|
||||
{
|
||||
string xml = Encoding.UTF8.GetString(buffer);
|
||||
XmlDocument.LoadXml(xml);
|
||||
var settings = new XmlReaderSettings() { XmlResolver = null };
|
||||
|
||||
using (StringReader reader = new StringReader(xml))
|
||||
{
|
||||
XmlReader xmlReader = XmlReader.Create(reader, settings);
|
||||
XmlDocument.Load(xmlReader);
|
||||
xmlReader.Dispose();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -46,9 +53,8 @@ namespace RobloxFiles
|
||||
{
|
||||
// Verify the version we are using.
|
||||
XmlNode version = roblox.Attributes.GetNamedItem("version");
|
||||
int schemaVersion;
|
||||
|
||||
if (version == null || !int.TryParse(version.Value, out schemaVersion))
|
||||
|
||||
if (version == null || !int.TryParse(version.Value, out int schemaVersion))
|
||||
throw new Exception("XmlRobloxFile: No version number defined!");
|
||||
else if (schemaVersion < 4)
|
||||
throw new Exception("XmlRobloxFile: Provided version must be at least 4!");
|
||||
|
Reference in New Issue
Block a user