Exemplo n.º 1
0
        internal static FilterWrapper LoadAndInitIFilter(string fileName, string extension)
        {
            FilterWrapper filter = LoadIFilter(extension);

            if (filter == null)
            {
                return(null);
            }

            IPersistFile persistFile = (filter.Filter as IPersistFile);

            if (persistFile != null)
            {
                persistFile.Load(fileName, 0);
                IFILTER_FLAGS      flags;
                const IFILTER_INIT iflags = IFILTER_INIT.CANON_HYPHENS |
                                            IFILTER_INIT.CANON_PARAGRAPHS |
                                            IFILTER_INIT.CANON_SPACES |
                                            IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
                                            IFILTER_INIT.HARD_LINE_BREAKS |
                                            IFILTER_INIT.FILTER_OWNED_VALUE_OK;

                if (filter.Filter.Init(iflags, 0, IntPtr.Zero, out flags) == IFilterReturnCode.S_OK)
                {
                    return(filter);
                }
            }

            using (filter)
                return(null);
        }
Exemplo n.º 2
0
        internal static IFilter LoadAndInitIFilter(string fileName, string extension)
        {
            IFilter filter = LoadIFilter(extension);

            if (filter == null)
            {
                return(null);
            }

            IPersistFile persistFile = (filter as IPersistFile);

            if (persistFile != null)
            {
                persistFile.Load(fileName, 0);
                IFILTER_FLAGS flags;
                IFILTER_INIT  iflags =
                    IFILTER_INIT.CANON_HYPHENS |
                    IFILTER_INIT.CANON_PARAGRAPHS |
                    IFILTER_INIT.CANON_SPACES |
                    IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
                    IFILTER_INIT.HARD_LINE_BREAKS |
                    IFILTER_INIT.FILTER_OWNED_VALUE_OK;

                if (filter.Init(iflags, 0, IntPtr.Zero, out flags) == IFilterReturnCode.S_OK)
                {
                    return(filter);
                }
            }
            //If we failed to retreive an IPersistFile interface or to initialize
            //the filter, we release it and return null.
            Marshal.ReleaseComObject(filter);
            return(null);
        }
Exemplo n.º 3
0
        public static string getFileContents(string filename)
        {
            try
            {
                IFilter filter = null;

                try
                {
                    StringBuilder plainTextResult = new StringBuilder();
                    filter = loadIFilter(filename);

                    STAT_CHUNK   ps     = new STAT_CHUNK();
                    IFILTER_INIT mFlags = 0;

                    uint i = 0;
                    filter.Init(mFlags, 0, null, ref i);

                    int resultChunk = 0;

                    resultChunk = filter.GetChunk(out ps);
                    while (resultChunk == 0)
                    {
                        if (ps.flags == CHUNKSTATE.CHUNK_TEXT)
                        {
                            uint sizeBuffer = 60000;
                            int  resultText = 0;
                            while (resultText == Constants.FILTER_S_LAST_TEXT || resultText == 0 || resultText == Constants.FILTER_S_LAST_TEXT)
                            {
                                sizeBuffer = 60000;
                                System.Text.StringBuilder sbBuffer = new System.Text.StringBuilder((int)sizeBuffer);
                                resultText = filter.GetText(ref sizeBuffer, sbBuffer);

                                if (sizeBuffer > 0 && sbBuffer.Length > 0)
                                {
                                    if (sbBuffer.Length < sizeBuffer) // Should never happen, but it happens !
                                    {
                                        sizeBuffer = (uint)sbBuffer.Length;
                                    }

                                    string chunk = sbBuffer.ToString(0, (int)sizeBuffer);
                                    plainTextResult.Append(chunk);
                                }
                            }
                        }
                        resultChunk = filter.GetChunk(out ps);
                    }
                    return(plainTextResult.ToString());
                }
                finally
                {
                    if (filter != null)
                    {
                        Marshal.ReleaseComObject(filter);
                    }
                }
            }
            catch
            { }
            return("");
        }
 // Token: 0x06006CCA RID: 27850 RVA: 0x001F4C62 File Offset: 0x001F2E62
 public IFILTER_FLAGS Init(IFILTER_INIT grfFlags, ManagedFullPropSpec[] aAttributes)
 {
     this._grfFlags               = grfFlags;
     this._aAttributes            = aAttributes;
     this._corePropertyEnumerator = new CorePropertyEnumerator(this._coreProperties, this._grfFlags, this._aAttributes);
     return(IFILTER_FLAGS.IFILTER_FLAGS_NONE);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initialzes the session for this filter.
 /// </summary>
 /// <param name="grfFlags">usage flags</param>
 /// <param name="cAttributes">number of elements in aAttributes array</param>
 /// <param name="aAttributes">array of FULLPROPSPEC structs to restrict responses</param>
 /// <returns>IFILTER_FLAGS_NONE. Return value is effectively ignored by the caller.</returns>
 public IFILTER_FLAGS Init(
     [In] IFILTER_INIT grfFlags,
     [In] uint cAttributes,
     [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] FULLPROPSPEC[] aAttributes)
 {
     return(_filter.Init(grfFlags, cAttributes, aAttributes));
 }
 // Token: 0x06006CD0 RID: 27856 RVA: 0x001F4D64 File Offset: 0x001F2F64
 internal CorePropertyEnumerator(PackageProperties coreProperties, IFILTER_INIT grfFlags, ManagedFullPropSpec[] attributes)
 {
     if (attributes != null && attributes.Length != 0)
     {
         this._attributes = attributes;
     }
     else if ((grfFlags & IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES) == IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES)
     {
         this._attributes = new ManagedFullPropSpec[]
         {
             new ManagedFullPropSpec(FormatId.SummaryInformation, 2U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 3U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 4U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 5U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 6U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 8U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 9U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 11U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 12U),
             new ManagedFullPropSpec(FormatId.SummaryInformation, 13U),
             new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, 2U),
             new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, 18U),
             new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, 26U),
             new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, 27U),
             new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, 28U),
             new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, 29U)
         };
     }
     this._coreProperties = coreProperties;
     this._currentIndex   = -1;
 }
        /// <summary>
        /// Init
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="cAttributes">length of aAttributes</param>
        /// <param name="aAttributes">array of FULLPROPSPEC structs</param>
        /// <returns>flags</returns>
        public IFILTER_FLAGS Init(IFILTER_INIT grfFlags,      // IFILTER_INIT value
                                  uint cAttributes,           // length of aAttributes
                                  FULLPROPSPEC[] aAttributes) // restrict responses to the specified attributes
        {
            ManagedFullPropSpec[] managedArray = MarshalFullPropSpecArray(
                cAttributes, aAttributes);

            return(_implementation.Init(grfFlags, managedArray));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="coreProperties">CoreProperties to enumerate</param>
        /// <param name="grfFlags">
        /// if IFILTER_INIT_APPLY_INDEX_ATTRIBUTES is specified,
        /// this indicates all core properties to be returned unless
        /// the parameter aAttributes is non-empty.
        /// </param>
        /// <param name="attributes">
        /// attributes specified corresponding to the properties to filter.
        /// </param>
        internal CorePropertyEnumerator(PackageProperties coreProperties,
                                        IFILTER_INIT grfFlags,
                                        ManagedFullPropSpec[] attributes)
        {
            if (attributes != null && attributes.Length > 0)
            {
                //
                // If attruibutes list specified,
                // return core properties for only those attributes.
                //

                _attributes = attributes;
            }
            else if ((grfFlags & IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES)
                     == IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES)
            {
                //
                // If no attributes list specified,
                // but IFILTER_INIT_APPLY_INDEX_ATTRIBUTES is present in grfFlags,
                // return all core properties.
                //

                _attributes = new ManagedFullPropSpec[]
                {
                    //
                    // SummaryInformation
                    //
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Title),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Subject),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Creator),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Keywords),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Description),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.LastModifiedBy),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Revision),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.LastPrinted),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.DateCreated),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.DateModified),

                    //
                    // DocumentSummaryInformation
                    //
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Category),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Identifier),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.ContentType),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Language),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Version),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.ContentStatus)
                };
            }
            else
            {
                // No core properties to be returned.
            }

            _coreProperties = coreProperties;
            _currentIndex   = -1;
        }
 // Token: 0x06006CB5 RID: 27829 RVA: 0x001F461A File Offset: 0x001F281A
 public IFILTER_FLAGS Init(IFILTER_INIT grfFlags, uint cAttributes, FULLPROPSPEC[] aAttributes)
 {
     this._grfFlags    = grfFlags;
     this._cAttributes = cAttributes;
     this._aAttributes = aAttributes;
     this._partIterator.Reset();
     this._progress = PackageFilter.Progress.FilteringNotStarted;
     return(IFILTER_FLAGS.IFILTER_FLAGS_NONE);
 }
 // Token: 0x06006CA0 RID: 27808 RVA: 0x001F3FA0 File Offset: 0x001F21A0
 IFILTER_FLAGS IFilter.Init([In] IFILTER_INIT grfFlags, [In] uint cAttributes, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)][In] FULLPROPSPEC[] aAttributes)
 {
     if (this._filter == null)
     {
         throw new COMException(SR.Get("FileToFilterNotLoaded"), -2147467259);
     }
     if (cAttributes > 0U && aAttributes == null)
     {
         throw new COMException(SR.Get("FilterInitInvalidAttributes"), -2147024809);
     }
     return(this._filter.Init(grfFlags, cAttributes, aAttributes));
 }
Exemplo n.º 11
0
        /// <summary>
        /// IFilter.Init
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="cAttributes">number of elements in aAttributes</param>
        /// <param name="aAttributes">array of Managed FULLPROPSPEC structs to restrict responses</param>
        /// <returns>flags</returns>
        /// <remarks>
        /// Returns systematically IFILTER_FLAGS_NONE insofar as flags are used to control property search,
        /// which is not supported (See GetValue).
        /// </remarks>
        public IFILTER_FLAGS Init(IFILTER_INIT grfFlags,      // IFILTER_INIT value
                                  uint cAttributes,           // length of aAttributes
                                  FULLPROPSPEC[] aAttributes) // restrict responses to the specified attributes
        {
            _grfFlags    = grfFlags;
            _cAttributes = cAttributes;
            _aAttributes = aAttributes;

            _partIterator.Reset();
            _progress = Progress.FilteringNotStarted;

            return(IFILTER_FLAGS.IFILTER_FLAGS_NONE);
        }
        /// <summary>
        /// Initialzes the session for this filter.
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="aAttributes">array of Managed FULLPROPSPEC structs to restrict responses</param>
        /// <returns>IFILTER_FLAGS_NONE. Return value is effectively ignored by the caller.</returns>
        public IFILTER_FLAGS Init(IFILTER_INIT grfFlags, ManagedFullPropSpec[] aAttributes)
        {
            // NOTE: Methods parameters have already been validated by XpsFilter.

            _grfFlags = grfFlags;
            _aAttributes = aAttributes;

            // Each call to Init() creates a new enumerator
            // with parameters corresponding to current Init() call.
            _corePropertyEnumerator = new CorePropertyEnumerator(
                _coreProperties, _grfFlags, _aAttributes);

            return IFILTER_FLAGS.IFILTER_FLAGS_NONE;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initialzes the session for this filter.
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="aAttributes">array of Managed FULLPROPSPEC structs to restrict responses</param>
        /// <returns>IFILTER_FLAGS_NONE. Return value is effectively ignored by the caller.</returns>
        public IFILTER_FLAGS Init(IFILTER_INIT grfFlags, ManagedFullPropSpec[] aAttributes)
        {
            // NOTE: Methods parameters have already been validated by XpsFilter.

            _grfFlags    = grfFlags;
            _aAttributes = aAttributes;

            // Each call to Init() creates a new enumerator
            // with parameters corresponding to current Init() call.
            _corePropertyEnumerator = new CorePropertyEnumerator(
                _coreProperties, _grfFlags, _aAttributes);

            return(IFILTER_FLAGS.IFILTER_FLAGS_NONE);
        }
Exemplo n.º 14
0
        private static string LoadAndInitIFilterAndReadAll(Stream stream, string extension)
        {
            // Get an IFilter for a file or file extension
            IFilter           filter = null;
            IFilterReturnCode result = NativeMethods.LoadIFilter(extension, null, ref filter);

            if (result != IFilterReturnCode.S_OK)
            {
                Marshal.ThrowExceptionForHR((int)result);
            }

            // Copy the content to global memory
            byte[] buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            IntPtr nativePtr = Marshal.AllocHGlobal(buffer.Length);

            Marshal.Copy(buffer, 0, nativePtr, buffer.Length);

            // Create a COM stream
            IStream comStream;

            NativeMethods.CreateStreamOnHGlobal(nativePtr, true, out comStream);

            // Load the contents to the iFilter using IPersistStream interface
            var persistStream = (IPersistStream)filter;

            persistStream.Load(comStream);

            // Initialize iFilter
            IFILTER_INIT iflags =
                IFILTER_INIT.CANON_HYPHENS |
                IFILTER_INIT.CANON_PARAGRAPHS |
                IFILTER_INIT.CANON_SPACES |
                IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
                IFILTER_INIT.HARD_LINE_BREAKS |
                IFILTER_INIT.FILTER_OWNED_VALUE_OK;
            IFILTER_FLAGS filterFlags;

            result = filter.Init(iflags, 0, IntPtr.Zero, out filterFlags);

            var text = ExtractTextFromIFilter(filter);

            if (filter != null)
            {
                Marshal.ReleaseComObject(filter);
            }

            return(text);
        }
Exemplo n.º 15
0
        /// <summary>
        /// CHUNK_TEXT状態ファイル(iFilterでテキスト変換されたもの)の検索用文字列作成
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static string Parse(string fileName)
        {
            IFilter filter = null;

            try {
                StringBuilder plainTextResult = new StringBuilder();
                filter = LoadIFilter(fileName);

                STAT_CHUNK   ps     = new STAT_CHUNK();
                IFILTER_INIT mFlags = 0;

                uint i = 0;
                filter.Init(mFlags, 0, null, ref i);

                int resultChunk = 0;

                resultChunk = filter.GetChunk(out ps);
                while (resultChunk == 0)
                {
                    if (ps.flags == CHUNKSTATE.CHUNK_TEXT)
                    {
                        uint sizeBuffer = 60000;
                        int  resultText = 0;
                        while (resultText == Constants.FILTER_S_LAST_TEXT || resultText == 0)
                        {
                            sizeBuffer = 60000;
                            StringBuilder sbBuffer = new StringBuilder((int)sizeBuffer);
                            resultText = filter.GetText(ref sizeBuffer, sbBuffer);

                            if (sizeBuffer > 0 && sbBuffer.Length > 0)
                            {
                                string chunk = sbBuffer.ToString(0, (int)sizeBuffer);
                                plainTextResult.Append(chunk);
                            }
                        }
                    }
                    resultChunk = filter.GetChunk(out ps);
                }
                return(plainTextResult.ToString());
            } finally {
                if (filter != null)
                {
                    Marshal.ReleaseComObject(filter);
                    //Marshal.FinalReleaseComObject(filter);
                }
            }
        }
Exemplo n.º 16
0
        internal static IFilter LoadAndInitIFilter(string fileName, string extension)
        {
            IFilter filter = LoadIFilter(extension);

            if (filter == null)
            {
                return(null);
            }

            var iPersistStream = filter as IPersistStream;

            if (iPersistStream != null)
            {
                IFILTER_FLAGS flags;
                IFILTER_INIT  iflags =
                    IFILTER_INIT.CANON_HYPHENS |
                    IFILTER_INIT.CANON_PARAGRAPHS |
                    IFILTER_INIT.CANON_SPACES |
                    IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
                    IFILTER_INIT.HARD_LINE_BREAKS |
                    IFILTER_INIT.FILTER_OWNED_VALUE_OK;

                iflags =
                    IFILTER_INIT.CANON_HYPHENS |
                    IFILTER_INIT.CANON_PARAGRAPHS |
                    IFILTER_INIT.CANON_SPACES |
                    IFILTER_INIT.HARD_LINE_BREAKS |
                    IFILTER_INIT.FILTER_OWNED_VALUE_OK |
                    IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
                    IFILTER_INIT.APPLY_CRAWL_ATTRIBUTES |
                    IFILTER_INIT.APPLY_OTHER_ATTRIBUTES |
                    IFILTER_INIT.FILTER_OWNED_VALUE_OK; // added [CD]


                Stream        fileStream = new System.IO.FileStream(fileName, FileMode.Open);
                StreamWrapper wrapper    = new StreamWrapper(fileStream);
                iPersistStream.Load(wrapper);
                if (filter.Init(iflags, 0, IntPtr.Zero, out flags) == IFilterReturnCode.S_OK)
                {
                    return(filter);
                }
            }
            //If we failed to retreive an IPersistFile interface or to initialize
            //the filter, we release it and return null.
            Marshal.ReleaseComObject(filter);
            return(null);
        }
Exemplo n.º 17
0
 // Token: 0x06006C42 RID: 27714 RVA: 0x001F2DD4 File Offset: 0x001F0FD4
 public IFILTER_FLAGS Init(IFILTER_INIT grfFlags, ManagedFullPropSpec[] aAttributes)
 {
     this._filterContents = true;
     if (aAttributes != null && aAttributes.Length != 0)
     {
         this._filterContents = false;
         for (int i = 0; i < aAttributes.Length; i++)
         {
             if (aAttributes[i].Guid == IndexingFilterMarshaler.PSGUID_STORAGE && aAttributes[i].Property.PropType == PropSpecType.Id && aAttributes[i].Property.PropId == 19U)
             {
                 this._filterContents = true;
                 break;
             }
         }
     }
     this._returnCanonicalParagraphBreaks = ((grfFlags & IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS) > (IFILTER_INIT)0);
     return(IFILTER_FLAGS.IFILTER_FLAGS_NONE);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Initialzes the session for this filter.
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="cAttributes">number of elements in aAttributes array</param>
        /// <param name="aAttributes">array of FULLPROPSPEC structs to restrict responses</param>
        /// <returns>
        /// IFILTER_FLAGS_NONE to indicate that the caller should not use the IPropertySetStorage
        /// and IPropertyStorage interfaces to locate additional properties.
        /// </returns>
        IFILTER_FLAGS IFilter.Init(
            [In] IFILTER_INIT grfFlags,
            [In] uint cAttributes,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] FULLPROPSPEC[] aAttributes)
        {
            if (_filter == null)
            {
                throw new COMException(SR.Get(SRID.FileToFilterNotLoaded),
                                       (int)NativeMethods.E_FAIL);
            }

            if (cAttributes > 0 && aAttributes == null)
            {
                // Attributes count and array do not match.
                throw new COMException(SR.Get(SRID.FilterInitInvalidAttributes),
                                       (int)NativeMethods.E_INVALIDARG);
            }

            return(_filter.Init(grfFlags, cAttributes, aAttributes));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Managed counterpart of IFilter.Init.
        /// </summary>
        /// <param name="grfFlags">Usage flags. Only IFILTER_INIT_CANON_PARAGRAPHS can be meaningfully
        /// honored by the XAML filter.</param>
        /// <param name="aAttributes">array of Managed FULLPROPSPEC structs to restrict responses</param>
        /// <returns>IFILTER_FLAGS_NONE, meaning the caller should not try to retrieve OLE property using
        /// IPropertyStorage on the Xaml part.</returns>
        /// <remarks>Input parameters are ignored because this filter never returns any property value.</remarks>
        public IFILTER_FLAGS Init(
            IFILTER_INIT grfFlags,             // IFILTER_INIT value
            ManagedFullPropSpec[] aAttributes) // restrict responses to the specified attributes
        {
            //
            // Content is filtered either if no attributes are specified,
            // or if there are attributes specified, the attribute with PSGUID_STORAGE
            // property set and PID_STG_CONTENTS property id is present.
            //

            _filterContents = true;

            if (aAttributes != null && aAttributes.Length > 0)
            {
                _filterContents = false;

                for (int i = 0; i < aAttributes.Length; i++)
                {
                    if (aAttributes[i].Guid == IndexingFilterMarshaler.PSGUID_STORAGE &&
                        aAttributes[i].Property.PropType == PropSpecType.Id &&
                        aAttributes[i].Property.PropId == (uint)MS.Internal.Interop.PID_STG.CONTENTS)
                    {
                        _filterContents = true;
                        break;
                    }
                }
            }

            // The only flag in grfFlags that makes sense to honor is IFILTER_INIT_CANON_PARAGRAPHS
            _returnCanonicalParagraphBreaks =
                ((grfFlags & IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS) != 0);

            // Return zero value to indicate that the client code should not take any special steps
            // to retrieve OLE properties. This might have to change if filtering loose Xaml is supported.
            return(IFILTER_FLAGS.IFILTER_FLAGS_NONE);
        }
Exemplo n.º 20
0
        private static string ExtractText(IFilter filter)
        {
            var          plainTextResult = new StringBuilder();
            var          ps     = new STAT_CHUNK();
            IFILTER_INIT mFlags = 0;

            uint i = 0;

            filter.Init(mFlags, 0, null, ref i);

            int resultChunk = 0;

            resultChunk = filter.GetChunk(out ps);
            while (resultChunk == 0)
            {
                if (ps.flags == CHUNKSTATE.CHUNK_TEXT)
                {
                    uint sizeBuffer = 60000;
                    var  resultText = 0;
                    while (resultText == Constants.FILTER_S_LAST_TEXT || resultText == 0)
                    {
                        sizeBuffer = 60000;
                        var sbBuffer = new StringBuilder((int)sizeBuffer);
                        resultText = filter.GetText(ref sizeBuffer, sbBuffer);

                        if (sizeBuffer > 0 && sbBuffer.Length > 0)
                        {
                            string chunk = sbBuffer.ToString(0, (int)sizeBuffer);
                            plainTextResult.Append(chunk);
                        }
                    }
                }
                resultChunk = filter.GetChunk(out ps);
            }
            return(plainTextResult.ToString());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Managed counterpart of IFilter.Init. 
        /// </summary>
        /// <param name="grfFlags">Usage flags. Only IFILTER_INIT_CANON_PARAGRAPHS can be meaningfully 
        /// honored by the XAML filter.</param> 
        /// <param name="aAttributes">array of Managed FULLPROPSPEC structs to restrict responses</param>
        /// <returns>IFILTER_FLAGS_NONE, meaning the caller should not try to retrieve OLE property using 
        /// IPropertyStorage on the Xaml part.</returns>
        /// <remarks>Input parameters are ignored because this filter never returns any property value.</remarks>
        public IFILTER_FLAGS Init(
            IFILTER_INIT grfFlags,    // IFILTER_INIT value 
            ManagedFullPropSpec[] aAttributes)    // restrict responses to the specified attributes
        { 
            // 
            // Content is filtered either if no attributes are specified,
            // or if there are attributes specified, the attribute with PSGUID_STORAGE 
            // property set and PID_STG_CONTENTS property id is present.
            //

            _filterContents = true; 

            if (aAttributes != null && aAttributes.Length > 0) 
            { 
                _filterContents = false;
 
                for (int i = 0; i < aAttributes.Length; i++)
                {
                    if (aAttributes[i].Guid == IndexingFilterMarshaler.PSGUID_STORAGE
                        && aAttributes[i].Property.PropType == PropSpecType.Id 
                        && aAttributes[i].Property.PropId == (uint)MS.Internal.Interop.PID_STG.CONTENTS)
                    { 
                        _filterContents = true; 
                        break;
                    } 
                }
            }

            // The only flag in grfFlags that makes sense to honor is IFILTER_INIT_CANON_PARAGRAPHS 
            _returnCanonicalParagraphBreaks =
                ((grfFlags & IFILTER_INIT.IFILTER_INIT_CANON_PARAGRAPHS) != 0); 
 
            // Return zero value to indicate that the client code should not take any special steps
            // to retrieve OLE properties. This might have to change if filtering loose Xaml is supported. 
            return IFILTER_FLAGS.IFILTER_FLAGS_NONE;
        }
Exemplo n.º 22
0
        public static string Extract(string path)
        {
            StringBuilder sb     = new StringBuilder();
            IFilter       filter = null;

            try
            {
                string sciezka = Directory.GetCurrentDirectory();
                filter = loadIFilter(path);

                if (filter == null)
                {
                    return(String.Empty);
                }

                uint       i  = 0;
                STAT_CHUNK ps = new STAT_CHUNK();

                IFILTER_INIT iflags =
                    IFILTER_INIT.CANON_HYPHENS |
                    IFILTER_INIT.CANON_PARAGRAPHS |
                    IFILTER_INIT.CANON_SPACES |                                                 // to chyba wsadza wszystkie spacje zamiast zpecialnych znakow
                    IFILTER_INIT.HARD_LINE_BREAKS |
                    IFILTER_INIT.APPLY_CRAWL_ATTRIBUTES |
                    IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
                    IFILTER_INIT.APPLY_OTHER_ATTRIBUTES |
                    IFILTER_INIT.SEARCH_LINKS |
                    IFILTER_INIT.FILTER_OWNED_VALUE_OK;

                if (filter.Init(iflags, 0, null, ref i) != (int)IFilterReturnCodes.S_OK)
                {
                    throw new Exception("Problem initializing an IFilter for:\n" + path + " \n\n");
                }

                while (filter.GetChunk(out ps) == (int)(IFilterReturnCodes.S_OK))
                {
                    if (ps.flags == CHUNKSTATE.CHUNK_TEXT)
                    {
                        IFilterReturnCodes scode = 0;
                        while (scode == IFilterReturnCodes.S_OK || scode == IFilterReturnCodes.FILTER_S_LAST_TEXT)
                        {
                            uint pcwcBuffer = 65536;
                            System.Text.StringBuilder sbBuffer = new System.Text.StringBuilder((int)pcwcBuffer);

                            scode = (IFilterReturnCodes)filter.GetText(ref pcwcBuffer, sbBuffer);

                            // Kamil
                            // scode = (IFilterReturnCodes)filter.GetChunk( (ref pcwcBuffer, sbBuffer);

                            if (pcwcBuffer > 0 && sbBuffer.Length > 0)
                            {
                                if (sbBuffer.Length < pcwcBuffer) // Should never happen, but it happens !
                                {
                                    pcwcBuffer = (uint)sbBuffer.Length;
                                }

                                sb.Append(sbBuffer.ToString(0, (int)pcwcBuffer));
                                sb.Append(" "); // "\r\n"
                            }
                        }
                    }
                }
            }
            finally
            {
                if (filter != null)
                {
                    Marshal.ReleaseComObject(filter);
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                }
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="coreProperties">CoreProperties to enumerate</param>
        /// <param name="grfFlags">
        /// if IFILTER_INIT_APPLY_INDEX_ATTRIBUTES is specified,
        /// this indicates all core properties to be returned unless
        /// the parameter aAttributes is non-empty.
        /// </param>
        /// <param name="attributes">
        /// attributes specified corresponding to the properties to filter.
        /// </param>
        internal CorePropertyEnumerator(PackageProperties coreProperties,
            IFILTER_INIT grfFlags,
            ManagedFullPropSpec[] attributes)
        {
            if (attributes != null && attributes.Length > 0)
            {
                //
                // If attruibutes list specified,
                // return core properties for only those attributes.
                //

                _attributes = attributes;
            }
            else if ((grfFlags & IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES)
                == IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES)
            {
                //
                // If no attributes list specified,
                // but IFILTER_INIT_APPLY_INDEX_ATTRIBUTES is present in grfFlags,
                // return all core properties.
                //

                _attributes = new ManagedFullPropSpec[]
                {
                    //
                    // SummaryInformation
                    //
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Title),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Subject),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Creator),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Keywords),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Description),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.LastModifiedBy),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.Revision),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.LastPrinted),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.DateCreated),
                    new ManagedFullPropSpec(FormatId.SummaryInformation, PropertyId.DateModified),

                    //
                    // DocumentSummaryInformation
                    //
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Category),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Identifier),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.ContentType),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Language),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.Version),
                    new ManagedFullPropSpec(FormatId.DocumentSummaryInformation, PropertyId.ContentStatus)
                };
            }
            else
            {
                // No core properties to be returned.
            }

            _coreProperties = coreProperties;
            _currentIndex = -1;
        }
Exemplo n.º 24
0
        /// <summary> 
        /// Constructs a new instance of a TextFilter  
        /// using the default flags (search links and apply all attributes) 
        /// </summary> 
        /// <param name="file">File to filter</param> 
        public TextFilter(string file)
        {
            mFile = file;
            mFlags = IFILTER_INIT.IFILTER_INIT_SEARCH_LINKS |
            IFILTER_INIT.IFILTER_INIT_APPLY_CRAWL_ATTRIBUTES |
            IFILTER_INIT.IFILTER_INIT_APPLY_INDEX_ATTRIBUTES |
            IFILTER_INIT.IFILTER_INIT_APPLY_OTHER_ATTRIBUTES;

            Process();
        }
Exemplo n.º 25
0
        /// <summary> 
        /// Constructs a new instance of TextFilter using the selected filter flags 
        /// </summary> 
        /// <param name="file">File to filter</param> 
        /// <param name="flags">IFilter initialisation flags</param> 
        public TextFilter(string file, IFILTER_INIT flags)
        {
            mFile = file;
            mFlags = flags;

            Process();
        }
Exemplo n.º 26
0
        /// <summary>
        /// Init
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="cAttributes">length of aAttributes</param>
        /// <param name="aAttributes">array of FULLPROPSPEC structs</param>
        /// <returns>flags</returns>
        public IFILTER_FLAGS Init(IFILTER_INIT grfFlags,       // IFILTER_INIT value     
            uint cAttributes,               // length of aAttributes
            FULLPROPSPEC[] aAttributes)     // restrict responses to the specified attributes
        {
            ManagedFullPropSpec[] managedArray = MarshalFullPropSpecArray(
                                                 cAttributes, aAttributes);

            return _implementation.Init(grfFlags, managedArray);
        }
Exemplo n.º 27
0
        /// <summary>
        /// IFilter.Init
        /// </summary>
        /// <param name="grfFlags">usage flags</param>
        /// <param name="cAttributes">number of elements in aAttributes</param>
        /// <param name="aAttributes">array of Managed FULLPROPSPEC structs to restrict responses</param>
        /// <returns>flags</returns>
        /// <remarks>
        /// Returns systematically IFILTER_FLAGS_NONE insofar as flags are used to control property search,
        /// which is not supported (See GetValue).
        /// </remarks>
        public IFILTER_FLAGS Init(IFILTER_INIT grfFlags,       // IFILTER_INIT value     
            uint cAttributes,               // length of aAttributes
            FULLPROPSPEC[] aAttributes)     // restrict responses to the specified attributes
        {
            _grfFlags = grfFlags;
            _cAttributes = cAttributes;
            _aAttributes = aAttributes;

            _partIterator.Reset();
            _progress = Progress.FilteringNotStarted;

            return IFILTER_FLAGS.IFILTER_FLAGS_NONE;
        }
 // Token: 0x06006C34 RID: 27700 RVA: 0x001F1FE0 File Offset: 0x001F01E0
 public IFILTER_FLAGS Init(IFILTER_INIT grfFlags, uint cAttributes, FULLPROPSPEC[] aAttributes)
 {
     ManagedFullPropSpec[] aAttributes2 = IndexingFilterMarshaler.MarshalFullPropSpecArray(cAttributes, aAttributes);
     return(this._implementation.Init(grfFlags, aAttributes2));
 }