Пример #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="stream">Metadata stream</param>
        public PinnedMetaData(IImageStream stream)
        {
            this.stream = stream;

            var umStream = stream as UnmanagedMemoryImageStream;

            if (umStream != null)
            {
                this.address = umStream.StartAddress;
                GC.SuppressFinalize(this);  // no GCHandle so finalizer isn't needed
            }
            else
            {
                var memStream = stream as MemoryImageStream;
                if (memStream != null)
                {
                    this.streamData = memStream.DataArray;
                    this.gcHandle   = GCHandle.Alloc(this.streamData, GCHandleType.Pinned);
                    this.address    = new IntPtr(this.gcHandle.AddrOfPinnedObject().ToInt64() + memStream.DataOffset);
                }
                else
                {
                    this.streamData = stream.ReadAllBytes();
                    this.gcHandle   = GCHandle.Alloc(this.streamData, GCHandleType.Pinned);
                    this.address    = this.gcHandle.AddrOfPinnedObject();
                }
            }
        }
Пример #2
0
		/// <summary>
		/// Adds a resource
		/// </summary>
		/// <param name="stream">The resource data</param>
		/// <returns>The resource data</returns>
		public ByteArrayChunk Add(IImageStream stream) {
			if (setOffsetCalled)
				throw new InvalidOperationException("SetOffset() has already been called");
			var rawData = stream.ReadAllBytes();
			length = Utils.AlignUp(length + 4 + (uint)rawData.Length, alignment);
			var data = new ByteArrayChunk(rawData);
			resources.Add(data);
			return data;
		}
Пример #3
0
        /// <summary>
        ///     Gets the resource data as a byte array
        /// </summary>
        /// <returns>The resource data</returns>
        public byte[] GetResourceData()
        {
#if THREAD_SAFE
            theLock.EnterWriteLock(); try {
#endif
            return(dataStream.ReadAllBytes());

#if THREAD_SAFE
        }
        finally { theLock.ExitWriteLock(); }
#endif
        }
Пример #4
0
        /// <summary>
        /// Adds a resource
        /// </summary>
        /// <param name="stream">The resource data</param>
        /// <returns>The resource data</returns>
        public ByteArrayChunk Add(IImageStream stream)
        {
            if (setOffsetCalled)
            {
                throw new InvalidOperationException("SetOffset() has already been called");
            }
            var rawData = stream.ReadAllBytes();

            length = Utils.AlignUp(length + 4 + (uint)rawData.Length, alignment);
            var data = new ByteArrayChunk(rawData);

            resources.Add(data);
            return(data);
        }
Пример #5
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="stream">Metadata stream</param>
		public PinnedMetaData(IImageStream stream) {
			this.stream = stream;

			var umStream = stream as UnmanagedMemoryImageStream;
			if (umStream != null) {
				this.address = umStream.StartAddress;
				GC.SuppressFinalize(this);	// no GCHandle so finalizer isn't needed
			}
			else {
				var memStream = stream as MemoryImageStream;
				if (memStream != null) {
					this.streamData = memStream.DataArray;
					this.gcHandle = GCHandle.Alloc(this.streamData, GCHandleType.Pinned);
					this.address = new IntPtr(this.gcHandle.AddrOfPinnedObject().ToInt64() + memStream.DataOffset);
				}
				else {
					this.streamData = stream.ReadAllBytes();
					this.gcHandle = GCHandle.Alloc(this.streamData, GCHandleType.Pinned);
					this.address = this.gcHandle.AddrOfPinnedObject();
				}
			}
		}
Пример #6
0
 byte[] GetRawBlob()
 {
     return(reader.ReadAllBytes());
 }