Skip to content

Commit

Permalink
Fix issue #49
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed Nov 21, 2022
1 parent c749482 commit fde7bb0
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
Binary file modified .vs/IFilterTextReader/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added .vs/IFilterTextReader/v17/.futdcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 13 additions & 16 deletions IFilterTextReader/FilterLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,28 +189,25 @@ public static NativeMethods.IFilter LoadAndInitIFilter(Stream stream,
if (string.IsNullOrWhiteSpace(fileName))
throw new IFOldFilterFormat("The IFilter does not support the IPersistStream interface, supply a filename to use the IFilter");

try
// If we get here we probably are using an old IFilter so try to load it the old way
// ReSharper disable once SuspiciousTypeConversion.Global
if (iFilter is IPersistFile persistFile)
{
// If we get here we probably are using an old IFilter so try to load it the old way
// ReSharper disable once SuspiciousTypeConversion.Global
if (iFilter is IPersistFile persistFile)
try
{
persistFile.Load(fileName, 0);
if (iFilter.Init(iFlags, 0, IntPtr.Zero, out _) == NativeMethods.IFilterReturnCode.S_OK)
return iFilter;
}
}
catch (Exception)
{
throw new IFUnknownFormat($"The file '{fileName}' has an unknown format");
}
finally
{
// If we failed to retrieve an IPersistStream or IPersistFile interface or to initialize
// the filter, we release it and return null.
Marshal.ReleaseComObject(iFilter);
catch (Exception)
{
Marshal.ReleaseComObject(iFilter);
throw new IFUnknownFormat($"The file '{fileName}' has an unknown format");
}

if (iFilter.Init(iFlags, 0, IntPtr.Zero, out _) == NativeMethods.IFilterReturnCode.S_OK)
return iFilter;
}

Marshal.ReleaseComObject(iFilter);
return null;
}
#endregion
Expand Down

0 comments on commit fde7bb0

Please sign in to comment.