/// <summary> /// Initializes a new instance of the <see cref="PluginData"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="resourceName">Name of the resource.</param> /// <param name="resourceLanguage">The resource language.</param> /// <param name="piplProperties">The properties.</param> public PluginData(string path, PIPLResourceName resourceName, ushort resourceLanguage, PIProperty[] piplProperties) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if (resourceName == null) { throw new ArgumentNullException(nameof(resourceName)); } if (piplProperties == null) { throw new ArgumentNullException(nameof(piplProperties)); } this.path = path; this.resourceName = resourceName; this.resourceLanguage = resourceLanguage; int propertyArrayLength = piplProperties.Length; if (piplProperties[propertyArrayLength - 1].Key != PIPropertyID.PICategoryProperty) { // Reserve space for a new category property at the end of the array. propertyArrayLength++; } properties = new PIProperty[propertyArrayLength]; piplProperties.CopyTo(properties, 0); newCategoryIndex = properties.Length - 1; for (int i = 0; i < piplProperties.Length; i++) { PIProperty prop = piplProperties[i]; switch (prop.Key) { case PIPropertyID.PICategoryProperty: category = PascalStringHelpers.ConvertToString(prop.GetPropertyDataReadOnly()); break; case PIPropertyID.PINameProperty: title = PascalStringHelpers.ConvertToString(prop.GetPropertyDataReadOnly()); break; } } dirty = false; }
private static unsafe bool EnumPIPL(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam) { GCHandle handle = GCHandle.FromIntPtr(lParam); QueryPlugin data = (QueryPlugin)handle.Target; IntPtr hRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, lpszType); if (hRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "FindResource failed for PiPL in {0}", data.path)); #endif return(true); } IntPtr loadRes = UnsafeNativeMethods.LoadResource(hModule, hRes); if (loadRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "LoadResource failed for PiPL in {0}", data.path)); #endif return(true); } IntPtr lockRes = UnsafeNativeMethods.LockResource(loadRes); if (lockRes == IntPtr.Zero) { #if DEBUG System.Diagnostics.Debug.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "LockResource failed for PiPL in {0}", data.path)); #endif return(true); } short signature = Marshal.ReadInt16(lockRes); if (signature == PIPLConstants.ResourceSignature) { int version = Marshal.ReadInt32(lockRes, 2); if (version == PIPLConstants.ResourceVersion) { int count = Marshal.ReadInt32(lockRes, 6); if (count > 0) { byte *propPtr = (byte *)lockRes.ToPointer() + PIPLConstants.ResourceHeaderSize; PIProperty[] properties = new PIProperty[count]; for (int i = 0; i < count; i++) { PIProperty property = new PIProperty(propPtr); if (property.Key == PIPropertyID.PIKindProperty) { const uint FilterKind = 0x3842464d; // 8BFM if (BitConverter.ToUInt32(property.GetPropertyDataReadOnly(), 0) != FilterKind) { // Skip any PiPL resources that are not filters. return(true); } } properties[i] = property; propPtr += property.TotalLength; } // Get the language that the PiPL resource is stored in. ushort language = 0; UnsafeNativeMethods.EnumResourceLanguagesW(hModule, lpszType, lpszName, EnumResourceLanguages, new IntPtr(&language)); data.plugins.Add(new PluginData(data.path, GetPIPLResourceName(lpszName), language, properties)); handle.Target = data; } } } return(true); }