示例#1
0
        bool DoRead(Stream stream)
        {
            if (stream.Length < _metadataTable.MinLength + SegmentLength)
            {
                return(false); // 虽然插件数据文件存在,但并未包含有效的数据
            }
            // 1. 读取各个分段的长度
            stream.Position = stream.Length - SegmentLength;
            var addinRecordSegmentLength           = stream.ReadInt64();
            var addinMetadataSegmentLength         = stream.ReadInt64();
            var invalidAddinFilePacksSegmentLength = stream.ReadInt64();
            var dataSegmentLength = stream.ReadInt64();

            if (dataSegmentLength + SegmentLength != stream.Length)
            {
                return(false); // 插件数据文件已被破坏,返回 false 以便让系统重新解析插件
            }
            // 2. 读取 AddinMetadata 分段 (AddinMetadataTable)
            stream.Position = addinRecordSegmentLength; // 指针指向 AddinMetadata 分段 (AddinMetadataTable) 的起始位置
            var hasAddins = _metadataTable.Read(stream);

            if (!hasAddins || _metadataTable.AddinCount == 0)
            {
                return(false); // 虽然插件数据文件存在,但并未包含有效的数据
            }
            // 3. 根据 AddinMetadata 读取 AddinRecord 分段,并进行验证
            foreach (var metadata in _metadataTable.Addins)
            {
                stream.Position = metadata.Position;
                var addin = new AddinRecord(metadata);
                addin.Read(stream);
                if (stream.Position - metadata.Position != metadata.Length || addin.Uid != metadata.AddinUid)
                {
                    return(false); // 插件数据文件已被破坏,返回 false 以便让系统重新解析插件
                }
                _addinRecords.Add(addin);
            }

            // 4. 读取 InvalidAddinFilePack 分段
            stream.Position        = addinRecordSegmentLength + addinMetadataSegmentLength; // 指针指向 InvalidAddinFilePack 分段的起始位置
            _invalidAddinFilePacks = RecordHelpers.Read(stream, ref AddinFilePack.Factory);
            if (stream.Position - (addinRecordSegmentLength + addinMetadataSegmentLength) != invalidAddinFilePacksSegmentLength)
            {
                return(false); // 插件数据文件已被破坏,返回 false 以便让系统重新解析插件
            }
            // 5. 读取 Uid 分段
            stream.Position = addinRecordSegmentLength + addinMetadataSegmentLength + invalidAddinFilePacksSegmentLength; // 指针指向 Uid 分段的起始位置
            UidStorage.Read(stream);

            return(true);
        }
示例#2
0
        public void Read(Stream reader)
        {
            //OperationStatus = (AddinOperationStatus)reader.ReadSByte();

            _addinHeader.Read(reader);
            _addinFilePack.Read(reader);

            var activatorIsNull = reader.ReadBoolean();

            if (!activatorIsNull)
            {
                _addinActivator = new AddinActivatorRecord();
                _addinActivator.Read(reader);
            }

            //_referencedApplicationAssemblies = RecordHelpers.Read(reader, ref ReferencedApplicationAssemblyRecord.Factory);
            _referencedAssemblies    = RecordHelpers.Read(reader, ref ReferencedAssemblyRecord.Factory);
            _extendedAddins          = RecordHelpers.Read(reader, ref ExtendedAddinRecord.Factory);
            _extendedExtensionPoints = RecordHelpers.Read(reader);

            _extensionPoints = RecordHelpers.Read(reader, ref ExtensionPointRecord.Factory);
            _ebRecordGroups  = RecordHelpers.Read(reader, ref ExtensionBuilderRecordGroup.Factory);
            _exRecordGroups  = RecordHelpers.Read(reader, ref ExtensionRecordGroup.Factory);
        }