Пример #1
0
        private short AddResource(uint ofType, IntPtr data)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.ResourceSuite, DebugUtils.PropToString(ofType));
#endif
            int size = HandleSuite.Instance.GetHandleSize(data);
            try
            {
                byte[] bytes = new byte[size];

                if (size > 0)
                {
                    Marshal.Copy(HandleSuite.Instance.LockHandle(data, 0), bytes, 0, size);
                    HandleSuite.Instance.UnlockHandle(data);
                }

                int index = CountResource(ofType) + 1;
                pseudoResources.Add(new PSResource(ofType, index, bytes));
            }
            catch (OutOfMemoryException)
            {
                return(PSError.memFullErr);
            }

            return(PSError.noErr);
        }
Пример #2
0
        private IntPtr GetResource(uint ofType, short index)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.ResourceSuite, string.Format("{0}, {1}", DebugUtils.PropToString(ofType), index));
#endif
            PSResource res = pseudoResources.Find(delegate(PSResource r)
            {
                return(r.Equals(ofType, index));
            });

            if (res != null)
            {
                byte[] data = res.GetDataReadOnly();

                IntPtr h = HandleSuite.Instance.NewHandle(data.Length);
                if (h != IntPtr.Zero)
                {
                    Marshal.Copy(data, 0, HandleSuite.Instance.LockHandle(h, 0), data.Length);
                    HandleSuite.Instance.UnlockHandle(h);
                }

                return(h);
            }

            return(IntPtr.Zero);
        }
Пример #3
0
        private short CountResource(uint ofType)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.ResourceSuite, DebugUtils.PropToString(ofType));
#endif
            short count = 0;

            foreach (var item in pseudoResources)
            {
                if (item.Equals(ofType))
                {
                    count++;
                }
            }

            return(count);
        }
Пример #4
0
        private void DeleteResource(uint ofType, short index)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.ResourceSuite, string.Format("{0}, {1}", DebugUtils.PropToString(ofType), index));
#endif
            int resourceIndex = pseudoResources.FindIndex(delegate(PSResource r)
            {
                return(r.Equals(ofType, index));
            });

            if (resourceIndex >= 0)
            {
                pseudoResources.RemoveAt(resourceIndex);

                int i = index + 1;

                while (true)
                {
                    // Renumber the index of subsequent items.
                    int next = pseudoResources.FindIndex(delegate(PSResource r)
                    {
                        return(r.Equals(ofType, i));
                    });

                    if (next < 0)
                    {
                        break;
                    }

                    PSResource existing = pseudoResources[next];
                    int        newIndex = i - 1;

                    pseudoResources[next] = new PSResource(existing, newIndex);

                    i++;
                }
            }
        }
Пример #5
0
        private short PropertySetProc(uint signature, uint key, int index, IntPtr simpleProperty, IntPtr complexProperty)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.PropertySuite, string.Format("Sig: {0}, Key: {1}, Index: {2}", DebugUtils.PropToString(signature), DebugUtils.PropToString(key), index));
#endif
            if (signature != PSConstants.kPhotoshopSignature)
            {
                return(PSError.errPlugInPropertyUndefined);
            }

            int    size  = 0;
            byte[] bytes = null;

            int simple = simpleProperty.ToInt32();

            try
            {
                switch (key)
                {
                case PSProperties.BigNudgeH:
                    break;

                case PSProperties.BigNudgeV:
                    break;

                case PSProperties.Caption:
                    size = HandleSuite.Instance.GetHandleSize(complexProperty);
                    if (size > 0)
                    {
                        string caption = IPTCData.CaptionFromMemory(HandleSuite.Instance.LockHandle(complexProperty, 0));
                        HandleSuite.Instance.UnlockHandle(complexProperty);

                        if (!string.IsNullOrEmpty(caption))
                        {
                            hostInfo.Caption = caption;
                        }
                    }
                    break;

                case PSProperties.Copyright:
                case PSProperties.Copyright2:
                    hostInfo.Copyright = simple != 0;
                    break;

                case PSProperties.EXIFData:
                case PSProperties.XMPData:
                    break;

                case PSProperties.GridMajor:
                    break;

                case PSProperties.GridMinor:
                    break;

                case PSProperties.RulerOriginH:
                    break;

                case PSProperties.RulerOriginV:
                    break;

                case PSProperties.URL:
                    size = HandleSuite.Instance.GetHandleSize(complexProperty);
                    if (size > 0)
                    {
                        bytes = new byte[size];
                        Marshal.Copy(HandleSuite.Instance.LockHandle(complexProperty, 0), bytes, 0, size);
                        HandleSuite.Instance.UnlockHandle(complexProperty);

                        Uri temp;
                        if (Uri.TryCreate(Encoding.ASCII.GetString(bytes, 0, size), UriKind.Absolute, out temp))
                        {
                            hostInfo.Url = temp;
                        }
                    }
                    break;

                case PSProperties.WatchSuspension:
                    break;

                case PSProperties.Watermark:
                    hostInfo.Watermark = simple != 0;
                    break;

                default:
                    return(PSError.errPlugInPropertyUndefined);
                }
            }
            catch (OutOfMemoryException)
            {
                return(PSError.memFullErr);
            }

            return(PSError.noErr);
        }
Пример #6
0
        private unsafe short PropertyGetProc(uint signature, uint key, int index, ref IntPtr simpleProperty, ref IntPtr complexProperty)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.PropertySuite, string.Format("Sig: {0}, Key: {1}, Index: {2}", DebugUtils.PropToString(signature), DebugUtils.PropToString(key), index));
#endif
            if (signature != PSConstants.kPhotoshopSignature)
            {
                return(PSError.errPlugInPropertyUndefined);
            }

            byte[] bytes = null;

            short err = PSError.noErr;
            try
            {
                switch (key)
                {
                case PSProperties.BigNudgeH:
                case PSProperties.BigNudgeV:
                    simpleProperty = new IntPtr(new Fixed16(PSConstants.Properties.BigNudgeDistance).Value);
                    break;

                case PSProperties.Caption:
                    if (IPTCData.TryCreateCaptionRecord(hostInfo.Caption, out bytes))
                    {
                        complexProperty = HandleSuite.Instance.NewHandle(bytes.Length);

                        if (complexProperty != IntPtr.Zero)
                        {
                            Marshal.Copy(bytes, 0, HandleSuite.Instance.LockHandle(complexProperty, 0), bytes.Length);
                            HandleSuite.Instance.UnlockHandle(complexProperty);
                        }
                        else
                        {
                            err = PSError.memFullErr;
                        }
                    }
                    else
                    {
                        if (complexProperty != IntPtr.Zero)
                        {
                            complexProperty = HandleSuite.Instance.NewHandle(0);
                        }
                    }
                    break;

                case PSProperties.ChannelName:
                    if (index < 0 || index >= numberOfChannels)
                    {
                        return(PSError.errPlugInPropertyUndefined);
                    }

                    string name = string.Empty;

                    if (imageMode == ImageModes.GrayScale || imageMode == ImageModes.Gray16)
                    {
                        switch (index)
                        {
                        case 0:
                            name = Resources.GrayChannelName;
                            break;
                        }
                    }
                    else
                    {
                        switch (index)
                        {
                        case 0:
                            name = Resources.RedChannelName;
                            break;

                        case 1:
                            name = Resources.GreenChannelName;
                            break;

                        case 2:
                            name = Resources.BlueChannelName;
                            break;

                        case 3:
                            name = Resources.AlphaChannelName;
                            break;
                        }
                    }

                    bytes = Encoding.ASCII.GetBytes(name);

                    complexProperty = HandleSuite.Instance.NewHandle(bytes.Length);
                    if (complexProperty != IntPtr.Zero)
                    {
                        Marshal.Copy(bytes, 0, HandleSuite.Instance.LockHandle(complexProperty, 0), bytes.Length);
                        HandleSuite.Instance.UnlockHandle(complexProperty);
                    }
                    else
                    {
                        err = PSError.memFullErr;
                    }
                    break;

                case PSProperties.Copyright:
                case PSProperties.Copyright2:
                    simpleProperty = new IntPtr(hostInfo.Copyright ? 1 : 0);
                    break;

                case PSProperties.EXIFData:
                case PSProperties.XMPData:

                    if (imageMetaData.Extract(out bytes, key == PSProperties.EXIFData))
                    {
                        complexProperty = HandleSuite.Instance.NewHandle(bytes.Length);
                        if (complexProperty != IntPtr.Zero)
                        {
                            Marshal.Copy(bytes, 0, HandleSuite.Instance.LockHandle(complexProperty, 0), bytes.Length);
                            HandleSuite.Instance.UnlockHandle(complexProperty);
                        }
                        else
                        {
                            err = PSError.memFullErr;
                        }
                    }
                    else
                    {
                        if (complexProperty != IntPtr.Zero)
                        {
                            // If the complexProperty is not IntPtr.Zero we return a valid zero byte handle,
                            // otherwise some filters will crash with an access violation.
                            complexProperty = HandleSuite.Instance.NewHandle(0);
                        }
                    }
                    break;

                case PSProperties.GridMajor:
                    simpleProperty = new IntPtr(new Fixed16(PSConstants.Properties.GridMajor).Value);
                    break;

                case PSProperties.GridMinor:
                    simpleProperty = new IntPtr(PSConstants.Properties.GridMinor);
                    break;

                case PSProperties.ImageMode:
                    simpleProperty = new IntPtr((int)imageMode);
                    break;

                case PSProperties.InterpolationMethod:
                    simpleProperty = new IntPtr(PSConstants.Properties.InterpolationMethod.NearestNeghbor);
                    break;

                case PSProperties.NumberOfChannels:
                    simpleProperty = new IntPtr(numberOfChannels);
                    break;

                case PSProperties.NumberOfPaths:
                    simpleProperty = new IntPtr(0);
                    break;

                case PSProperties.PathName:
                    if (complexProperty != IntPtr.Zero)
                    {
                        complexProperty = HandleSuite.Instance.NewHandle(0);
                    }
                    break;

                case PSProperties.WorkPathIndex:
                case PSProperties.ClippingPathIndex:
                case PSProperties.TargetPathIndex:
                    simpleProperty = new IntPtr(PSConstants.Properties.NoPathIndex);
                    break;

                case PSProperties.RulerUnits:
                    simpleProperty = new IntPtr((int)hostInfo.RulerUnit);
                    break;

                case PSProperties.RulerOriginH:
                case PSProperties.RulerOriginV:
                    simpleProperty = new IntPtr(new Fixed16(0).Value);
                    break;

                case PSProperties.Watermark:
                    simpleProperty = new IntPtr(hostInfo.Watermark ? 1 : 0);
                    break;

                case PSProperties.SerialString:
                    bytes           = Encoding.ASCII.GetBytes(hostSerial);
                    complexProperty = HandleSuite.Instance.NewHandle(bytes.Length);

                    if (complexProperty != IntPtr.Zero)
                    {
                        Marshal.Copy(bytes, 0, HandleSuite.Instance.LockHandle(complexProperty, 0), bytes.Length);
                        HandleSuite.Instance.UnlockHandle(complexProperty);
                    }
                    else
                    {
                        err = PSError.memFullErr;
                    }
                    break;

                case PSProperties.URL:
                    if (hostInfo.Url != null)
                    {
                        bytes           = Encoding.ASCII.GetBytes(hostInfo.Url.ToString());
                        complexProperty = HandleSuite.Instance.NewHandle(bytes.Length);

                        if (complexProperty != IntPtr.Zero)
                        {
                            Marshal.Copy(bytes, 0, HandleSuite.Instance.LockHandle(complexProperty, 0), bytes.Length);
                            HandleSuite.Instance.UnlockHandle(complexProperty);
                        }
                        else
                        {
                            err = PSError.memFullErr;
                        }
                    }
                    else
                    {
                        if (complexProperty != IntPtr.Zero)
                        {
                            complexProperty = HandleSuite.Instance.NewHandle(0);
                        }
                    }
                    break;

                case PSProperties.Title:
                case PSProperties.UnicodeTitle:
                    string title;
                    if (!string.IsNullOrEmpty(hostInfo.Title))
                    {
                        title = hostInfo.Title;
                    }
                    else
                    {
                        title = "temp.png";
                    }

                    if (key == PSProperties.UnicodeTitle)
                    {
                        bytes = Encoding.Unicode.GetBytes(title);
                    }
                    else
                    {
                        bytes = Encoding.ASCII.GetBytes(title);
                    }
                    complexProperty = HandleSuite.Instance.NewHandle(bytes.Length);

                    if (complexProperty != IntPtr.Zero)
                    {
                        Marshal.Copy(bytes, 0, HandleSuite.Instance.LockHandle(complexProperty, 0), bytes.Length);
                        HandleSuite.Instance.UnlockHandle(complexProperty);
                    }
                    else
                    {
                        err = PSError.memFullErr;
                    }

                    break;

                case PSProperties.WatchSuspension:
                    simpleProperty = new IntPtr(0);
                    break;

                case PSProperties.DocumentWidth:
                    simpleProperty = new IntPtr(documentWidth);
                    break;

                case PSProperties.DocumentHeight:
                    simpleProperty = new IntPtr(documentHeight);
                    break;

                case PSProperties.ToolTips:
                    simpleProperty = new IntPtr(1);
                    break;

                case PSProperties.HighDPI:
                    simpleProperty = new IntPtr(hostInfo.HighDpi ? 1 : 0);
                    break;

                default:
                    return(PSError.errPlugInPropertyUndefined);
                }
            }
            catch (OutOfMemoryException)
            {
                err = PSError.memFullErr;
            }

            return(err);
        }
Пример #7
0
        private static unsafe bool EnumPiMI(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam)
        {
            GCHandle    handle = GCHandle.FromIntPtr(lParam);
            QueryFilter query  = (QueryFilter)handle.Target;

            IntPtr hRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, lpszType);

            if (hRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for PiMI in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr loadRes = UnsafeNativeMethods.LoadResource(hModule, hRes);
            if (loadRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for PiMI in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr lockRes = UnsafeNativeMethods.LockResource(loadRes);
            if (lockRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for PiMI in {0}", query.fileName));
#endif
                return(true);
            }
            int   length = 0;
            byte *ptr    = (byte *)lockRes.ToPointer() + 2L;

            string category = StringUtil.FromCString((IntPtr)ptr, out length);

            ptr += length;

            if (string.IsNullOrEmpty(category))
            {
                category = PSFilterHostDll.Properties.Resources.PiMIDefaultCategoryName;
            }

            PlugInInfo *info = (PlugInInfo *)ptr;

            if (info->version > PSConstants.latestFilterVersion ||
                (info->version == PSConstants.latestFilterVersion && info->subVersion > PSConstants.latestFilterSubVersion))
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("{0} requires newer filter interface version {1}.{2} and only version {3}.{4} is supported",
                                                                 new object[] { query.fileName, info->version, info->subVersion, PSConstants.latestFilterVersion, PSConstants.latestFilterSubVersion }));
#endif
                return(true);
            }

#if GDIPLUS
            // All GDI+ images are converted to 8-bit RGB(A) for processing.
            if ((info->supportsMode & PSConstants.supportsRGBColor) != PSConstants.supportsRGBColor)
            {
                return(true);
            }
#else
            if ((info->supportsMode & PSConstants.supportsRGBColor) != PSConstants.supportsRGBColor &&
                (info->supportsMode & PSConstants.supportsGrayScale) != PSConstants.supportsGrayScale)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("{0} does not support the plugInModeRGBColor or plugInModeGrayScale image modes.", query.fileName));
#endif
                return(true);
            }
#endif
            // Add the supported modes to the plug-in data as it can be used later to disable filters that do not support the image type.
            ushort supportedModes = 0;
            if ((info->supportsMode & PSConstants.supportsGrayScale) == PSConstants.supportsGrayScale)
            {
                supportedModes |= PSConstants.flagSupportsGrayScale;
            }

            if ((info->supportsMode & PSConstants.supportsRGBColor) == PSConstants.supportsRGBColor)
            {
                supportedModes |= PSConstants.flagSupportsRGBColor;
            }

            if (info->requireHost != PSConstants.kPhotoshopSignature && info->requireHost != PSConstants.AnyHostSignature)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("{0} requires host '{1}'.", query.fileName, DebugUtils.PropToString(info->requireHost)));
#endif
                return(true);
            }

            IntPtr filterRes = IntPtr.Zero;

            fixed(char *typePtr = "_8BFM")
            {
                // Load the _8BFM resource to get the filter title.
                filterRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, (IntPtr)typePtr);
            }

            if (filterRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for _8BFM in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr filterLoad = UnsafeNativeMethods.LoadResource(hModule, filterRes);

            if (filterLoad == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for _8BFM in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr filterLock = UnsafeNativeMethods.LockResource(filterLoad);

            if (filterLock == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for _8BFM in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr resPtr = new IntPtr(filterLock.ToInt64() + 2L);

            string title = StringUtil.FromCString(resPtr);

            // The entry point number is the same as the resource number.
            string entryPoint = "ENTRYPOINT" + lpszName.ToInt32().ToString(CultureInfo.InvariantCulture);

            PluginData pluginData = new PluginData(query.fileName, entryPoint, category, title, supportedModes);

            if (pluginData.IsValid())
            {
                query.plugins.Add(pluginData);
                handle.Target = query;
                lParam        = GCHandle.ToIntPtr(handle);
            }

            return(true);
        }
Пример #8
0
        private static unsafe bool EnumPiPL(IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam)
        {
            GCHandle    handle = GCHandle.FromIntPtr(lParam);
            QueryFilter query  = (QueryFilter)handle.Target;

            IntPtr hRes = UnsafeNativeMethods.FindResourceW(hModule, lpszName, lpszType);

            if (hRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("FindResource failed for PiPL in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr loadRes = UnsafeNativeMethods.LoadResource(hModule, hRes);
            if (loadRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("LoadResource failed for PiPL in {0}", query.fileName));
#endif
                return(true);
            }

            IntPtr lockRes = UnsafeNativeMethods.LockResource(loadRes);
            if (lockRes == IntPtr.Zero)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("LockResource failed for PiPL in {0}", query.fileName));
#endif

                return(true);
            }

#if DEBUG
            short fb = Marshal.ReadInt16(lockRes);             // PiPL Resources always start with 1, this seems to be Photoshop's signature.
#endif
            int version = Marshal.ReadInt32(lockRes, 2);

            if (version != PSConstants.latestPIPLVersion)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("Invalid PiPL version in {0}: {1}, Expected version {2}", query.fileName, version, PSConstants.latestPIPLVersion));
#endif
                return(true);
            }

            int count = Marshal.ReadInt32(lockRes, 6);

            byte *propPtr = (byte *)lockRes.ToPointer() + 10L;

            string           entryPoint     = null;
            string           category       = null;
            string           title          = null;
            FilterCaseInfo[] filterInfo     = null;
            PluginAETE       aete           = null;
            string           enableInfo     = null;
            ushort?          supportedModes = null;
            bool             hasAboutBox    = true;

            uint platformEntryPoint = IntPtr.Size == 8 ? PIPropertyID.PIWin64X86CodeProperty : PIPropertyID.PIWin32X86CodeProperty;

            for (int i = 0; i < count; i++)
            {
                PIProperty *pipp           = (PIProperty *)propPtr;
                uint        propKey        = pipp->propertyKey;
                int         propertyLength = pipp->propertyLength;

                byte *dataPtr = propPtr + PIProperty.SizeOf;
                if (propKey == PIPropertyID.PIKindProperty)
                {
                    if (*((uint *)dataPtr) != PSConstants.filterKind)
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine(string.Format("{0} is not a valid Photoshop filter.", query.fileName));
#endif
                        return(true);
                    }
                }
                else if (propKey == platformEntryPoint)
                {
                    entryPoint = Marshal.PtrToStringAnsi((IntPtr)dataPtr, propertyLength).TrimEnd('\0');
                }
                else if (propKey == PIPropertyID.PIVersionProperty)
                {
                    int packedVersion = *(int *)dataPtr;
                    int major         = (packedVersion >> 16);
                    int minor         = (packedVersion & 0xffff);

                    if (major > PSConstants.latestFilterVersion ||
                        major == PSConstants.latestFilterVersion && minor > PSConstants.latestFilterSubVersion)
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine(string.Format("{0} requires newer filter interface version {1}.{2} and only version {3}.{4} is supported",
                                                                         new object[] { query.fileName, major, minor, PSConstants.latestFilterVersion, PSConstants.latestFilterSubVersion }));
#endif
                        return(true);
                    }
                }
                else if (propKey == PIPropertyID.PIImageModesProperty)
                {
#if GDIPLUS
                    // All GDI+ images are converted to 8-bit RGB(A) for processing.
                    if ((dataPtr[0] & PSConstants.flagSupportsRGBColor) != PSConstants.flagSupportsRGBColor)
                    {
                        return(true);
                    }
#else
                    if ((dataPtr[0] & PSConstants.flagSupportsRGBColor) != PSConstants.flagSupportsRGBColor &&
                        (dataPtr[0] & PSConstants.flagSupportsGrayScale) != PSConstants.flagSupportsGrayScale)
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine(string.Format("{0} does not support the plugInModeRGBColor or plugInModeGrayScale image modes.", query.fileName));
#endif
                        return(true);
                    }
#endif
                    supportedModes = *(ushort *)dataPtr;
                }
                else if (propKey == PIPropertyID.PICategoryProperty)
                {
                    category = StringUtil.FromPascalString(dataPtr);
                }
                else if (propKey == PIPropertyID.PINameProperty)
                {
                    title = StringUtil.FromPascalString(dataPtr);
                }
                else if (propKey == PIPropertyID.PIFilterCaseInfoProperty)
                {
                    FilterCaseInfoResult result = FilterCaseInfoParser.Parse(dataPtr, propertyLength);

                    if (result != null)
                    {
                        filterInfo = result.filterCaseInfo;
                        // The actual property length may be longer than the header specifies
                        // if the FilterCaseInfo fields are incorrectly escaped.
                        if (propertyLength != result.propertyLength)
                        {
                            propertyLength = result.propertyLength;
                        }
                    }
                }
                else if (propKey == PIPropertyID.PIHasTerminologyProperty)
                {
                    PITerminology *term = (PITerminology *)dataPtr;
                    if (term->version == PSConstants.LatestTerminologyVersion)
                    {
#if DEBUG
                        string aeteName = Marshal.PtrToStringAnsi(new IntPtr(dataPtr + PITerminology.SizeOf)).TrimEnd('\0');
#endif
                        QueryAETE queryAETE = new QueryAETE(term->terminologyID);

                        GCHandle aeteHandle = GCHandle.Alloc(queryAETE, GCHandleType.Normal);
                        try
                        {
                            IntPtr callback = GCHandle.ToIntPtr(aeteHandle);
                            if (!UnsafeNativeMethods.EnumResourceNamesW(hModule, "AETE", new UnsafeNativeMethods.EnumResNameDelegate(EnumAETE), callback))
                            {
                                queryAETE = (QueryAETE)GCHandle.FromIntPtr(callback).Target;
                            }
                        }
                        finally
                        {
                            if (aeteHandle.IsAllocated)
                            {
                                aeteHandle.Free();
                            }
                        }

                        if (queryAETE.enumAETE != null)
                        {
                            aete = queryAETE.enumAETE;
                        }
                    }
                }
                else if (propKey == PIPropertyID.EnableInfo)
                {
                    enableInfo = Marshal.PtrToStringAnsi((IntPtr)dataPtr, propertyLength).TrimEnd('\0');
                }
                else if (propKey == PIPropertyID.PIRequiredHostProperty)
                {
                    uint host = *(uint *)dataPtr;
                    if (host != PSConstants.kPhotoshopSignature && host != PSConstants.AnyHostSignature)
                    {
#if DEBUG
                        System.Diagnostics.Debug.WriteLine(string.Format("{0} requires host '{1}'.", query.fileName, DebugUtils.PropToString(host)));
#endif
                        return(true);
                    }
                }
                else if (propKey == PIPropertyID.NoAboutBox)
                {
                    hasAboutBox = false;
                }
#if DEBUG
                else
                {
                    DebugUtils.Ping(DebugFlags.PiPL, string.Format("Unsupported property '{0}' in {1}", DebugUtils.PropToString(propKey), query.fileName));
                }
#endif

                // The property data is padded to a 4 byte boundary.
                int propertyDataPaddedLength = (propertyLength + 3) & ~3;
                propPtr += (PIProperty.SizeOf + propertyDataPaddedLength);
            }

            PluginData pluginData = new PluginData(query.fileName, entryPoint, category, title, filterInfo, aete, enableInfo, supportedModes, hasAboutBox);

            if (pluginData.IsValid())
            {
                query.plugins.Add(pluginData);
                handle.Target = query;
                lParam        = GCHandle.ToIntPtr(handle);
            }

            return(true);
        }
Пример #9
0
        private short PutStringProc(IntPtr descriptor, uint key, IntPtr stringHandle)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: 0x{0:X4}({1})", key, DebugUtils.PropToString(key)));
#endif
            try
            {
                int    size = Marshal.ReadByte(stringHandle);
                byte[] data = new byte[size];
                Marshal.Copy(new IntPtr(stringHandle.ToInt64() + 1L), data, 0, size);

                writeDescriptors[descriptor].AddOrUpdate(key, new AETEValue(DescriptorTypes.Char, GetAETEParamFlags(key), size, data));
            }
            catch (OutOfMemoryException)
            {
                return(PSError.memFullErr);
            }

            return(PSError.noErr);
        }
Пример #10
0
        private short PutObjectProc(IntPtr descriptor, uint key, uint type, IntPtr descriptorHandle)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: {0}, type: {1}", DebugUtils.PropToString(key), DebugUtils.PropToString(type)));
#endif
            try
            {
                // If the handle is a sub key add it to the parent descriptor.
                Dictionary <uint, AETEValue> subKeys;
                if (descriptorHandles.TryGetValue(descriptorHandle, out subKeys))
                {
                    writeDescriptors[descriptor].AddOrUpdate(key, new AETEValue(type, GetAETEParamFlags(key), 0, subKeys));
                    descriptorHandles.Remove(descriptorHandle);
                }
                else
                {
                    return(PSError.paramErr);
                }
            }
            catch (OutOfMemoryException)
            {
                return(PSError.memFullErr);
            }

            return(PSError.noErr);
        }
Пример #11
0
        private short PutIntegerProc(IntPtr descriptor, uint key, int data)
        {
#if DEBUG
            DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: 0x{0:X4}({1})", key, DebugUtils.PropToString(key)));
#endif
            try
            {
                writeDescriptors[descriptor].AddOrUpdate(key, new AETEValue(DescriptorTypes.Integer, GetAETEParamFlags(key), 0, data));
            }
            catch (OutOfMemoryException)
            {
                return(PSError.memFullErr);
            }

            return(PSError.noErr);
        }