2015-02-17 23:40:44 +00:00
|
|
|
|
// plist-cil - An open source library to parse and generate property lists for .NET
|
|
|
|
|
|
// Copyright (C) 2015 Natalia Portillo
|
|
|
|
|
|
//
|
|
|
|
|
|
// This code is based on:
|
|
|
|
|
|
// plist - An open source library to parse and generate property lists
|
|
|
|
|
|
// Copyright (C) 2014 Daniel Dreibrodt
|
|
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
|
// SOFTWARE.
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Claunia.PropertyList
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2015-02-20 03:45:45 +00:00
|
|
|
|
/// An UID. Only found in binary property lists that are keyed archives.
|
2015-02-17 23:40:44 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// @author Daniel Dreibrodt
|
2015-02-19 23:54:19 +00:00
|
|
|
|
/// @author Natalia Portillo
|
2015-02-17 23:40:44 +00:00
|
|
|
|
public class UID : NSObject
|
|
|
|
|
|
{
|
2015-02-20 00:42:40 +00:00
|
|
|
|
readonly byte[] bytes;
|
|
|
|
|
|
readonly string name;
|
2015-02-17 23:40:44 +00:00
|
|
|
|
|
2015-02-20 02:23:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="Claunia.PropertyList.UID"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name">Name.</param>
|
|
|
|
|
|
/// <param name="bytes">Bytes.</param>
|
2015-02-17 23:40:44 +00:00
|
|
|
|
public UID(String name, byte[] bytes)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.name = name;
|
|
|
|
|
|
this.bytes = bytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-20 02:23:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the bytes.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The bytes.</value>
|
2015-02-17 23:40:44 +00:00
|
|
|
|
public byte[] Bytes
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return bytes;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-20 02:23:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <value>The name.</value>
|
2015-02-17 23:40:44 +00:00
|
|
|
|
public string Name
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// There is no XML representation specified for UIDs.
|
|
|
|
|
|
/// In this implementation UIDs are represented as strings in the XML output.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="xml">The xml StringBuilder</param>
|
|
|
|
|
|
/// <param name="level">The indentation level</param>
|
2015-02-20 00:00:26 +00:00
|
|
|
|
internal override void ToXml(StringBuilder xml, int level)
|
|
|
|
|
|
{
|
2015-02-17 23:40:44 +00:00
|
|
|
|
Indent(xml, level);
|
|
|
|
|
|
xml.Append("<string>");
|
2015-02-20 00:42:40 +00:00
|
|
|
|
foreach (byte b in bytes)
|
2015-02-17 23:40:44 +00:00
|
|
|
|
xml.Append(String.Format("{0:x2}", b));
|
|
|
|
|
|
xml.Append("</string>");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-20 00:00:26 +00:00
|
|
|
|
internal override void ToBinary(BinaryPropertyListWriter outPlist)
|
|
|
|
|
|
{
|
2015-02-19 17:41:33 +00:00
|
|
|
|
outPlist.Write(0x80 + bytes.Length - 1);
|
|
|
|
|
|
outPlist.Write(bytes);
|
|
|
|
|
|
}
|
2015-02-17 23:40:44 +00:00
|
|
|
|
|
2015-02-20 00:00:26 +00:00
|
|
|
|
internal override void ToASCII(StringBuilder ascii, int level)
|
|
|
|
|
|
{
|
2015-02-17 23:40:44 +00:00
|
|
|
|
Indent(ascii, level);
|
|
|
|
|
|
ascii.Append("\"");
|
2015-02-20 00:42:40 +00:00
|
|
|
|
foreach (byte b in bytes)
|
2015-02-17 23:40:44 +00:00
|
|
|
|
ascii.Append(String.Format("{0:x2}", b));
|
|
|
|
|
|
ascii.Append("\"");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-02-20 00:00:26 +00:00
|
|
|
|
internal override void ToASCIIGnuStep(StringBuilder ascii, int level)
|
|
|
|
|
|
{
|
2015-02-17 23:40:44 +00:00
|
|
|
|
ToASCII(ascii, level);
|
|
|
|
|
|
}
|
2015-02-19 21:30:01 +00:00
|
|
|
|
|
2015-02-20 02:23:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines whether the specified <see cref="Claunia.PropertyList.NSObject"/> is equal to the current <see cref="Claunia.PropertyList.UID"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">The <see cref="Claunia.PropertyList.NSObject"/> to compare with the current <see cref="Claunia.PropertyList.UID"/>.</param>
|
|
|
|
|
|
/// <returns><c>true</c> if the specified <see cref="Claunia.PropertyList.NSObject"/> is equal to the current
|
|
|
|
|
|
/// <see cref="Claunia.PropertyList.UID"/>; otherwise, <c>false</c>.</returns>
|
2015-02-19 21:30:01 +00:00
|
|
|
|
public override bool Equals(NSObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!(obj is UID))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
if (((UID)obj).Name != name)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
return ArrayEquals(((UID)obj).Bytes, bytes);
|
|
|
|
|
|
}
|
2015-02-17 23:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|