/// <summary> /// Checks if a child storage exists within the parent. /// </summary> /// <param name="storageName">Name of the storage to look for.</param> /// <returns>A boolean value indicating whether the child storage was found.</returns> /// <example> /// <code> /// String FILENAME = "MultipleStorage2.cfs"; /// CompoundFile cf = new CompoundFile(FILENAME, UpdateMode.ReadOnly, false, false); /// /// bool exists = cf.RootStorage.ExistsStorage("MyStorage"); /// /// if exists /// { /// CFStorage st = cf.RootStorage.GetStorage("MyStorage"); /// } /// /// Assert.IsNotNull(st); /// cf.Close(); /// </code> /// </example> public bool ExistsStorage(string storageName) { CheckDisposed(); var tmp = new CFMock(storageName, StgType.StgStorage); CFItem outDe = null; return(Children.TryFind(tmp, out outDe) && outDe.DirEntry.StgType == StgType.StgStorage); }
/// <summary> /// Get a named storage contained in the current one if existing. /// </summary> /// <param name="storageName">Name of the storage to look for</param> /// <returns>A storage reference if existing.</returns> /// <exception cref="T:OpenMcdf.CFDisposedException">Raised if trying to delete item from a closed compound file</exception> /// <exception cref="T:OpenMcdf.CFItemNotFound">Raised if item to delete is not found</exception> /// <example> /// <code> /// /// String FILENAME = "MultipleStorage2.cfs"; /// CompoundFile cf = new CompoundFile(FILENAME, UpdateMode.ReadOnly, false, false); /// /// CFStorage st = cf.RootStorage.GetStorage("MyStorage"); /// /// Assert.IsNotNull(st); /// cf.Close(); /// </code> /// </example> public ICFStorage GetStorage(String storageName) { CheckDisposed(); CFMock tmp = new CFMock(storageName, StgType.StgStorage); CFItem outDe = null; if (Children.TryFind(tmp, out outDe) && outDe.DirEntry.StgType == StgType.StgStorage) { return(outDe as CFStorage); } else { throw new CFItemNotFound("Cannot find item [" + storageName + "] within the current storage"); } }
//public void DeleteStream(String name) //{ // Delete(name, typeof(CFStream)); //} //public void DeleteStorage(String name) //{ // Delete(name, typeof(CFStorage)); //} /// <summary> /// Remove an entry from the current storage and compound file. /// </summary> /// <param name="entryName">The name of the entry in the current storage to delete</param> /// <example> /// <code> /// cf = new CompoundFile("A_FILE_YOU_CAN_CHANGE.cfs", UpdateMode.Update, true, false); /// cf.RootStorage.Delete("AStream"); // AStream item is assumed to exist. /// cf.Commit(true); /// cf.Close(); /// </code> /// </example> /// <exception cref="T:OpenMcdf.CFDisposedException">Raised if trying to delete item from a closed compound file</exception> /// <exception cref="T:OpenMcdf.CFItemNotFound">Raised if item to delete is not found</exception> /// <exception cref="T:OpenMcdf.CFException">Raised if trying to delete root storage</exception> public void Delete(String entryName) { CheckDisposed(); // Find entry to delete CFMock tmp = new CFMock(entryName, StgType.StgInvalid); CFItem foundObj = null; this.Children.TryFind(tmp, out foundObj); if (foundObj == null) throw new CFItemNotFound("Entry named [" + entryName + "] was not found"); //if (foundObj.GetType() != typeCheck) // throw new CFException("Entry named [" + entryName + "] has not the correct type"); if (foundObj.DirEntry.StgType == StgType.StgRoot) throw new CFException("Root storage cannot be removed"); switch (foundObj.DirEntry.StgType) { case StgType.StgStorage: CFStorage temp = (CFStorage)foundObj; foreach (CFItem de in temp.Children) { temp.Delete(de.Name); } // Remove item from children tree this.Children.Remove(foundObj); // Synchronize tree with directory entries this.CompoundFile.RefreshIterative(this.Children.Root); // Rethread the root of siblings tree... if (this.Children.Root != null) this.DirEntry.Child = this.Children.Root.Value.DirEntry.SID; else this.DirEntry.Child = DirectoryEntry.NOSTREAM; // ...and now remove directory (storage) entry this.CompoundFile.RemoveDirectoryEntry(foundObj.DirEntry.SID); break; case StgType.StgStream: // Remove item from children tree this.Children.Remove(foundObj); // Synchronize tree with directory entries this.CompoundFile.RefreshIterative(this.Children.Root); // Rethread the root of siblings tree... if (this.Children.Root != null) this.DirEntry.Child = this.Children.Root.Value.DirEntry.SID; else this.DirEntry.Child = DirectoryEntry.NOSTREAM; // Remove directory entry this.CompoundFile.RemoveDirectoryEntry(foundObj.DirEntry.SID); break; } //// Refresh recursively all SIDs (invariant for tree sorting) //VisitedEntryAction action = delegate(CFSItem target) //{ // if( ((IDirectoryEntry)target).SID>foundObj.SID ) // { // ((IDirectoryEntry)target).SID--; // } // ((IDirectoryEntry)target).LeftSibling--; //}; }
/// <summary> /// Checks if a child storage exists within the parent. /// </summary> /// <param name="storageName">Name of the storage to look for.</param> /// <returns>A boolean value indicating whether the child storage was found.</returns> /// <example> /// <code> /// String FILENAME = "MultipleStorage2.cfs"; /// CompoundFile cf = new CompoundFile(FILENAME, UpdateMode.ReadOnly, false, false); /// /// bool exists = cf.RootStorage.ExistsStorage("MyStorage"); /// /// if exists /// { /// CFStorage st = cf.RootStorage.GetStorage("MyStorage"); /// } /// /// Assert.IsNotNull(st); /// cf.Close(); /// </code> /// </example> public bool ExistsStorage(string storageName) { CheckDisposed(); var tmp = new CFMock(storageName, StgType.StgStorage); CFItem outDe = null; return Children.TryFind(tmp, out outDe) && outDe.DirEntry.StgType == StgType.StgStorage; }
/// <summary> /// Get a named storage contained in the current one if existing. /// </summary> /// <param name="storageName">Name of the storage to look for</param> /// <returns>A storage reference if existing.</returns> /// <exception cref="T:OpenMcdf.CFDisposedException">Raised if trying to delete item from a closed compound file</exception> /// <exception cref="T:OpenMcdf.CFItemNotFound">Raised if item to delete is not found</exception> /// <example> /// <code> /// /// String FILENAME = "MultipleStorage2.cfs"; /// CompoundFile cf = new CompoundFile(FILENAME, UpdateMode.ReadOnly, false, false); /// /// CFStorage st = cf.RootStorage.GetStorage("MyStorage"); /// /// Assert.IsNotNull(st); /// cf.Close(); /// </code> /// </example> public ICFStorage GetStorage(String storageName) { CheckDisposed(); CFMock tmp = new CFMock(storageName, StgType.StgStorage); CFItem outDe = null; if (Children.TryFind(tmp, out outDe) && outDe.DirEntry.StgType == StgType.StgStorage) { return outDe as CFStorage; } else { throw new CFItemNotFound("Cannot find item [" + storageName + "] within the current storage"); } }
//public void DeleteStream(String name) //{ // Delete(name, typeof(CFStream)); //} //public void DeleteStorage(String name) //{ // Delete(name, typeof(CFStorage)); //} /// <summary> /// Remove an entry from the current storage and compound file. /// </summary> /// <param name="entryName">The name of the entry in the current storage to delete</param> /// <example> /// <code> /// cf = new CompoundFile("A_FILE_YOU_CAN_CHANGE.cfs", UpdateMode.Update, true, false); /// cf.RootStorage.Delete("AStream"); // AStream item is assumed to exist. /// cf.Commit(true); /// cf.Close(); /// </code> /// </example> /// <exception cref="T:OpenMcdf.CFDisposedException">Raised if trying to delete item from a closed compound file</exception> /// <exception cref="T:OpenMcdf.CFItemNotFound">Raised if item to delete is not found</exception> /// <exception cref="T:OpenMcdf.CFException">Raised if trying to delete root storage</exception> public void Delete(String entryName) { CheckDisposed(); // Find entry to delete CFMock tmp = new CFMock(entryName, StgType.StgInvalid); CFItem foundObj = null; this.Children.TryFind(tmp, out foundObj); if (foundObj == null) { throw new CFItemNotFound("Entry named [" + entryName + "] was not found"); } //if (foundObj.GetType() != typeCheck) // throw new CFException("Entry named [" + entryName + "] has not the correct type"); if (foundObj.DirEntry.StgType == StgType.StgRoot) { throw new CFException("Root storage cannot be removed"); } switch (foundObj.DirEntry.StgType) { case StgType.StgStorage: CFStorage temp = (CFStorage)foundObj; foreach (CFItem de in temp.Children) { temp.Delete(de.Name); } // Remove item from children tree this.Children.Remove(foundObj); // Synchronize tree with directory entries this.CompoundFile.RefreshIterative(this.Children.Root); // Rethread the root of siblings tree... if (this.Children.Root != null) { this.DirEntry.Child = this.Children.Root.Value.DirEntry.SID; } else { this.DirEntry.Child = DirectoryEntry.NOSTREAM; } // ...and now remove directory (storage) entry this.CompoundFile.RemoveDirectoryEntry(foundObj.DirEntry.SID); break; case StgType.StgStream: // Remove item from children tree this.Children.Remove(foundObj); // Synchronize tree with directory entries this.CompoundFile.RefreshIterative(this.Children.Root); // Rethread the root of siblings tree... if (this.Children.Root != null) { this.DirEntry.Child = this.Children.Root.Value.DirEntry.SID; } else { this.DirEntry.Child = DirectoryEntry.NOSTREAM; } // Remove directory entry this.CompoundFile.RemoveDirectoryEntry(foundObj.DirEntry.SID); break; } //// Refresh recursively all SIDs (invariant for tree sorting) //VisitedEntryAction action = delegate(CFSItem target) //{ // if( ((IDirectoryEntry)target).SID>foundObj.SID ) // { // ((IDirectoryEntry)target).SID--; // } // ((IDirectoryEntry)target).LeftSibling--; //}; }