internal int CompareTo(CFItem other) { return DirEntry.CompareTo(other.DirEntry); }
/// <summary> /// Sets the data for the current stream /// </summary> /// <param name="cfItem"></param> /// <param name="buffer"></param> internal void SetData(CFItem cfItem, Byte[] buffer) { SetStreamData(cfItem, buffer); }
/// <summary> /// Sets the data for the current stream /// </summary> /// <param name="cfItem"></param> /// <param name="buffer"></param> /// <exception cref="CFException">Raised when <see cref="buffer" /> is null</exception> private void SetStreamData(CFItem cfItem, Byte[] buffer) { if (buffer == null) throw new CFException("Parameter [buffer] cannot be null"); // Quick and dirty :-) if (buffer.Length == 0) return; var directoryEntry = cfItem.DirEntry; var sectorType = SectorType.Normal; var sectorSize = GetSectorSize(); if (buffer.Length < _header.MinSizeStandardStream) { sectorType = SectorType.Mini; sectorSize = Sector.MinisectorSize; } // Check for transition ministream -> stream: // Only in this case we need to free old sectors, // otherwise they will be overwritten. if (directoryEntry.StartSector != Sector.Endofchain) { if ( (buffer.Length < _header.MinSizeStandardStream && directoryEntry.Size > _header.MinSizeStandardStream) || (buffer.Length > _header.MinSizeStandardStream && directoryEntry.Size < _header.MinSizeStandardStream) ) { if (directoryEntry.Size < _header.MinSizeStandardStream) { FreeMiniChain(GetMiniSectorChain(directoryEntry.StartSector), _eraseFreeSectors); } else { FreeChain(GetNormalSectorChain(directoryEntry.StartSector), _eraseFreeSectors); } directoryEntry.Size = 0; directoryEntry.StartSector = Sector.Endofchain; } } var sectorChain = GetSectorChain(directoryEntry.StartSector, sectorType); Queue<Sector> freeList = null; if (_sectorRecycle) freeList = FindFreeSectors(sectorType); // Collect available free sectors var streamView = new StreamView(sectorChain, sectorSize, buffer.Length, freeList, SourceStream); streamView.Write(buffer, 0, buffer.Length); switch (sectorType) { case SectorType.Normal: SetNormalSectorChain(streamView.BaseSectorChain); break; case SectorType.Mini: SetMiniSectorChain(streamView.BaseSectorChain); break; } if (streamView.BaseSectorChain.Count > 0) { directoryEntry.StartSector = streamView.BaseSectorChain[0].Id; directoryEntry.Size = buffer.Length; } else { directoryEntry.StartSector = Sector.Endofchain; directoryEntry.Size = 0; } }
internal int CompareTo(CFItem other) { return(DirEntry.CompareTo(other.DirEntry)); }