コード例 #1
0
ファイル: Plugin.cs プロジェクト: reliefpfeiler42/Fusee
        private void CheckDll(FileInfo fi)
        {
            Logger.Debug("CheckDll(" + fi.FullName + ")");

            Assembly plugIn;

            try
            {
                plugIn = Assembly.LoadFrom(fi.FullName);
            }
            catch (BadImageFormatException)
            {
                // Swallow this because we could just step over an unmanaged dll
                return;
            }

            if (plugIn == null)
            {
                return;
            }
            try
            {
                foreach (Type t in plugIn.GetTypes())
                {
                    // Is it a "generic" plugin?
                    if (t.IsDefined(typeof(PluginAttribute), true))
                    {
                        PluginAttribute attr =
                            (PluginAttribute)Attribute.GetCustomAttribute(t, typeof(PluginAttribute), true);
                        Logger.Debug("  Class " + t.Name + " is attributed with [Plugin]");

                        MethodInfo miStart = t.GetMethod("Start", BindingFlags.Instance | BindingFlags.Public);
                        if (miStart == null)
                        {
                            Logger.Warn("Class " + t.Name + " in " + fi.Name + " seems suitable as a plugin but is missing the Start() method");
                        }
                        MethodInfo miEnd = t.GetMethod("End", BindingFlags.Instance | BindingFlags.Public);
                        if (miStart == null)
                        {
                            Logger.Warn("Class " + t.Name + " in " + fi.Name + " seems suitable as a plugin but is missing the End() method");
                        }

                        if (miStart != null && miEnd != null)
                        {
                            // We have a class
                            ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                object     instance = ctor.Invoke(null);
                                MethodInfo mi       = t.GetMethod("Start");
                                _pluginInstanceList.Add(instance);
                                object ret = mi.Invoke(instance, null);

                                // TODO: Do something with the return value
                            }
                            else
                            {
                                Logger.Warn("Class " + t.Name + " in " + fi.Name + " is missing a parameterless constructor");
                            }
                        }
                    }
                    // Or is it an attributed CommandPlugin ?
                    else if (t.IsDefined(typeof(CommandPluginAttribute), true))
                    {
                        CommandPluginAttribute attr =
                            (CommandPluginAttribute)Attribute.GetCustomAttribute(t, typeof(CommandPluginAttribute), true);
                        Logger.Debug("  Class " + t.Name + " is attributed with [CommandPlugin(ID=" + attr.ID + ", Name=\"" +
                                     attr.Name + "\")]");

                        if (InheritsFrom(t, typeof(CommandData)))
                        {
                            // Register the command plugin
                            string     name;
                            BaseBitmap bmp;
                            GetPluginDescription(t, attr, out name, out bmp);
                            // Fallback help text
                            string helpText = attr.HelpText;
                            if (string.IsNullOrEmpty(helpText))
                            {
                                helpText = "Execute the " + name + " command.";
                            }

                            ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                CommandData commandData = (CommandData)ctor.Invoke(null);
                                C4dApi.RegisterCommandPlugin(attr.ID, name, 0, bmp, helpText, commandData);
                            }
                            else
                            {
                                Logger.Warn("Class " + t.Name + " in " + fi.Name + " is missing a parameterless constructor");
                            }
                        }
                        else
                        {
                            Logger.Warn("  Class " + t.Name + " in " + fi.Name +
                                        " is attributed with [CommandPlugin] but does not inherit from CommandData");
                        }
                    }
                    // Or is it an attributed ObjectPlugin ?
                    else if (t.IsDefined(typeof(ObjectPluginAttribute), true))
                    {
                        ObjectPluginAttribute attr = (ObjectPluginAttribute)Attribute.GetCustomAttribute(t, typeof(ObjectPluginAttribute), true);
                        Logger.Debug("  Class " + t.Name + " is attributed with [ObjectPlugin(ID=" + attr.ID + ", Name=\"" +
                                     attr.Name + "\")]");

                        if (InheritsFrom(t, typeof(ObjectDataM)))
                        {
                            // Register the object plugin
                            string     name;
                            BaseBitmap bmp;
                            GetPluginDescription(t, attr, out name, out bmp);

                            ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                PluginAllocator   pa  = new PluginAllocator(ctor);
                                NodeDataAllocator nda = pa.Allocate;
                                _nodeAllocatorList.Add(nda);
                                C4dApi.RegisterObjectPlugin(attr.ID, name, attr.Info, nda, "obase", bmp, 0);
                            }
                            else
                            {
                                Logger.Warn("Class " + t.Name + " in " + fi.Name + " is missing a parameterless constructor");
                            }
                        }
                        else
                        {
                            Logger.Warn("  Class " + t.Name + " in " + fi.Name +
                                        " is attributed with [ObjectPlugin] but does not inherit from ObjectDataM");
                        }
                    }
                    // Or is it an attributed TagPlugin ?
                    else if (t.IsDefined(typeof(TagPluginAttribute), true))
                    {
                        TagPluginAttribute attr = (TagPluginAttribute)Attribute.GetCustomAttribute(t, typeof(TagPluginAttribute), true);
                        Logger.Debug("  Class " + t.Name + " is attributed with [TagPlugin(ID=" + attr.ID + ", Name=\"" +
                                     attr.Name + "\")]");

                        if (InheritsFrom(t, typeof(TagDataM)))
                        {
                            // Register the tag plugin
                            string     name;
                            BaseBitmap bmp;
                            GetPluginDescription(t, attr, out name, out bmp);

                            ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                PluginAllocator   pa  = new PluginAllocator(ctor);
                                NodeDataAllocator nda = pa.Allocate;
                                _nodeAllocatorList.Add(nda);
                                // C4dApi.RegisterTagPlugin(attr.ID, name, attr.Info, nda, "tbase", bmp, 0);
                                C4dApi.RegisterTagPlugin(attr.ID, name, attr.Info, nda, "", bmp, 0);
                            }
                            else
                            {
                                Logger.Warn("Class " + t.Name + " in " + fi.Name + " is missing a parameterless constructor");
                            }
                        }
                        else
                        {
                            Logger.Warn("  Class " + t.Name + " in " + fi.Name +
                                        " is attributed with [TagPlugin] but does not inherit from TagDataM");
                        }
                    }

                    // Or is it an attributed SceneSaverPlugin?
                    else if (t.IsDefined(typeof(SceneSaverPluginAttribute), true))
                    {
                        SceneSaverPluginAttribute attr =
                            (SceneSaverPluginAttribute)
                            Attribute.GetCustomAttribute(t, typeof(SceneSaverPluginAttribute), true);
                        Logger.Debug("  Class " + t.Name + " is attributed with [SceneSaverPlugin(ID=" + attr.ID +
                                     ", Name=\"" +
                                     attr.Name + "\")]");

                        if (InheritsFrom(t, typeof(SceneSaverData)))
                        {
                            // Register the object plugin
                            string     name;
                            BaseBitmap bmp;
                            GetPluginDescription(t, attr, out name, out bmp);

                            ConstructorInfo ctor = t.GetConstructor(Type.EmptyTypes);
                            if (ctor != null)
                            {
                                PluginAllocator   pa  = new PluginAllocator(ctor);
                                NodeDataAllocator nda = pa.Allocate;
                                _nodeAllocatorList.Add(nda);
                                C4dApi.RegisterSceneSaverPlugin(attr.ID, name, attr.Info, nda, "obase", attr.Suffix);
                            }
                            else
                            {
                                Logger.Warn("Class " + t.Name + " in " + fi.Name + " is missing a parameterless constructor");
                            }
                        }
                        else
                        {
                            Logger.Warn("  Class " + t.Name + " in " + fi.Name +
                                        " is attributed with [ObjectPlugin] but does not inherit from ObjectData");
                        }
                    }
                }
            }
            catch (System.TypeLoadException tlx)
            {
                Logger.Warn("  EXCEPTION while attempting to check " + plugIn.CodeBase + " for managed C4D PlugIns. " + tlx);
                throw;
            }
        }
コード例 #2
0
ファイル: C4dApi.cs プロジェクト: KilledChicken/Fusee
 public static void FillNodePlugin(SWIGTYPE_p_NODEPLUGIN np, int info, NodeDataAllocator /* DataAllocator*_cstype */ g, BaseBitmap icon, int disklevel) {
   C4dApiPINVOKE.FillNodePlugin__SWIG_1(SWIGTYPE_p_NODEPLUGIN.getCPtr(np), info, g /* DataAllocator*_csin */, BaseBitmap.getCPtr(icon), disklevel);
 }
コード例 #3
0
ファイル: C4dApi.cs プロジェクト: KilledChicken/Fusee
 public static bool RegisterNodePlugin(int id, string /* constString&_cstype */ str, int info, NodeDataAllocator /* DataAllocator*_cstype */ g, BaseBitmap icon, int disklevel, SWIGTYPE_p_LONG fallback) {
   bool ret = C4dApiPINVOKE.RegisterNodePlugin(id, str, info, g /* DataAllocator*_csin */, BaseBitmap.getCPtr(icon), disklevel, SWIGTYPE_p_LONG.getCPtr(fallback));
   if (C4dApiPINVOKE.SWIGPendingException.Pending) throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #4
0
ファイル: C4dApi.cs プロジェクト: KilledChicken/Fusee
 public static bool GvRegisterOperatorPlugin(int id, string /* constString&_cstype */ str, int info, NodeDataAllocator /* DataAllocator*_cstype */ at, string /* constString&_cstype */ description, int disklevel, int op_class, int op_group, int op_owner, BaseBitmap icon) {
   bool ret = C4dApiPINVOKE.GvRegisterOperatorPlugin(id, str, info, at /* DataAllocator*_csin */, description, disklevel, op_class, op_group, op_owner, BaseBitmap.getCPtr(icon));
   if (C4dApiPINVOKE.SWIGPendingException.Pending) throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #5
0
ファイル: C4dApi.cs プロジェクト: KilledChicken/Fusee
 public static bool RegisterObjectPlugin(int id, string /* constString&_cstype */ str, int info, NodeDataAllocator /* DataAllocator*_cstype */ g, string /* constString&_cstype */ description, BaseBitmap icon, int disklevel) {
   bool ret = C4dApiPINVOKE.RegisterObjectPlugin(id, str, info, g /* DataAllocator*_csin */, description, BaseBitmap.getCPtr(icon), disklevel);
   if (C4dApiPINVOKE.SWIGPendingException.Pending) throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
   return ret;
 }
コード例 #6
0
ファイル: C4dApiPINVOKE.cs プロジェクト: pr1m3c0d3/Fusee
 public static extern bool RegisterNodePlugin(int jarg1, string /* constString&_imtype */ jarg2, int jarg3, NodeDataAllocator /* DataAllocator*_imtype */ jarg4, HandleRef jarg5, int jarg6, HandleRef jarg7);
コード例 #7
0
ファイル: C4dApiPINVOKE.cs プロジェクト: pr1m3c0d3/Fusee
 public static extern void FillNodePlugin__SWIG_1(HandleRef jarg1, int jarg2, NodeDataAllocator /* DataAllocator*_imtype */ jarg3, HandleRef jarg4, int jarg5);
コード例 #8
0
ファイル: C4dApiPINVOKE.cs プロジェクト: pr1m3c0d3/Fusee
 public static extern bool GvRegisterOperatorPlugin(int jarg1, string /* constString&_imtype */ jarg2, int jarg3, NodeDataAllocator /* DataAllocator*_imtype */ jarg4, string /* constString&_imtype */ jarg5, int jarg6, int jarg7, int jarg8, int jarg9, HandleRef jarg10);