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.
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Claunia.PropertyList
|
||||
{
|
||||
@@ -162,7 +164,7 @@ namespace Claunia.PropertyList
|
||||
long count;
|
||||
|
||||
// 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;
|
||||
|
||||
/// <summary>
|
||||
@@ -220,10 +222,10 @@ namespace Claunia.PropertyList
|
||||
long[] offsets = new long[idMap.Count];
|
||||
|
||||
// write each object, save offset
|
||||
foreach (KeyValuePair<NSObject, int> entry in idMap)
|
||||
for(int i = 0; i < idMap.Count; i++)
|
||||
{
|
||||
NSObject obj = entry.Key;
|
||||
int id = entry.Value;
|
||||
NSObject obj = idMap[i];
|
||||
int id = i;
|
||||
offsets[id] = count;
|
||||
if (obj == null)
|
||||
{
|
||||
@@ -255,8 +257,7 @@ namespace Claunia.PropertyList
|
||||
// number of objects
|
||||
WriteLong(idMap.Count);
|
||||
// top object
|
||||
int rootID;
|
||||
idMap.TryGetValue(root, out rootID);
|
||||
int rootID = idMap.IndexOf(root);
|
||||
WriteLong(rootID);
|
||||
// offset table offset
|
||||
WriteLong(offsetTableOffset);
|
||||
@@ -267,17 +268,28 @@ namespace Claunia.PropertyList
|
||||
|
||||
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)
|
||||
{
|
||||
int ID;
|
||||
idMap.TryGetValue(obj, out ID);
|
||||
return ID;
|
||||
if (obj is UID)
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user