public SegmentResizedEventArgs(int segmentId, int oldSize, int newSize, SegmentResizeOrigin origin) { SegmentID = segmentId; OldSize = oldSize; NewSize = newSize; ResizeOrigin = origin; }
/// <summary> /// Defines a new segment in the file. /// </summary> /// <param name="offset">The offset at which the segment starts.</param> /// <param name="size">The size of the segment.</param> /// <param name="offsetAlignment">A power of two which the offset must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param> /// <returns>The segment's ID number which can be used to retrieve information about it.</returns> public int DefineSegment(int offset, int size, int offsetAlignment, int sizeAlignment, SegmentResizeOrigin resizeOrigin) { if (offset != Align(offset, offsetAlignment)) { throw new ArgumentException("The segment offset is not aligned to the given alignment."); } if (size != Align(size, sizeAlignment)) { throw new ArgumentException("The segment size is not aligned to the given alignment."); } if (_segmentsByOffset.ContainsKey(offset)) { throw new ArgumentException("A segment has already been defined at the given offset."); } // Create and add the segment definition int id = _segmentsById.Count; var segment = new InternalSegment { ID = id, Offset = offset, Size = size, OffsetAlignment = offsetAlignment, SizeAlignment = sizeAlignment, ResizeOrigin = resizeOrigin }; _segmentsById.Add(segment); _segmentsByOffset[offset] = segment; RecalculateActualSizes(); return(id); }
/// <summary> /// Defines a new segment in the file. /// </summary> /// <param name="offset">The offset at which the segment starts.</param> /// <param name="size">The size of the segment.</param> /// <param name="offsetAlignment">A power of two which the offset must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param> /// <returns>The segment's ID number which can be used to retrieve information about it.</returns> public int DefineSegment(int offset, int size, int offsetAlignment, int sizeAlignment, SegmentResizeOrigin resizeOrigin) { if (offset != Align(offset, offsetAlignment)) throw new ArgumentException("The segment offset is not aligned to the given alignment."); if (size != Align(size, sizeAlignment)) throw new ArgumentException("The segment size is not aligned to the given alignment."); if (_segmentsByOffset.ContainsKey(offset)) throw new ArgumentException("A segment has already been defined at the given offset."); // Create and add the segment definition int id = _segmentsById.Count; var segment = new InternalSegment { ID = id, Offset = offset, Size = size, OffsetAlignment = offsetAlignment, SizeAlignment = sizeAlignment, ResizeOrigin = resizeOrigin }; _segmentsById.Add(segment); _segmentsByOffset[offset] = segment; RecalculateActualSizes(); return id; }
/// <summary> /// Defines a new segment in the file. It will be aligned to the segmenter's default offset alignment. /// </summary> /// <param name="offset">The offset at which the segment starts.</param> /// <param name="size">The size of the segment.</param> /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param> /// <returns>The segment's ID number which can be used to retrieve information about it.</returns> public int DefineSegment(int offset, int size, int sizeAlignment, SegmentResizeOrigin resizeOrigin) { return DefineSegment(offset, size, _defaultOffsetAlign, sizeAlignment, resizeOrigin); }
/// <summary> /// Defines a segment and returns a FileSegment that wraps it. /// </summary> /// <param name="offset">The offset at which the segment starts.</param> /// <param name="size">The size of the segment.</param> /// <param name="offsetAlignment">A power of two which the offset must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param> /// <returns>The segment's ID number which can be used to retrieve information about it.</returns> public static FileSegment WrapSegment(this FileSegmenter segmenter, int offset, int size, int offsetAlignment, int sizeAlignment, SegmentResizeOrigin resizeOrigin) { return new FileSegment(segmenter.DefineSegment(offset, size, offsetAlignment, sizeAlignment, resizeOrigin), segmenter); }
/// <summary> /// Defines a new segment in the file. It will be aligned to the segmenter's default offset alignment. /// </summary> /// <param name="offset">The offset at which the segment starts.</param> /// <param name="size">The size of the segment.</param> /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param> /// <returns>The segment's ID number which can be used to retrieve information about it.</returns> public int DefineSegment(int offset, int size, int sizeAlignment, SegmentResizeOrigin resizeOrigin) { return(DefineSegment(offset, size, _defaultOffsetAlign, sizeAlignment, resizeOrigin)); }
/// <summary> /// Defines a segment and returns a FileSegment that wraps it. /// </summary> /// <param name="offset">The offset at which the segment starts.</param> /// <param name="size">The size of the segment.</param> /// <param name="offsetAlignment">A power of two which the offset must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="sizeAlignment">A power of two which the size must be a multiple of (e.g. 0x1000 = 4kb-aligned).</param> /// <param name="resizeOrigin">The origin at which to insert/remove data in the segment.</param> /// <returns>The segment's ID number which can be used to retrieve information about it.</returns> public static FileSegment WrapSegment(this FileSegmenter segmenter, int offset, int size, int offsetAlignment, int sizeAlignment, SegmentResizeOrigin resizeOrigin) { return(new FileSegment(segmenter.DefineSegment(offset, size, offsetAlignment, sizeAlignment, resizeOrigin), segmenter)); }