2019-01-30 06:36:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
2019-02-01 17:19:20 +00:00
|
|
|
|
namespace RobloxFiles.XmlFormat.PropertyTokens
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
|
|
|
|
public class BinaryStringToken : IXmlPropertyToken
|
|
|
|
|
{
|
|
|
|
|
public string Token => "BinaryString";
|
|
|
|
|
|
2019-05-17 12:08:06 +00:00
|
|
|
|
public bool ReadProperty(Property prop, XmlNode token)
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
|
|
|
|
// BinaryStrings are encoded in base64
|
2019-05-17 12:08:06 +00:00
|
|
|
|
string base64 = token.InnerText.Replace("\n", "");
|
2019-06-30 22:01:19 +00:00
|
|
|
|
prop.Value = Convert.FromBase64String(base64);
|
2019-01-30 06:36:56 +00:00
|
|
|
|
prop.Type = PropertyType.String;
|
2019-06-30 22:01:19 +00:00
|
|
|
|
|
2019-01-30 06:36:56 +00:00
|
|
|
|
byte[] buffer = Convert.FromBase64String(base64);
|
2019-05-19 04:44:51 +00:00
|
|
|
|
prop.RawBuffer = buffer;
|
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-05-19 04:44:51 +00:00
|
|
|
|
byte[] data = prop.RawBuffer;
|
2019-05-17 12:08:06 +00:00
|
|
|
|
string value = Convert.ToBase64String(data);
|
|
|
|
|
|
|
|
|
|
if (value.Length > 72)
|
|
|
|
|
{
|
|
|
|
|
string buffer = "";
|
|
|
|
|
|
|
|
|
|
while (value.Length > 72)
|
|
|
|
|
{
|
|
|
|
|
string chunk = value.Substring(0, 72);
|
|
|
|
|
value = value.Substring(72);
|
|
|
|
|
buffer += chunk + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = buffer + value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XmlCDataSection cdata = doc.CreateCDataSection(value);
|
|
|
|
|
node.AppendChild(cdata);
|
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|