// Token: 0x06006CBD RID: 27837 RVA: 0x001F4A30 File Offset: 0x001F2C30
        private string GetFilterClsid(ContentType contentType, Uri partUri)
        {
            string text = null;

            if (contentType != null && !ContentType.Empty.AreTypeAndSubTypeEqual(contentType))
            {
                text = this.FileTypeGuidFromMimeType(contentType);
            }
            else
            {
                string partExtension = this.GetPartExtension(partUri);
                if (partExtension != null)
                {
                    text = this.FileTypeGuidFromFileExtension(partExtension);
                }
            }
            if (text == null)
            {
                return(null);
            }
            RegistryKey registryKey = PackageFilter.FindSubkey(Registry.ClassesRoot, PackageFilter.MakeRegistryPath(this._IFilterAddinPath, new string[]
            {
                text
            }));

            if (registryKey == null)
            {
                return(null);
            }
            return((string)registryKey.GetValue(null));
        }
Beispiel #2
0
        void IPersistStream.Load(MS.Internal.Interop.IStream stream)
        {
            // Check argument.
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // Only one of _package and _encryptedPackage can be non-null at a time.
            Invariant.Assert(_package == null || _encryptedPackage == null);

            // If there has been a previous call to Load, reinitialize everything.
            // Note closing a closed stream does not cause any exception.
            ReleaseResources();

            _filter      = null;
            _xpsFileName = null;

            try
            {
                _packageStream = new UnsafeIndexingFilterStream(stream);

                // different filter for encrypted package
                if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(_packageStream))
                {
                    // Open the encrypted package.
                    _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream);
                    _filter           = new EncryptedPackageFilter(_encryptedPackage);
                }
                else
                {
                    // Open the package.
                    _package = Package.Open(_packageStream);
                    _filter  = new PackageFilter(_package);
                }
            }
            catch (IOException ex)
            {
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS);
            }
            catch (Exception ex)
            {
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT);
            }
            finally
            {
                // clean-up if we failed
                if (_filter == null)
                {
                    ReleaseResources();
                }
            }
        }
        // Token: 0x06006CC0 RID: 27840 RVA: 0x001F4B28 File Offset: 0x001F2D28
        private string FileTypeGuidFromFileExtension(string dottedExtensionName)
        {
            RegistryKey registryKey = PackageFilter.FindSubkey(Registry.ClassesRoot, PackageFilter.MakeRegistryPath(this._persistentHandlerKey, new string[]
            {
                dottedExtensionName
            }));

            if (registryKey != null)
            {
                return((string)registryKey.GetValue(null));
            }
            return(null);
        }
        // Token: 0x06006CBF RID: 27839 RVA: 0x001F4AD4 File Offset: 0x001F2CD4
        private string FileTypeGuidFromMimeType(ContentType contentType)
        {
            RegistryKey registryKey  = PackageFilter.FindSubkey(Registry.ClassesRoot, this._mimeContentTypeKey);
            RegistryKey registryKey2 = (registryKey == null) ? null : registryKey.OpenSubKey(contentType.ToString());

            if (registryKey2 == null)
            {
                return(null);
            }
            string text = (string)registryKey2.GetValue("Extension");

            if (text == null)
            {
                return(null);
            }
            return(this.FileTypeGuidFromFileExtension(text));
        }
Beispiel #5
0
        void IPersistStream.Load(MS.Internal.Interop.IStream stream)
        {
            // Check argument. 
            if (stream == null)
            { 
                throw new ArgumentNullException("stream"); 
            }
 
            // Only one of _package and _encryptedPackage can be non-null at a time.
            Invariant.Assert(_package == null || _encryptedPackage == null);

            // If there has been a previous call to Load, reinitialize everything. 
            // Note closing a closed stream does not cause any exception.
            ReleaseResources(); 
 
            _filter = null;
            _xpsFileName = null; 

            try
            {
                _packageStream = new UnsafeIndexingFilterStream(stream); 

                // different filter for encrypted package 
                if (EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(_packageStream)) 
                {
                    // Open the encrypted package. 
                    _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream);
                    _filter = new EncryptedPackageFilter(_encryptedPackage);
                }
                else 
                {
                    // Open the package. 
                    _package = Package.Open(_packageStream); 
                    _filter = new PackageFilter(_package);
                } 
            }
            catch (IOException ex)
            {
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS); 
            }
            catch (Exception ex) 
            { 
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT);
            } 
            finally
            {
                // clean-up if we failed
                if (_filter == null) 
                {
                    ReleaseResources(); 
                } 
            }
        } 
Beispiel #6
0
        /// <summary> 
        /// Opens the specified file with the specified mode.. 
        /// This can return any of the STG_E_* error codes, along
        /// with S_OK, E_OUTOFMEMORY, and E_FAIL. 
        /// </summary>
        /// <param name="pszFileName">
        /// A zero-terminated string containing the absolute path of the file to open.
        /// </param> 
        /// <param name="dwMode">The mode in which to open pszFileName. </param>
        void IPersistFile.Load(string pszFileName, int dwMode) 
        { 
            FileMode fileMode;
            FileAccess fileAccess; 
            FileShare fileSharing;

            // Check argument.
            if (pszFileName == null || pszFileName == String.Empty) 
            {
                throw new ArgumentException(SR.Get(SRID.FileNameNullOrEmpty), "pszFileName"); 
            } 

            // Convert mode information in flag. 
            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.MODE))
            {
                case STGM_FLAGS.CREATE:
                    throw new ArgumentException(SR.Get(SRID.FilterLoadInvalidModeFlag), "dwMode"); 

                default: 
                    fileMode = FileMode.Open; 
                    break;
            } 

            // Convert access flag.
            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.ACCESS))
            { 
                case STGM_FLAGS.READ:
                case STGM_FLAGS.READWRITE: 
                    fileAccess = FileAccess.Read; 
                    break;
 
                default:
                    throw new ArgumentException(SR.Get(SRID.FilterLoadInvalidModeFlag), "dwMode");
            }
 
            // Sharing flags are ignored. Since managed filters do not have the equivalent
            // of a destructor to release locks on files as soon as they get disposed of from 
            // unmanaged code, the option taken is not to lock at all while filtering. 
            // (See call to FileToStream further down.)
            fileSharing = FileShare.ReadWrite; 

            // Only one of _package and _encryptedPackage can be non-null at a time.
            Invariant.Assert(_package == null || _encryptedPackage == null);
 
            // If there has been a previous call to Load, reinitialize everything.
            // Note closing a closed stream does not cause any exception. 
            ReleaseResources(); 

            _filter = null; 
            _xpsFileName = null;

            bool encrypted = EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(pszFileName);
 
            try
            { 
                // opens to MemoryStream or just returns FileStream if file exceeds _maxMemoryStreamBuffer 
                _packageStream = FileToStream(pszFileName, fileMode, fileAccess, fileSharing, _maxMemoryStreamBuffer);
 
                if (encrypted)
                {
                    // Open the encrypted package.
                    _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream); 
                    _filter = new EncryptedPackageFilter(_encryptedPackage);
                } 
                else 
                {
                    // Open the package. 
                    _package = Package.Open(_packageStream);
                    _filter = new PackageFilter(_package);
                }
            } 
            catch (IOException ex)
            { 
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS); 
            }
            catch (FileFormatException ex) 
            {
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT);
            }
            finally 
            {
                // failure? 
                if (_filter == null) 
                {
                    // clean up 
                    ReleaseResources();
                }

            } 

            _xpsFileName = pszFileName; 
        } 
Beispiel #7
0
        /// <summary>
        /// Opens the specified file with the specified mode..
        /// This can return any of the STG_E_* error codes, along
        /// with S_OK, E_OUTOFMEMORY, and E_FAIL.
        /// </summary>
        /// <param name="pszFileName">
        /// A zero-terminated string containing the absolute path of the file to open.
        /// </param>
        /// <param name="dwMode">The mode in which to open pszFileName. </param>
        void IPersistFile.Load(string pszFileName, int dwMode)
        {
            FileMode   fileMode;
            FileAccess fileAccess;
            FileShare  fileSharing;

            // Check argument.
            if (pszFileName == null || pszFileName == String.Empty)
            {
                throw new ArgumentException(SR.Get(SRID.FileNameNullOrEmpty), "pszFileName");
            }

            // Convert mode information in flag.
            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.MODE))
            {
            case STGM_FLAGS.CREATE:
                throw new ArgumentException(SR.Get(SRID.FilterLoadInvalidModeFlag), "dwMode");

            default:
                fileMode = FileMode.Open;
                break;
            }

            // Convert access flag.
            switch ((STGM_FLAGS)(dwMode & (int)STGM_FLAGS.ACCESS))
            {
            case STGM_FLAGS.READ:
            case STGM_FLAGS.READWRITE:
                fileAccess = FileAccess.Read;
                break;

            default:
                throw new ArgumentException(SR.Get(SRID.FilterLoadInvalidModeFlag), "dwMode");
            }

            // Sharing flags are ignored. Since managed filters do not have the equivalent
            // of a destructor to release locks on files as soon as they get disposed of from
            // unmanaged code, the option taken is not to lock at all while filtering.
            // (See call to FileToStream further down.)
            fileSharing = FileShare.ReadWrite;

            // Only one of _package and _encryptedPackage can be non-null at a time.
            Invariant.Assert(_package == null || _encryptedPackage == null);

            // If there has been a previous call to Load, reinitialize everything.
            // Note closing a closed stream does not cause any exception.
            ReleaseResources();

            _filter      = null;
            _xpsFileName = null;

            bool encrypted = EncryptedPackageEnvelope.IsEncryptedPackageEnvelope(pszFileName);

            try
            {
                // opens to MemoryStream or just returns FileStream if file exceeds _maxMemoryStreamBuffer
                _packageStream = FileToStream(pszFileName, fileMode, fileAccess, fileSharing, _maxMemoryStreamBuffer);

                if (encrypted)
                {
                    // Open the encrypted package.
                    _encryptedPackage = EncryptedPackageEnvelope.Open(_packageStream);
                    _filter           = new EncryptedPackageFilter(_encryptedPackage);
                }
                else
                {
                    // Open the package.
                    _package = Package.Open(_packageStream);
                    _filter  = new PackageFilter(_package);
                }
            }
            catch (IOException ex)
            {
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_ACCESS);
            }
            catch (FileFormatException ex)
            {
                throw new COMException(ex.Message, (int)FilterErrorCode.FILTER_E_UNKNOWNFORMAT);
            }
            finally
            {
                // failure?
                if (_filter == null)
                {
                    // clean up
                    ReleaseResources();
                }
            }

            _xpsFileName = pszFileName;
        }