/// <summary> /// Opens a sub storage. Call this if an enumerated file object is of type storage /// </summary> /// <param name="parentStorage">parent storage of the sub storage file</param> /// <param name="storageName">name of the storage</param> /// <returns>Returns a reference to the sub storage</returns> public Interop.IStorage OpenSubStorage(Interop.IStorage parentStorage, string storageName) { if(parentStorage == null) parentStorage = storage; Interop.IStorage retObject = null; STATSTG sTATSTG; sTATSTG.pwcsName = storageName; sTATSTG.type = 1; try { Interop.IStorage iStorage = parentStorage.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0); retObject = iStorage; } catch(Exception ex) { retObject = null; Debug.WriteLine("ITStorageWrapper.OpenSubStorage() - Failed for storage '" + storageName + "'"); Debug.Indent(); Debug.WriteLine("Exception: " + ex.Message); Debug.Unindent(); } return retObject; }
/// <summary> /// Enumerates an Interop.IStorage object and creates the internal file object collection /// </summary> /// <param name="stgEnum">Interop.IStorage to enumerate</param> /// <param name="BasePath">Sets the base url for the storage files</param> protected void EnumIStorageObject(Interop.IStorage stgEnum, string BasePath) { Interop.IEnumSTATSTG iEnumSTATSTG; STATSTG sTATSTG; int i; stgEnum.EnumElements(0, IntPtr.Zero, 0, out iEnumSTATSTG); iEnumSTATSTG.Reset(); while (iEnumSTATSTG.Next(1, out sTATSTG, out i) == (int)Interop.S_OK) { if(i==0) break; FileObject newFileObj = new FileObject(); newFileObj.FileType = sTATSTG.type; switch (sTATSTG.type) { case 1: Interop.IStorage iStorage = stgEnum.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0); if (iStorage != null) { string str = String.Concat(BasePath, sTATSTG.pwcsName.ToString()); newFileObj.FileStorage = iStorage; newFileObj.FilePath = BasePath; newFileObj.FileName = sTATSTG.pwcsName.ToString(); foCollection.Add(newFileObj); EnumIStorageObject(iStorage, str); } break; case 2: UCOMIStream uCOMIStream = stgEnum.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0); newFileObj.FilePath = BasePath; newFileObj.FileName = sTATSTG.pwcsName.ToString(); newFileObj.FileStream = uCOMIStream; foCollection.Add(newFileObj); break; case 4: Debug.WriteLine("Ignoring IProperty type ..."); break; case 3: Debug.WriteLine("Ignoring ILockBytes type ..."); break; default: Debug.WriteLine("Unknown object type ..."); break; } } }