Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed Mar 30, 2022
1 parent eeb1d5c commit c749482
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
26 changes: 13 additions & 13 deletions IFilterTextReader/FilterLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
if (iFilter == null)
return null;

var iflags = NativeMethods.IFILTER_INIT.CANON_HYPHENS |
var iFlags = NativeMethods.IFILTER_INIT.CANON_HYPHENS |
NativeMethods.IFILTER_INIT.CANON_PARAGRAPHS |
NativeMethods.IFILTER_INIT.CANON_SPACES |
NativeMethods.IFILTER_INIT.APPLY_INDEX_ATTRIBUTES |
Expand All @@ -149,11 +149,11 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
NativeMethods.IFILTER_INIT.EMIT_FORMATTING;

if (disableEmbeddedContent)
iflags = iflags | NativeMethods.IFILTER_INIT.DISABLE_EMBEDDED;
iFlags |= NativeMethods.IFILTER_INIT.DISABLE_EMBEDDED;

// ReSharper disable once SuspiciousTypeConversion.Global

// IPersistStream is asumed on 64 bits systems
// IPersistStream is assumed on 64 bits systems
if (iFilter is NativeMethods.IPersistStream iPersistStream)
{
// Create a COM stream
Expand All @@ -163,6 +163,7 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
{
// Copy the content to global memory
var buffer = new byte[stream.Length];
// ReSharper disable once MustUseReturnValue
stream.Read(buffer, 0, buffer.Length);
var nativePtr = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, nativePtr, buffer.Length);
Expand All @@ -175,13 +176,13 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
{
iPersistStream.Load(comStream);

if (iFilter.Init(iflags, 0, IntPtr.Zero, out _) == NativeMethods.IFilterReturnCode.S_OK)
if (iFilter.Init(iFlags, 0, IntPtr.Zero, out _) == NativeMethods.IFilterReturnCode.S_OK)
return iFilter;
}
catch (Exception exception)
{
if (string.IsNullOrWhiteSpace(fileName))
throw new IFOldFilterFormat("An error occured while trying to load a stream with the IPersistStream interface", exception);
throw new IFOldFilterFormat("An error occurred while trying to load a stream with the IPersistStream interface", exception);
}
}

Expand All @@ -195,7 +196,7 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
if (iFilter is IPersistFile persistFile)
{
persistFile.Load(fileName, 0);
if (iFilter.Init(iflags, 0, IntPtr.Zero, out _) == NativeMethods.IFilterReturnCode.S_OK)
if (iFilter.Init(iFlags, 0, IntPtr.Zero, out _) == NativeMethods.IFilterReturnCode.S_OK)
return iFilter;
}
}
Expand All @@ -205,7 +206,7 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
}
finally
{
// If we failed to retreive an IPersistStream or IPersistFile interface or to initialize
// If we failed to retrieve an IPersistStream or IPersistFile interface or to initialize
// the filter, we release it and return null.
Marshal.ReleaseComObject(iFilter);
}
Expand Down Expand Up @@ -286,8 +287,7 @@ private static bool GetFilterDllAndClassFromPersistentHandler(
dllName = null;

// Read the CLASS ID of the IFilter persistent handler
filterPersistClass = ReadFromHKLM(
$@"Software\Classes\CLSID\{persistentHandlerClass}\PersistentAddinsRegistered\{{89BCB740-6119-101A-BCB7-00DD010655AF}}");
filterPersistClass = ReadFromHKLM($@"Software\Classes\CLSID\{persistentHandlerClass}\PersistentAddinsRegistered\{{89BCB740-6119-101A-BCB7-00DD010655AF}}");

if (string.IsNullOrEmpty(filterPersistClass))
return false;
Expand All @@ -302,7 +302,7 @@ private static bool GetFilterDllAndClassFromPersistentHandler(

#region GetPersistentHandlerClass
/// <summary>
/// Returns an persistant handler class
/// Returns an persistent handler class
/// </summary>
/// <param name="extension">The file extension</param>
/// <param name="searchContentType"></param>
Expand All @@ -326,7 +326,7 @@ private static string GetPersistentHandlerClass(string extension, bool searchCon

#region GetPersistentHandlerClassFromContentType
/// <summary>
/// Returns an persistant handler class based on the contenttype of the file
/// Returns an persistent handler class based on the content type of the file
/// </summary>
/// <param name="extension"></param>
/// <returns></returns>
Expand All @@ -346,7 +346,7 @@ private static string GetPersistentHandlerClassFromContentType(string extension)

#region GetPersistentHandlerClassFromDocumentType
/// <summary>
/// Returns an persistant handler class based on the document type
/// Returns an persistent handler class based on the document type
/// </summary>
/// <param name="extension">The file extension</param>
/// <returns></returns>
Expand All @@ -369,7 +369,7 @@ private static string GetPersistentHandlerClassFromDocumentType(string extension

#region GetPersistentHandlerClassFromExtension
/// <summary>
/// Returns an persistant handler class based on the extension of the file
/// Returns an persistent handler class based on the extension of the file
/// </summary>
/// <param name="extension">The file extension</param>
/// <returns></returns>
Expand Down
3 changes: 2 additions & 1 deletion IFilterTextReader/FilterReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ public FilterReader(Stream stream,
_filter = FilterLoader.LoadAndInitIFilter(
stream,
extension,
_options.DisableEmbeddedContent, string.Empty,
_options.DisableEmbeddedContent,
string.Empty,
_options.ReadIntoMemory);

if (_filter == null)
Expand Down

0 comments on commit c749482

Please sign in to comment.