2019-01-30 06:36:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
using RobloxFiles.DataTypes;
|
|
|
|
|
|
2021-02-25 20:09:54 +00:00
|
|
|
|
namespace RobloxFiles.Tokens
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
|
|
|
|
public class ContentToken : IXmlPropertyToken
|
|
|
|
|
{
|
2021-02-25 20:09:54 +00:00
|
|
|
|
public string XmlPropertyToken => "Content";
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2019-05-17 12:08:06 +00:00
|
|
|
|
public bool ReadProperty(Property prop, XmlNode token)
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
string data = token.InnerText;
|
|
|
|
|
prop.Value = new Content(data);
|
2019-01-30 06:36:56 +00:00
|
|
|
|
prop.Type = PropertyType.String;
|
|
|
|
|
|
|
|
|
|
if (token.HasChildNodes)
|
|
|
|
|
{
|
|
|
|
|
XmlNode childNode = token.FirstChild;
|
|
|
|
|
string contentType = childNode.Name;
|
|
|
|
|
|
|
|
|
|
if (contentType.StartsWith("binary") || contentType == "hash")
|
|
|
|
|
{
|
2019-05-25 23:45:54 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Roblox technically doesn't support this anymore, but load it anyway :P
|
2019-06-30 22:01:19 +00:00
|
|
|
|
byte[] buffer = Convert.FromBase64String(data);
|
2019-05-25 23:45:54 +00:00
|
|
|
|
prop.RawBuffer = buffer;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2021-01-20 20:45:58 +00:00
|
|
|
|
RobloxFile.LogError($"ContentToken: Got illegal base64 string: {data}");
|
2019-05-25 23:45:54 +00:00
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
|
|
|
|
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
|
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
string content = prop.CastValue<Content>();
|
2019-05-17 12:08:06 +00:00
|
|
|
|
string type = "null";
|
|
|
|
|
|
|
|
|
|
if (prop.HasRawBuffer)
|
|
|
|
|
type = "binary";
|
|
|
|
|
else if (content.Length > 0)
|
|
|
|
|
type = "url";
|
|
|
|
|
|
|
|
|
|
XmlElement contentType = doc.CreateElement(type);
|
|
|
|
|
|
2019-05-25 23:45:54 +00:00
|
|
|
|
if (type == "binary")
|
|
|
|
|
{
|
|
|
|
|
XmlCDataSection cdata = doc.CreateCDataSection(content);
|
|
|
|
|
contentType.AppendChild(cdata);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
contentType.InnerText = content;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-17 12:08:06 +00:00
|
|
|
|
node.AppendChild(contentType);
|
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|