Ejemplo n.º 1
0
        public override void Execute()
        {
            StorageDescriptor pluginCache = new StorageDescriptor(Application.CacheDirectory, PluginCacheFileName, path.Name);

            if (pluginCache.Load())
            {
                foreach (StorageContainer node in pluginCache.Nodes.Values)
                {
                    if (!node.Validate())
                    {
                        pluginCache.Clear();
                        break;
                    }
                }
            }
            StorageContainer assemblyNode; if (!pluginCache.TryGetNode(PluginAssemblyStorageAlias, out assemblyNode))

            {
                List <FileSystemDescriptor> files = Application.GetPluginFiles(path);
                if (files.Count > 0)
                {
                    FileDescriptor assemblyFile = Compile(files);
                    assemblyNode = pluginCache.Store(assemblyFile, PluginAssemblyStorageAlias);

                    foreach (FileDescriptor mixin in files)
                    {
                        pluginCache.Store(mixin);
                    }
                    pluginCache.Save();
                }
                else
                {
                    Application.Warning(SeverityFlags.None, "Plugin '{0}' has no code files to compile", path.Name);
                }
                files = null;
            }
            if (assemblyNode != null && assemblyNode.Element.Exists())
            {
                Assembly assembly = Assembly.LoadFrom(assemblyNode.Element.GetAbsolutePath());
                Type     type     = assembly.GetType <IPlugin>();
                if (type != null)
                {
                    instance = type.CreateInstance <IPlugin>();

                    if (instance != null)
                    {
                        instance.Load();
                        return;
                    }
                }
                Application.Warning(SeverityFlags.None, "'{0}' is not a plugin", path.GetAbsolutePath());
            }
        }
Ejemplo n.º 2
0
        private static void LoadMixins()
        {
            StorageDescriptor mixinCache = new StorageDescriptor(Application.CacheDirectory, ModuleCacheFileName);

            if (mixinCache.Load())
            {
                foreach (StorageContainer node in mixinCache.Nodes.Values)
                {
                    if (!node.Validate())
                    {
                        mixinCache.Clear();
                        break;
                    }
                }
            }
            StorageContainer assemblyNode; if (!mixinCache.TryGetNode(MixinAssemblyStorageAlias, out assemblyNode))

            {
                Filter filter = new Filter();

                SetMixinFilter(filter);
                List <FileSystemDescriptor> mixins = Application.SdkDirectory.FindFiles(filter);
                if (mixins.Count > 0)
                {
                    FileDescriptor assemblyFile = Compile(mixins);
                    assemblyNode = mixinCache.Store(assemblyFile, MixinAssemblyStorageAlias);

                    foreach (FileDescriptor mixin in mixins)
                    {
                        mixinCache.Store(mixin);
                    }
                    mixinCache.Save();
                }
                filter = null;
                mixins = null;
            }
            MixinManager.RegisterMixins(Assembly.GetExecutingAssembly());
            if (assemblyNode != null && assemblyNode.Element.Exists())
            {
                MixinManager.RegisterMixins(Assembly.LoadFrom(assemblyNode.Element.GetAbsolutePath()));
            }
        }
Ejemplo n.º 3
0
        public static void DisplayManual()
        {
            Application.Log(SeverityFlags.None, "Forge {0}, distributed under the Schroedinger Entertainment EULA (See EULA.md for details)", Application.Version);

            StorageDescriptor mixinCache = new StorageDescriptor(Application.CacheDirectory, ModuleCacheFileName);

            if (mixinCache.Load() && mixinCache.Nodes.Count > 0)
            {
                Application.Log(SeverityFlags.None, "Loaded {0} Mixin(s) from root", mixinCache.Nodes.Count - 1);
                foreach (StorageContainer mixin in mixinCache.Nodes.Values)
                {
                    if (mixin.Tag == 0)
                    {
                        Application.Log(SeverityFlags.None, "  {0}", mixin.Element.GetRelativePath(Application.SdkDirectory));
                    }
                }
            }
            mixinCache = null;

            Application.Log(SeverityFlags.None, "Loaded {0} Plugin(s) from root", plugins.Count);
            foreach (Plugin plugin in plugins)
            {
                Application.Log(SeverityFlags.None, "  {0}", plugin.Path.GetRelativePath(Application.SdkDirectory));
            }

            Application.Log(SeverityFlags.None, string.Empty);

            PageFormatter page = new PageFormatter();

            AutoConfig.GetAttributePage <Application>(page);
            page.Sort();

            PageFormatter subPage = new PageFormatter();

            AutoConfig.GetAttributePage(Application.Profile.GetType(), subPage);
            AutoConfig.GetAttributePage(Application.Profile, subPage);
            subPage.Sort();

            if (subPage.Rows.Count > 0)
            {
                page.AddRow("");
                page.AddRow(string.Format("{0} Profile", Application.Profile.Name.ToTitleCase()));
                page.Rows.AddRange(subPage.Rows);
            }

            Dictionary <string, PageFormatter> subSystems = new Dictionary <string, PageFormatter>();

            AppDomain.CurrentDomain.GetAssemblies().ParallelFor((assembly) =>
            {
                foreach (Type receiver in assembly.GetTypes <IConfigReceiver>())
                {
                    try
                    {
                        PageFormatter systemPage = new PageFormatter();
                        AutoConfig.GetAttributePage(receiver, systemPage);

                        IConfigReceiver instance; if (receiver.IsAbstract && MixinType.IsAssignableFrom(receiver))
                        {
                            instance = MixinManager.Create(receiver) as IConfigReceiver;
                        }
                        else if (!receiver.IsAbstract)
                        {
                            instance = receiver.CreateInstance <IConfigReceiver>();
                        }
                        else
                        {
                            continue;
                        }

                        if (instance != null && instance.Display)
                        {
                            instance.GetAdditionalManualInfo(systemPage);
                            if (systemPage.Rows.Count > 0)
                            {
                                lock (subSystems)
                                {
                                    PageFormatter tmp; if (subSystems.TryGetValue(instance.DisplayName, out tmp))
                                    {
                                        tmp.AddRows(systemPage.Rows);
                                    }
                                    else
                                    {
                                        subSystems.Add(instance.DisplayName, systemPage);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    { }
                }
            });
            foreach (KeyValuePair <string, PageFormatter> systems in subSystems.OrderBy(x => x.Key))
            {
                systems.Value.Sort();

                page.AddRow("");
                page.AddRow(string.Format("{0} System", systems.Key));
                page.Rows.AddRange(systems.Value.Rows);
            }
            foreach (Plugin plugin in plugins)
            {
                subPage = new PageFormatter();
                plugin.GetManualPage(subPage);
                subPage.Sort();

                if (subPage.Rows.Count > 0)
                {
                    page.AddRow("");
                    page.AddRow(string.Format("{0} Plugin", plugin.Path.Name.ToTitleCase()));
                    page.Rows.AddRange(subPage.Rows);
                }
            }

            Application.Log(SeverityFlags.None, page.ToString());
        }