Roblox-File-Format/Tokens/SharedString.cs

36 lines
931 B
C#
Raw Permalink Normal View History

using System.Xml;
using RobloxFiles.DataTypes;
2021-02-25 20:09:54 +00:00
namespace RobloxFiles.Tokens
{
public class SharedStringToken : IXmlPropertyToken
{
2021-02-25 20:09:54 +00:00
public string XmlPropertyToken => "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)
{
2021-02-25 20:09:54 +00:00
if (prop.Value is SharedString value)
{
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;
}
}
}
}