Roblox-File-Format/XmlFormat/Tokens/SharedString.cs

38 lines
972 B
C#
Raw Normal View History

using System.Xml;
using RobloxFiles.DataTypes;
namespace RobloxFiles.XmlFormat.PropertyTokens
{
public class SharedStringToken : IXmlPropertyToken
{
public string Token => "SharedString";
public bool ReadProperty(Property prop, XmlNode token)
{
string key = token.InnerText;
prop.Type = PropertyType.SharedString;
prop.Value = new SharedString(key);
return true;
}
public void WriteProperty(Property prop, XmlDocument doc, XmlNode node)
{
2020-08-18 01:12:24 +00:00
var value = prop.Value as SharedString;
2020-08-18 01:12:24 +00:00
if (value != null)
{
2020-08-18 01:12:24 +00:00
string key = value.Key;
if (value.ComputedKey == null)
{
var newShared = SharedString.FromBuffer(value.SharedValue);
key = newShared.ComputedKey;
}
2020-08-18 01:12:24 +00:00
node.InnerText = key;
}
}
}
}