2020-07-13 01:19:30 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
2021-02-25 20:09:54 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
using RobloxFiles.DataTypes;
|
2021-02-25 20:09:54 +00:00
|
|
|
|
using RobloxFiles.XmlFormat;
|
2019-01-30 06:36:56 +00:00
|
|
|
|
|
2021-02-25 20:09:54 +00:00
|
|
|
|
namespace RobloxFiles.Tokens
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
public class ProtectedStringToken : IXmlPropertyToken
|
2019-01-30 06:36:56 +00:00
|
|
|
|
{
|
2021-02-25 20:09:54 +00:00
|
|
|
|
public string XmlPropertyToken => "ProtectedString";
|
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
|
|
|
|
ProtectedString contents = token.InnerText;
|
2021-05-01 22:40:09 +00:00
|
|
|
|
prop.Type = PropertyType.String;
|
|
|
|
|
prop.Value = contents.ToString();
|
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)
|
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
ProtectedString value = prop.CastValue<ProtectedString>();
|
2019-05-17 12:08:06 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
if (value.IsCompiled)
|
2019-05-17 12:08:06 +00:00
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
var binary = XmlPropertyTokens.GetHandler<BinaryStringToken>();
|
|
|
|
|
binary.WriteProperty(prop, doc, node);
|
2019-05-17 12:08:06 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
string contents = Encoding.UTF8.GetString(value.RawBuffer);
|
|
|
|
|
|
|
|
|
|
if (contents.Contains("\r") || contents.Contains("\n"))
|
|
|
|
|
{
|
|
|
|
|
XmlCDataSection cdata = doc.CreateCDataSection(contents);
|
|
|
|
|
node.AppendChild(cdata);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
node.InnerText = contents;
|
|
|
|
|
}
|
2019-05-17 12:08:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-30 06:36:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|