diff --git a/sources/OpenMcdf/CompoundFile.cs b/sources/OpenMcdf/CompoundFile.cs index 31d0f091..ae0a2fee 100644 --- a/sources/OpenMcdf/CompoundFile.cs +++ b/sources/OpenMcdf/CompoundFile.cs @@ -117,8 +117,7 @@ public enum CFSUpdateMode /// public class CompoundFile : IDisposable { - private CFSConfiguration configuration - = CFSConfiguration.Default; + private CFSConfiguration configuration; /// /// Get the configuration parameters of the CompoundFile object. @@ -170,6 +169,16 @@ internal int GetSectorSize() /// private bool eraseFreeSectors = false; + private bool validationExceptionEnabled = true; + + public bool ValidationExceptionEnabled + { + get { return validationExceptionEnabled; } + } + + private CFSUpdateMode updateMode = CFSUpdateMode.ReadOnly; + private String fileName = String.Empty; + /// /// Initial capacity of the flushing queue used /// to optimize commit writing operations @@ -221,25 +230,7 @@ internal int GetSectorSize() /// /// /// - public CompoundFile() : this(CFSVersion.Ver_3, CFSConfiguration.Default) - { - - //this.header = new Header(); - //this.sectorRecycle = false; - - ////this.sectors.OnVer3SizeLimitReached += new Ver3SizeLimitReached(OnSizeLimitReached); - - //DIFAT_SECTOR_FAT_ENTRIES_COUNT = (GetSectorSize() / 4) - 1; - //FAT_SECTOR_ENTRIES_COUNT = (GetSectorSize() / 4); - - ////Root -- - //IDirectoryEntry de = DirectoryEntry.New("Root Entry", StgType.StgRoot, directoryEntries); - //rootStorage = new CFStorage(this, de); - //rootStorage.DirEntry.StgType = StgType.StgRoot; - //rootStorage.DirEntry.StgColor = StgColor.Black; - - ////this.InsertNewDirectoryEntry(rootStorage.DirEntry); - } + public CompoundFile() : this(CFSVersion.Ver_3, CFSConfiguration.Default) { } void OnSizeLimitReached() { @@ -280,19 +271,13 @@ void OnSizeLimitReached() /// public CompoundFile(CFSVersion cfsVersion, CFSConfiguration configFlags) { - this.configuration = configFlags; - - bool sectorRecycle = configFlags.HasFlag(CFSConfiguration.SectorRecycle); - bool eraseFreeSectors = configFlags.HasFlag(CFSConfiguration.EraseFreeSectors); - + SetConfigurationOptions(configFlags); + this.header = new Header((ushort)cfsVersion); if (cfsVersion == CFSVersion.Ver_4) this.sectors.OnVer3SizeLimitReached += new Ver3SizeLimitReached(OnSizeLimitReached); - - this.sectorRecycle = sectorRecycle; - - + DIFAT_SECTOR_FAT_ENTRIES_COUNT = (GetSectorSize() / 4) - 1; FAT_SECTOR_ENTRIES_COUNT = (GetSectorSize() / 4); @@ -302,9 +287,6 @@ public CompoundFile(CFSVersion cfsVersion, CFSConfiguration configFlags) //this.InsertNewDirectoryEntry(rootDir); rootStorage = new CFStorage(this, rootDir); - - - // } @@ -334,17 +316,7 @@ public CompoundFile(CFSVersion cfsVersion, CFSConfiguration configFlags) /// automatically recognized from the file. Sector recycle is turned off /// to achieve the best reading/writing performance in most common scenarios. /// - public CompoundFile(String fileName) - { - this.sectorRecycle = false; - this.updateMode = CFSUpdateMode.ReadOnly; - this.eraseFreeSectors = false; - - LoadFile(fileName); - - DIFAT_SECTOR_FAT_ENTRIES_COUNT = (GetSectorSize() / 4) - 1; - FAT_SECTOR_ENTRIES_COUNT = (GetSectorSize() / 4); - } + public CompoundFile(String fileName) : this(fileName, CFSUpdateMode.ReadOnly, CFSConfiguration.Default) { } /// /// Load an existing compound file. @@ -373,26 +345,15 @@ public CompoundFile(String fileName) /// public CompoundFile(String fileName, CFSUpdateMode updateMode, CFSConfiguration configParameters) { - this.configuration = configParameters; - this.validationExceptionEnabled = !configParameters.HasFlag(CFSConfiguration.NoValidationException); - this.sectorRecycle = configParameters.HasFlag(CFSConfiguration.SectorRecycle); + SetConfigurationOptions(configParameters); this.updateMode = updateMode; - this.eraseFreeSectors = configParameters.HasFlag(CFSConfiguration.EraseFreeSectors); LoadFile(fileName); DIFAT_SECTOR_FAT_ENTRIES_COUNT = (GetSectorSize() / 4) - 1; FAT_SECTOR_ENTRIES_COUNT = (GetSectorSize() / 4); } - - private bool validationExceptionEnabled = true; - - public bool ValidationExceptionEnabled - { - get { return validationExceptionEnabled; } - } - - + /// /// Load an existing compound file. /// @@ -421,13 +382,9 @@ public bool ValidationExceptionEnabled /// Raised stream is null public CompoundFile(Stream stream, CFSUpdateMode updateMode, CFSConfiguration configParameters) { - this.configuration = configParameters; - this.validationExceptionEnabled = !configParameters.HasFlag(CFSConfiguration.NoValidationException); - this.sectorRecycle = configParameters.HasFlag(CFSConfiguration.SectorRecycle); - this.eraseFreeSectors = configParameters.HasFlag(CFSConfiguration.EraseFreeSectors); - this.closeStream = !configParameters.HasFlag(CFSConfiguration.LeaveOpen); - + SetConfigurationOptions(configParameters); this.updateMode = updateMode; + LoadStream(stream); DIFAT_SECTOR_FAT_ENTRIES_COUNT = (GetSectorSize() / 4) - 1; @@ -458,18 +415,7 @@ public CompoundFile(Stream stream, CFSUpdateMode updateMode, CFSConfiguration co /// /// Raised when trying to open a non-seekable stream /// Raised stream is null - public CompoundFile(Stream stream) - { - LoadStream(stream); - - DIFAT_SECTOR_FAT_ENTRIES_COUNT = (GetSectorSize() / 4) - 1; - FAT_SECTOR_ENTRIES_COUNT = (GetSectorSize() / 4); - } - - private CFSUpdateMode updateMode = CFSUpdateMode.ReadOnly; - private String fileName = String.Empty; - - + public CompoundFile(Stream stream) : this(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default) { } /// /// Commit data changes since the previously commit operation @@ -666,6 +612,18 @@ public void Commit(bool releaseMemory) //} } + /// + /// Set configuration parameters + /// + private void SetConfigurationOptions(CFSConfiguration configParameters) + { + this.configuration = configParameters; + this.validationExceptionEnabled = !configParameters.HasFlag(CFSConfiguration.NoValidationException); + this.sectorRecycle = configParameters.HasFlag(CFSConfiguration.SectorRecycle); + this.eraseFreeSectors = configParameters.HasFlag(CFSConfiguration.EraseFreeSectors); + this.closeStream = !configParameters.HasFlag(CFSConfiguration.LeaveOpen); + } + /// /// Load compound file from an existing stream. ///