Example #1
0
        public static object LoadFrom(this BinaryPropertyListReader item, byte[] data)
        {
            object result = default;

            using (var stream = new MemoryStream(data, false))
            {
                result = item.LoadFrom(stream);
            }

            return(result);
        }
Example #2
0
        public static object LoadFrom(this BinaryPropertyListReader item, string path)
        {
            object result = default;

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                result = item.LoadFrom(stream);
            }

            return(result);
        }
        public static object LoadFrom(this BinaryPropertyListReader item, Stream stream)
        {
            PropertyContext result = default;

            using (var reader = new BinaryReader(stream))
            {
                result = item.LoadFrom(reader);
            }

            return(result.Value);
        }
Example #4
0
        public static object LoadFrom(this BinaryPropertyListReader item, Stream stream)
        {
            object result = default;

            using (var reader = new BinaryReader(stream))
            {
                var context = item.Parse(reader);

                result = context?.Root.Value;
            }

            return(result);
        }
Example #5
0
        public static ManifestEntry ConvertToManifestEntry(this ManifestDbEntry item, ManifestEntryType includeType, bool isEncrypted)
        {
            ManifestEntry result = default;

            var propertyList = new BinaryPropertyListReader()
                               .LoadFrom(item.Properties);

            if (propertyList != null && propertyList is IReadOnlyDictionary <string, object> )
            {
                dynamic properties = propertyList;

                var mode      = (int)properties["$objects"][1]["Mode"];
                var entryType = CommonHelpers.GetManifestEntryTypeFromMode(mode);
                if (entryType == includeType)
                {
                    var id = item.FileID;

                    result = new ManifestEntry
                    {
                        Id           = id,
                        Domain       = item.Domain,
                        RelativePath = item.RelativePath,
                        EntryType    = entryType,
                    };

                    if (isEncrypted)
                    {
                        var protectionClass = (ProtectionClass)properties["$objects"][1]["ProtectionClass"];
                        var index           = (int)properties["$objects"][1]["EncryptionKey"];
                        var data            = (byte[])properties["$objects"][index]["NS.data"];

                        result.ProtectionClass = protectionClass;
                        result.WrappedKey      = WrappedKeyReader.Read(data);
                    }
                }
            }

            return(result);
        }
Example #6
0
        public static IReadOnlyDictionary <string, object> LoadReadOnlyDictionaryFrom(this BinaryPropertyListReader item, string path)
        {
            var obj = item.LoadFrom(path);

            var result = obj as Dictionary <string, object>;

            if (obj is null)
            {
                throw new InvalidDataException();
            }

            return(result);
        }