/// <summary> /// Clones this instance. /// </summary> /// <returns>Returns the cloned file allocation table.</returns> public FileAllocationTable Clone() { FileAllocationTable table = new FileAllocationTable(); List <int> list = new List <int>(); foreach (int num in this._innerList) { list.Add(num); } table._innerList = list; return(table); }
/// <summary> /// Populate all stream fields for the compound file. /// </summary> private void PopulateStreamFields() { DirectoryEntry entry = this._directoryEntries["Root Entry"]; if (this._directoryEntries.IndexOf("Root Entry") != 0) { throw new Exception("The root storage entry MUST exist and proceed all entries."); } if (((entry.Type != CompoundFileObjectType.RootStorage) || (entry.LeftSiblingID != DirectoryEntry.NoStream)) || (entry.RightSiblingID != DirectoryEntry.NoStream)) { throw new ArgumentException("Properties of root entry are not valid for compound file."); } if ((this._directoryEntries.Count > 1) && (entry.ChildID == DirectoryEntry.NoStream)) { throw new Exception("The child id of root directory entry was not set correctly."); } this.FillEmptyDirectoryEntries(); this._difatList = new FileAllocationTable(); this._fatList = new FileAllocationTable(); this._miniFatList = new FileAllocationTable(); int sectorCount = (int)Math.Ceiling((double)((this._directoryEntries.Count * 128.0) / ((double)SectorSize))); int num2 = this.GetTotalUserDataSectorCount() + sectorCount; int num3 = (int)Math.Ceiling((double)(((double)this.GetTotalUserDataMiniSectorCount()) / ((double)(SectorSize / MiniSectorSize)))); int num4 = num2 + num3; int num5 = SectorSize / 4; int num6 = SectorSize / 4; int num7 = (SectorSize - 4) / 4; int num8 = (int)Math.Ceiling((double)(((double)num4) / ((double)num5))); int num9 = (int)Math.Ceiling((double)(((double)Math.Max(0, num8 - CompoundFileHeader.MaxDifatArrayLength)) / ((double)num7))); int num10 = (int)Math.Ceiling((double)(((double)this.GetTotalUserDataMiniSectorCount()) / ((double)num6))); for (int i = (((num2 + num3) + num8) + num9) + num10; i != num4; i = (((num2 + num3) + num8) + num9) + num10) { num4 = i; num8 = (int)Math.Ceiling((double)(((double)num4) / ((double)num5))); num9 = (int)Math.Ceiling((double)(((double)Math.Max(0, num8 - CompoundFileHeader.MaxDifatArrayLength)) / ((double)num7))); } this.AllocateUserDataSectors(); int num12 = -2; if (num3 > 0) { int num13 = this._fatList.Allocate(num3, SectorType.Data); entry.StartSector = num13; entry.StreamSize = this.GetTotalUserDataMiniSectorCount() * MiniSectorSize; num12 = this._fatList.Allocate(num10, SectorType.Data); } int num14 = this._fatList.Allocate(sectorCount, SectorType.Data); int num15 = this._fatList.Allocate(num8, SectorType.FAT); int num16 = this._fatList.Allocate(num9, SectorType.DIFAT); for (int j = num15; j < (num15 + num8); j++) { this._difatList.Add(j); } this._header = new CompoundFileHeader(); this._header.FirstMiniFatSector = num12; this._header.MiniFatSectorCount = num10; this._header.FirstDirectorySector = num14; this._header.FatSectorCount = this._difatList.Count; this._header.DifatSectorCount = num9; this._header.FirstDifatSector = (num9 > 0) ? num16 : -2; if (num9 > 0) { this._header.DifatArray = new int[CompoundFileHeader.MaxDifatArrayLength]; for (int k = 0; k < this._header.DifatArray.Length; k++) { this._header.DifatArray[k] = this._difatList[k]; } } else { this._header.DifatArray = this._difatList.ToArray(); } }