mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
BinaryPropertyListWriter: Allow for multiple occurences of the same UID, to maintain compatibility with the Apple binary format
This commit is contained in:
@@ -24,7 +24,9 @@
|
|||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
|
||||||
namespace Claunia.PropertyList
|
namespace Claunia.PropertyList
|
||||||
{
|
{
|
||||||
@@ -162,7 +164,7 @@ namespace Claunia.PropertyList
|
|||||||
long count;
|
long count;
|
||||||
|
|
||||||
// map from object to its ID
|
// map from object to its ID
|
||||||
Dictionary<NSObject, int> idMap = new Dictionary<NSObject, int>();
|
Collection<NSObject> idMap = new Collection<NSObject>(); //(new IdentityEqualityComparer<NSObject>());
|
||||||
int idSizeInBytes;
|
int idSizeInBytes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -220,10 +222,10 @@ namespace Claunia.PropertyList
|
|||||||
long[] offsets = new long[idMap.Count];
|
long[] offsets = new long[idMap.Count];
|
||||||
|
|
||||||
// write each object, save offset
|
// write each object, save offset
|
||||||
foreach (KeyValuePair<NSObject, int> entry in idMap)
|
for(int i = 0; i < idMap.Count; i++)
|
||||||
{
|
{
|
||||||
NSObject obj = entry.Key;
|
NSObject obj = idMap[i];
|
||||||
int id = entry.Value;
|
int id = i;
|
||||||
offsets[id] = count;
|
offsets[id] = count;
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
@@ -255,8 +257,7 @@ namespace Claunia.PropertyList
|
|||||||
// number of objects
|
// number of objects
|
||||||
WriteLong(idMap.Count);
|
WriteLong(idMap.Count);
|
||||||
// top object
|
// top object
|
||||||
int rootID;
|
int rootID = idMap.IndexOf(root);
|
||||||
idMap.TryGetValue(root, out rootID);
|
|
||||||
WriteLong(rootID);
|
WriteLong(rootID);
|
||||||
// offset table offset
|
// offset table offset
|
||||||
WriteLong(offsetTableOffset);
|
WriteLong(offsetTableOffset);
|
||||||
@@ -267,17 +268,28 @@ namespace Claunia.PropertyList
|
|||||||
|
|
||||||
internal void AssignID(NSObject obj)
|
internal void AssignID(NSObject obj)
|
||||||
{
|
{
|
||||||
if (!idMap.ContainsKey(obj))
|
if(obj is UID)
|
||||||
{
|
{
|
||||||
idMap.Add(obj, idMap.Count);
|
idMap.Add(obj);
|
||||||
|
}
|
||||||
|
else if(!idMap.Contains(obj))
|
||||||
|
{
|
||||||
|
idMap.Add(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal int GetID(NSObject obj)
|
internal int GetID(NSObject obj)
|
||||||
{
|
{
|
||||||
int ID;
|
if (obj is UID)
|
||||||
idMap.TryGetValue(obj, out ID);
|
{
|
||||||
return ID;
|
var uid = obj as UID;
|
||||||
|
var first = idMap.OfType<UID>().First(v => NSObject.ArrayEquals(v.Bytes, uid.Bytes));
|
||||||
|
return idMap.IndexOf(first);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return idMap.IndexOf(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ComputeIdSizeInBytes(int numberOfIds)
|
static int ComputeIdSizeInBytes(int numberOfIds)
|
||||||
|
|||||||
Reference in New Issue
Block a user