Пример #1
0
        private void Check(MainForm form, IWICBitmapDecoderInfo info, Tag tag)
        {
            ComponentInfoHelper.CheckNotReserverdGuid(form, info.GetContainerFormat, this);

            tag.PixelFormats = PixelFormatInfoRule.CheckPixelFormats(form, this, info.GetPixelFormats);

            ComponentInfoHelper.CheckVersion(form, info.GetColorManagementVersion, this);
            ComponentInfoHelper.CheckCommaSeparatedString(form, info.GetMimeTypes, ComponentInfoHelper.MimeMask, this);

            tag.Extensions = ComponentInfoHelper.CheckCommaSeparatedString(form, info.GetFileExtensions, ComponentInfoHelper.ExtensionMask, this);

            if (!info.DoesSupportMultiframe() && info.DoesSupportAnimation())
            {
                form.Add(this, Resources.DecoderAnimationIfMultiframe);
            }
            tag.SupportsMultiframe = info.DoesSupportMultiframe();

            uint size = info.GetPatterns(0, IntPtr.Zero, out var count);

            if (size != 0)
            {
                IntPtr p = Marshal.AllocCoTaskMem((int)size);
                try
                {
                    info.GetPatterns(size, p, out count);

                    WICBitmapPattern[] patterns = PropVariantMarshaler.ToArrayOf <WICBitmapPattern>(p, (int)count);
                    int index = 0;
                    var dups  = new HashSet <int>();
                    foreach (WICBitmapPattern pattern in patterns)
                    {
                        index++;
                        if (pattern.Length == 0)
                        {
                            form.Add(this, Resources.PatternZeroLength, new DataEntry(Resources.PatternIndex, index));
                        }
                        else if (index < patterns.Length)
                        {
                            if (Array.FindIndex(patterns, index, delegate(WICBitmapPattern obj) { return(obj.EndOfStream == pattern.EndOfStream && obj.Position == pattern.Position && GetNormalizedMask(obj).ItemsEqual(GetNormalizedMask(pattern))); }) >= 0)
                            {
                                dups.Add(index);
                            }
                        }
                    }
                    if (dups.Count > 0)
                    {
                        form.Add(this, Resources.PatternDuplicated, new DataEntry(Resources.PatternIndices, dups.ToArray()));
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(p);
                }
            }

            if (count == 0 || size == 0)
            {
                form.Add(this, Resources.PatternNo);
            }
        }
Пример #2
0
        protected override void RunOverride(ListView.ListViewItemCollection collection, object tag)
        {
            IWICImagingFactory    factory = (IWICImagingFactory) new WICImagingFactory();
            IWICBitmapDecoderInfo info    = null;

            try
            {
                info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid);
                string[] mimes = Extensions.GetString(info.GetMimeTypes).Split(',');

                foreach (string ext in Extensions.GetString(info.GetFileExtensions).Split(','))
                {
                    using (RegistryKey rk = OpenSubKey(collection, Registry.ClassesRoot, ext, new DataEntry[] { new DataEntry("File Extension", ext) }))
                    {
                        if (rk != null)
                        {
                            Check(collection, ext, rk, info);
                        }
                    }
                }
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
            }
        }
Пример #3
0
        protected override bool ProcessDecoder(MainForm form, IWICBitmapDecoder decoder, DataEntry[] de, object tag)
        {
            IWICBitmapDecoderInfo info = decoder.GetDecoderInfo();

            try
            {
                info.GetCLSID(out var clsid);
                if (clsid != Parent.Clsid)
                {
                    form.Add(this, Resources.IncorrectDecoderPickedUp, de, new DataEntry(Resources.Expected, Parent.Clsid), new DataEntry(Resources.Actual, clsid));
                }
                else
                {
                    Tag t = (Tag)tag;
                    if (!t.SupportsMultiframe && decoder.GetFrameCount() > 1)
                    {
                        form.Add(this, Resources.DecoderDoesNotMultiframe, de, new DataEntry(Resources.FrameCount, decoder.GetFrameCount()));
                    }
                }
            }
            finally
            {
                info.ReleaseComObject();
            }

            return(true);
        }
Пример #4
0
        public static WICBitmapPattern[] GetPatterns(this IWICBitmapDecoderInfo bitmapDecoderInfo)
        {
            int count;
            int size;

            bitmapDecoderInfo.GetPatterns(0, IntPtr.Zero, out count, out size);
            if (count == 0)
            {
                return(new WICBitmapPattern[0]);
            }
            using (var buffer = new CoTaskMemPtr(Marshal.AllocCoTaskMem(size)))
            {
                bitmapDecoderInfo.GetPatterns(size, buffer, out count, out size);
                IntPtr at       = buffer;
                var    patterns = new WICBitmapPattern[count];
                for (int i = 0, stride = Marshal.SizeOf(typeof(WICBitmapPatternRaw)); i < count; ++i, at += stride)
                {
                    var raw    = (WICBitmapPatternRaw)Marshal.PtrToStructure(at, typeof(WICBitmapPatternRaw));
                    int length = raw.Length;
                    patterns[i] = new WICBitmapPattern()
                    {
                        Length      = length,
                        Position    = raw.Position,
                        Pattern     = new byte[length],
                        Mask        = new byte[length],
                        EndOfStream = raw.EndOfStream
                    };
                    Marshal.Copy(raw.Pattern, patterns[i].Pattern, 0, length);
                    Marshal.Copy(raw.Mask, patterns[i].Mask, 0, length);
                }
                return(patterns);
            }
        }
 protected override void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info)
 {
     DataEntry[] de = new DataEntry[] { new DataEntry("File Extension", ext)};
     using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "{0}\\ShellEx\\{1}", ext, ShellExGuid), de))
     {
         CheckValue(collection, r, null, new string[] { ThumnailCacheGuid }, de);
     }
     using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "SystemFileAssociations\\{0}\\ShellEx\\{1}", ext, ShellExGuid), de))
     {
         CheckValue(collection, r, null, new string[] { ThumnailCacheGuid }, de);
     }
 }
Пример #6
0
        public void GetDecoderInfo(out IWICBitmapDecoderInfo ppIDecoderInfo)
        {
            Log.Trace("GetDecoderInfo called");

            var imagingFactory = GetImagingFactory();
            IWICComponentInfo componentInfo;
            var guid = GetType().GUID;

            imagingFactory.CreateComponentInfo(ref guid, out componentInfo);
            ppIDecoderInfo = (IWICBitmapDecoderInfo)componentInfo;

            Log.Trace("GetDecoderInfo finished");
        }
Пример #7
0
        protected override void RunOverride(MainForm form, object tag)
        {
            IWICImagingFactory    factory = (IWICImagingFactory) new WICImagingFactory();
            IWICBitmapDecoderInfo info    = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid);
            Guid cf;

            info.GetContainerFormat(out cf);
            IWICBitmapDecoder decoder = null;

            try
            {
                decoder = info.CreateInstance();
                Guid containerFormat;
                try
                {
                    decoder.GetContainerFormat(out containerFormat);
                    if (containerFormat != cf)
                    {
                        form.Add(this, Resources.ContainerFormatsDoNotMatch, new DataEntry(Resources.Actual, cf), new DataEntry(Resources.Expected, containerFormat));
                    }
                }
                catch (Exception e)
                {
                    form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(e));
                }

                ComponentInfoHelper.CheckEquals <IWICBitmapDecoderInfo>(form, decoder.GetDecoderInfo, this, Extensions.CompareInfos);
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
                decoder.ReleaseComObject();
            }

            base.RunOverride(form, tag);
        }
Пример #8
0
        IEnumerable <string> GetDecodableFiles(MainForm form, Guid decoderClsid)
        {
            IWICImagingFactory    factory = (IWICImagingFactory) new WICImagingFactory();
            IWICBitmapDecoderInfo info    = null;
            IWICBitmapDecoder     decoder = null;

            try
            {
                info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(decoderClsid);

                if (Settings.Default.Files != null)
                {
                    foreach (string s in Settings.Default.Files)
                    {
                        IWICStream stream = factory.CreateStream();
                        try
                        {
                            stream.InitializeFromFilename(s, NativeMethods.GenericAccessRights.GENERIC_READ);

                            bool matches = info.MatchesPattern(stream);
                            stream.Seek(0, 0, IntPtr.Zero);
                            decoder = info.CreateInstance();

                            if (decoder != null)
                            {
                                WICBitmapDecoderCapabilities?capabilities = null;

                                try
                                {
                                    capabilities = decoder.QueryCapability(stream);
                                    if (!matches)
                                    {
                                        QueryCapabilitiesError(form, string.Format(CultureInfo.CurrentUICulture, Resources.PatternDoesnotMatchButPassed, "IWICBitmapDecoder::QueryCapability(...)"), new DataEntry(s));
                                    }
                                }
                                catch (Exception e)
                                {
                                    if (Array.IndexOf(queryCapabilitiesErrors, (WinCodecError)Marshal.GetHRForException(e)) < 0)
                                    {
                                        QueryCapabilitiesError(form, e.TargetSite.ToString(Resources._0_FailedWithIncorrectHRESULT), new DataEntry(s), new DataEntry(Resources.Actual, e), new DataEntry(Resources.Expected, queryCapabilitiesErrors));
                                    }
                                }

                                if (capabilities.HasValue && 0 != (uint)(capabilities.Value & (WICBitmapDecoderCapabilities.WICBitmapDecoderCapabilityCanDecodeSomeImages | WICBitmapDecoderCapabilities.WICBitmapDecoderCapabilityCanDecodeAllImages)))
                                {
                                    yield return(s);
                                }
                            }
                        }
                        finally
                        {
                            stream.ReleaseComObject();
                            decoder.ReleaseComObject();
                            decoder = null;
                        }
                    }
                }
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
                decoder.ReleaseComObject();
            }
        }
Пример #9
0
        protected override void RunOverride(MainForm form, object tag)
        {
            bool hasFile   = false;
            bool processed = false;

            IWICImagingFactory    factory = (IWICImagingFactory) new WICImagingFactory();
            IWICBitmapDecoderInfo info    = null;
            IWICBitmapDecoder     decoder = null;

            try
            {
                info = (IWICBitmapDecoderInfo)factory.CreateComponentInfo(Parent.Clsid);
                foreach (string file in GetDecodableFiles(form, Parent.Clsid))
                {
                    decoder.ReleaseComObject();
                    decoder = info.CreateInstance();
                    hasFile = true;

                    IWICStream stream = factory.CreateStream();
                    stream.InitializeFromFilename(file, NativeMethods.GenericAccessRights.GENERIC_READ);
                    try
                    {
                        decoder.Initialize(stream, WICDecodeOptions.WICDecodeMetadataCacheOnDemand);

                        if (ProcessDecoder(form, decoder, new DataEntry[] { new DataEntry(file) }, tag))
                        {
                            for (uint index = 0; index < decoder.GetFrameCount(); index++)
                            {
                                IWICBitmapFrameDecode frame = decoder.GetFrame(index);
                                try
                                {
                                    if (ProcessFrameDecode(form, frame, new DataEntry[] { new DataEntry(file), new DataEntry(index) }, tag))
                                    {
                                        processed = true;
                                    }
                                }
                                finally
                                {
                                    frame.ReleaseComObject();
                                }
                            }
                        }
                        else
                        {
                            processed = true;
                        }
                    }
                    catch (Exception e)
                    {
                        form.Add(this, e.TargetSite.ToString(Resources._0_Failed), new DataEntry(file), new DataEntry(e));
                    }
                    finally
                    {
                        stream.ReleaseComObject();
                    }
                }
            }
            finally
            {
                factory.ReleaseComObject();
                info.ReleaseComObject();
                decoder.ReleaseComObject();
            }

            if (!hasFile)
            {
                form.Add(Parent, string.Format(CultureInfo.CurrentUICulture, Resources.NoFilesFor_0, Parent.Text));
            }
            else if (!processed)
            {
                form.Add(this, string.Format(CultureInfo.CurrentUICulture, Resources.NoFilesFor_0, Text));
            }
        }
        protected override void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info)
        {
            DataEntry[] de     = new DataEntry[] { new DataEntry("File Extension", ext) };
            string      progid = CheckStringValue(collection, rk, null, de);

            if (!string.IsNullOrEmpty(progid))
            {
                using (RegistryKey r = OpenSubKey(collection, rk, "OpenWithProgids", de))
                {
                    if (r != null)
                    {
                        if (Array.IndexOf(r.GetValueNames(), progid) < 0)
                        {
                            collection.Add(this, "Registry value is missing.", de, new DataEntry("Expected Values", progid), new DataEntry("Key", rk.ToString()));
                        }
                    }
                }
                using (RegistryKey r = OpenSubKey(collection, rk, string.Format(CultureInfo.InvariantCulture, "OpenWithList\\{0}", PhotoViewerDll), de))
                {
                }
                using (RegistryKey r = OpenSubKey(collection, rk, "ShelExt\\ContextMenuHandlers\\ShellImagePreview", de))
                {
                    CheckValue(collection, r, null, new string[] { PhotoGalleryGuid }, de);
                }

                using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, progid, new DataEntry[0]))
                {
                    CheckStringValue(collection, r, null, de);

                    using (RegistryKey r1 = OpenSubKey(collection, r, "DefaultIcon", new DataEntry[0]))
                    {
                        CheckStringValue(collection, r1, null, de);
                        // TODO get and check icon
                    }

                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open\\command", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, null, new string [] { "%SystemRoot%\\System32\\rundll32.exe \"%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll\", ImageView_Fullscreen %1" }, de);
                    }
                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, "MuiVerb", new string[] { "@%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll,-3043" }, de);
                    }
                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open\\DropTarget", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, "Clsid", new string[] { PhotoGalleryGuid }, de);
                    }
                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\printto\\command", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, null, new string[] { "%SystemRoot%\\System32\\rundll32.exe \"%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll\", ImageView_PrintTo /pt \"%1\" \"%2\" \"%3\" \"%4\"" }, de);
                    }
                }
            }

            using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "SystemFileAssociations\\{0}", ext), new DataEntry[0]))
            {
                using (RegistryKey r2 = OpenSubKey(collection, r, "ShellEx\\ContextMenuHandlers\\ShellImagePreview", de))
                {
                    CheckValue(collection, r2, null, new string[] { PhotoGalleryGuid }, de);
                }
            }
        }
Пример #11
0
 protected override void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info)
 {
     CheckValue(collection, rk, ContentType, Extensions.GetString(info.GetMimeTypes).Split(','), new DataEntry[] { new DataEntry("File Extension", ext) });
     CheckValue(collection, rk, PerceivedType, new string[] { "image" }, new DataEntry[] { new DataEntry("File Extension", ext) });
 }
 protected override void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info)
 {
     DataEntry[] de = new DataEntry[] { new DataEntry("File Extension", ext) };
     using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "{0}\\ShellEx\\{1}", ext, ShellExGuid), de))
     {
         CheckValue(collection, r, null, new string[] { ThumnailCacheGuid }, de);
     }
     using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "SystemFileAssociations\\{0}\\ShellEx\\{1}", ext, ShellExGuid), de))
     {
         CheckValue(collection, r, null, new string[] { ThumnailCacheGuid }, de);
     }
 }
Пример #13
0
        public void GetDecoderInfo(out IWICBitmapDecoderInfo ppIDecoderInfo)
        {
            Log.Trace("GetDecoderInfo called");

            var imagingFactory = GetImagingFactory();
            IWICComponentInfo componentInfo;
            var guid = GetType().GUID;
            imagingFactory.CreateComponentInfo(ref guid, out componentInfo);
            ppIDecoderInfo = (IWICBitmapDecoderInfo)componentInfo;

            Log.Trace("GetDecoderInfo finished");
        }
Пример #14
0
        protected override void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info)
        {
            DataEntry[] de = new DataEntry[] { new DataEntry("File Extension", ext)};
            string progid = CheckStringValue(collection, rk, null, de);
            if (!string.IsNullOrEmpty(progid))
            {
                using (RegistryKey r = OpenSubKey(collection, rk, "OpenWithProgids", de))
                {
                    if (r != null)
                    {
                        if (Array.IndexOf(r.GetValueNames(), progid) < 0)
                        {
                            collection.Add(this, "Registry value is missing.", de, new DataEntry("Expected Values", progid), new DataEntry("Key", rk.ToString()));
                        }
                    }
                }
                using (RegistryKey r = OpenSubKey(collection, rk, string.Format(CultureInfo.InvariantCulture, "OpenWithList\\{0}", PhotoViewerDll), de))
                {
                }
                using (RegistryKey r = OpenSubKey(collection, rk, "ShelExt\\ContextMenuHandlers\\ShellImagePreview", de))
                {
                    CheckValue(collection, r, null, new string[] { PhotoGalleryGuid }, de);
                }

                using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, progid, new DataEntry[0]))
                {
                    CheckStringValue(collection, r, null, de);

                    using (RegistryKey r1 = OpenSubKey(collection, r, "DefaultIcon", new DataEntry[0]))
                    {
                        CheckStringValue(collection, r1, null, de);
                        // TODO get and check icon
                    }

                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open\\command", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, null, new string []{"%SystemRoot%\\System32\\rundll32.exe \"%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll\", ImageView_Fullscreen %1"}, de);
                    }
                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, "MuiVerb", new string[] { "@%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll,-3043" }, de);
                    }
                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\open\\DropTarget", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, "Clsid", new string[] { PhotoGalleryGuid }, de);
                    }
                    using (RegistryKey r1 = OpenSubKey(collection, r, "shell\\printto\\command", new DataEntry[0]))
                    {
                        CheckValue(collection, r1, null, new string[] { "%SystemRoot%\\System32\\rundll32.exe \"%ProgramFiles%\\Windows Photo Gallery\\PhotoViewer.dll\", ImageView_PrintTo /pt \"%1\" \"%2\" \"%3\" \"%4\"" }, de);
                    }
                }
            }

            using (RegistryKey r = OpenSubKey(collection, Registry.ClassesRoot, string.Format(CultureInfo.InvariantCulture, "SystemFileAssociations\\{0}", ext), new DataEntry[0]))
            {
                using (RegistryKey r2 = OpenSubKey(collection, r, "ShellEx\\ContextMenuHandlers\\ShellImagePreview", de))
                {
                    CheckValue(collection, r2, null, new string[] { PhotoGalleryGuid }, de);
                }
            }
        }
Пример #15
0
 protected abstract void Check(ListView.ListViewItemCollection collection, string ext, RegistryKey rk, IWICBitmapDecoderInfo info);
Пример #16
0
        void Check(MainForm form, IWICBitmapDecoderInfo info, Tag tag)
        {
            ComponentInfoHelper.CheckNotReserverdGuid(form, info.GetContainerFormat, this);

            tag.PixelFormats = PixelFormatInfoRule.CheckPixelFormats(form, this, info.GetPixelFormats);

            ComponentInfoHelper.CheckVersion(form, info.GetColorManagementVersion, this);
            ComponentInfoHelper.CheckCommaSeparatedString(form, info.GetMimeTypes, ComponentInfoHelper.MimeMask, this);

            tag.Extensions = ComponentInfoHelper.CheckCommaSeparatedString(form, info.GetFileExtensions, ComponentInfoHelper.ExtensionMask, this);

            if (!info.DoesSupportMultiframe() && info.DoesSupportAnimation())
            {
                form.Add(this, Resources.DecoderAnimationIfMultiframe);
            }
            tag.SupportsMultiframe = info.DoesSupportMultiframe();

            uint count;
            uint size = info.GetPatterns(0, IntPtr.Zero, out count);
            if (size != 0)
            {
                IntPtr p = Marshal.AllocCoTaskMem((int)size);
                try
                {
                    info.GetPatterns(size, p, out count);

                    WICBitmapPattern[] patterns = PropVariantMarshaler.ToArrayOf<WICBitmapPattern>(p, (int)count);
                    int index = 0;
                    HashSet<int> dups = new HashSet<int>();
                    foreach (WICBitmapPattern pattern in patterns)
                    {
                        index++;
                        if (pattern.Length == 0)
                        {
                            form.Add(this, Resources.PatternZeroLength, new DataEntry(Resources.PatternIndex, index));
                        }
                        else if (index < patterns.Length)
                        {
                            if (Array.FindIndex(patterns, index, delegate(WICBitmapPattern obj) { return obj.EndOfStream == pattern.EndOfStream && obj.Position == pattern.Position && GetNormalizedMask(obj).ItemsEqual(GetNormalizedMask(pattern)); }) >= 0)
                            {
                                dups.Add(index);
                            }
                        }
                    }
                    if (dups.Count > 0)
                    {
                        form.Add(this, Resources.PatternDuplicated, new DataEntry(Resources.PatternIndices, dups.ToArray()));
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(p);
                }
            }

            if (count == 0 || size == 0)
            {
                form.Add(this, Resources.PatternNo);
            }
        }