internal CompoundDocument(Stream stream, FileHeader header) { this.FileStorage = stream; this.Reader = new BinaryReader(this.FileStorage); // added this "if" to prevent exception when file is read only if( this.FileStorage.CanWrite ) this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode); this.Header = header; this.SectorSize = (int)Math.Pow(2, Header.SectorSizeInPot); // prevent errors by limiting sector size to a most used value of 2^9 // compare it to zero because this integer can overflow if (this.SectorSize < 0) this.SectorSize = 512; this.ShortSectorSize = (int)Math.Pow(2, Header.ShortSectorSizeInPot); // prevent errors by limiting sector size to a most used value of 2^6 // compare it to zero because this integer can overflow if (this.ShortSectorSize < 0) this.ShortSectorSize = 64; this.TotalSectors = stream.Length == 0 ? 0 : (int)(stream.Length - 512) / this.SectorSize; this.MasterSectorAllocation = new MasterSectorAllocation(this); this.SectorAllocation = new SectorAllocation(this); this.ShortSectorAllocation = new ShortSectorAllocation(this); }
internal CompoundDocument(Stream stream, FileHeader header) { this.FileStorage = stream; this.Reader = new BinaryReader(this.FileStorage); this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode); this.Header = header; checked { this.SectorSize = (int)Math.Pow(2.0, (double)this.Header.SectorSizeInPot); this.ShortSectorSize = (int)Math.Pow(2.0, (double)this.Header.ShortSectorSizeInPot); this.TotalSectors = ((stream.Length == 0L) ? 0 : ((int)(stream.Length - 512L) / this.SectorSize)); this.MasterSectorAllocation = new MasterSectorAllocation(this); this.SectorAllocation = new SectorAllocation(this); this.ShortSectorAllocation = new ShortSectorAllocation(this); } }
internal CompoundDocument(Stream stream, FileHeader header) { this.FileStorage = stream; this.Reader = new BinaryReader(this.FileStorage); this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode); this.Header = header; this.SectorSize = (int)Math.Pow(2, Header.SectorSizeInPot); this.ShortSectorSize = (int)Math.Pow(2, Header.ShortSectorSizeInPot); this.TotalSectors = stream.Length == 0 ? 0 : (int)(stream.Length - 512) / this.SectorSize; this.MasterSectorAllocation = new MasterSectorAllocation(this); this.SectorAllocation = new SectorAllocation(this); this.ShortSectorAllocation = new ShortSectorAllocation(this); }
internal CompoundDocument(Stream stream, FileHeader header) { this.FileStorage = stream; this.Reader = new BinaryReader(this.FileStorage); if (stream.CanWrite) { this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode); } this.Header = header; this.SectorSize = (int)Math.Pow(2, Header.SectorSizeInPot); this.ShortSectorSize = (int)Math.Pow(2, Header.ShortSectorSizeInPot); this.TotalSectors = stream.Length == 0 ? 0 : (int)(stream.Length - 512) / this.SectorSize; this.MasterSectorAllocation = new MasterSectorAllocation(this); this.SectorAllocation = new SectorAllocation(this); this.ShortSectorAllocation = new ShortSectorAllocation(this); }
internal CompoundDocument(Stream stream, FileHeader header) { this.FileStorage = stream; this.Reader = new BinaryReader(this.FileStorage); try { this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode); } catch (Exception StreamNotReadable) { Console.Write("stream not readable"); } this.Header = header; this.SectorSize = (int)Math.Pow(2, Header.SectorSizeInPot); this.ShortSectorSize = (int)Math.Pow(2, Header.ShortSectorSizeInPot); this.TotalSectors = stream.Length == 0 ? 0 : (int)(stream.Length - 512) / this.SectorSize; this.MasterSectorAllocation = new MasterSectorAllocation(this); this.SectorAllocation = new SectorAllocation(this); this.ShortSectorAllocation = new ShortSectorAllocation(this); }