/// <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;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Opens an UCOMIStream and returns the associated file object
        /// </summary>
        /// <param name="parentStorage">storage used to open the stream</param>
        /// <param name="fileName">filename of the stream</param>
        /// <returns>A <see cref="FileObject">FileObject</see> instance if the file was found, otherwise null.</returns>
        public FileObject OpenUCOMStream(Interop.IStorage parentStorage, string fileName)
        {
            if(parentStorage == null)
                parentStorage = storage;

            FileObject retObject = null;

            STATSTG sTATSTG;
            sTATSTG.pwcsName = fileName;
            sTATSTG.type = 2;

            try
            {
                retObject = new FileObject();

                UCOMIStream uCOMIStream = parentStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0);

                if(uCOMIStream != null)
                {
                    retObject.FileType = sTATSTG.type;
                    retObject.FilePath = "";
                    retObject.FileName = sTATSTG.pwcsName.ToString();
                    retObject.FileStream = uCOMIStream;
                }
                else
                {
                    retObject = null;
                }
            }
            catch(Exception ex)
            {
                retObject = null;

                Debug.WriteLine("ITStorageWrapper.OpenUCOMStream() - Failed for file '" + fileName + "'");
                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>
 public virtual void EnumIStorageObject(Interop.IStorage stgEnum)
 {
     EnumIStorageObject(stgEnum, "");
 }
 /// <summary>
 /// Enumerates an IStorage object and creates the file object collection
 /// </summary>
 /// <param name="stgEnum">IStorage to enumerate</param>
 public override void EnumIStorageObject(Interop.IStorage stgEnum)
 {
     base.EnumIStorageObject(storage);
 }