Example #1
0
        /// <summary>
        /// Function to load all the plug-in assemblies from the plug-in directory.
        /// </summary>
        /// <param name="plugInDirectory">Plug-in directory that contains the assemblies.</param>
        /// <param name="callback">The function to call back to when loading the assembly.</param>
        /// <returns>The list of plug-ins loaded.</returns>
        private static IList <GorgonPlugIn> LoadAssemblies(DirectoryInfo plugInDirectory, Action <string> callback)
        {
            var results = new List <GorgonPlugIn>();
            IEnumerable <FileInfo> assemblies = plugInDirectory.GetFiles("*.dll", SearchOption.AllDirectories);

            foreach (var assembly in assemblies)
            {
                EditorLogging.Print("Loading plug-in assembly \"{0}\".", assembly.FullName);

                if (!Gorgon.PlugIns.IsPlugInAssembly(assembly.FullName))
                {
                    EditorLogging.Print("Assembly \"{0}\" is not a valid plug-in assembly.", assembly.FullName);
                    continue;
                }

                if (callback != null)
                {
                    callback(assembly.FullName);
                }

                // Load the DLL and return the list of plugins from it.
                AssemblyName name = Gorgon.PlugIns.LoadPlugInAssembly(assembly.FullName);
                IEnumerable <GorgonPlugIn> plugIns = Gorgon.PlugIns.EnumeratePlugIns(name);

                results.AddRange(plugIns.Where(item => item is EditorPlugIn || item is GorgonFileSystemProviderPlugIn));
            }

            return(results);
        }
Example #2
0
        /// <summary>
        /// Function to initialize the plug-ins interface.
        /// </summary>
        private void InitializePlugIns()
        {
            PlugIns.PlugInPath          = Program.Settings.PlugInDirectory;
            PlugIns.UserDisabledPlugIns = Program.Settings.DisabledPlugIns.ToArray();

            EditorLogging.Print("Loading plug-ins...", LoggingLevel.Verbose);
            _splash.UpdateVersion(Resources.GOREDIT_TEXT_LOADING_PLUGINS);

            PlugIns.LoadPlugIns(UpdateSplashPlugInText);
        }
Example #3
0
        /// <summary>
        /// Function to initialize the scratch files area.
        /// </summary>
        private void InitializeScratchArea()
        {
            ScratchArea.ScratchPath = Program.Settings.ScratchPath;

            EditorLogging.Print("Creating scratch area at \"{0}\"", LoggingLevel.Verbose, ScratchArea.ScratchPath);

            _splash.UpdateVersion(Resources.GOREDIT_TEXT_CREATING_SCRATCH);

            // Ensure that we're not being clever and trying to mess up our system.
            if (ScratchArea.CanAccessScratch(Program.Settings.ScratchPath) == ScratchAccessibility.SystemArea)
            {
                GorgonDialogs.ErrorBox(null, Resources.GOREDIT_ERR_CANNOT_USESYS_SCRATCH);
            }
            else
            {
                // Destroy previous scratch area files if possible.
                // Do not do this when we have it set to a system area, this will keep us from
                // destroying anything critical.
                ScratchArea.CleanOldScratchAreas();
            }

            // Ensure we can actually access the scratch area.
            while (ScratchArea.CanAccessScratch(Program.Settings.ScratchPath) != ScratchAccessibility.Accessible)
            {
                EditorLogging.Print("Could not access scratch area at \"{0}\"", LoggingLevel.Verbose, Program.Settings.ScratchPath);

                if (ScratchArea.SetScratchLocation() == ScratchAccessibility.Canceled)
                {
                    // Exit the application if we cancel.
                    MainForm.Dispose();
                    Gorgon.Quit();
                    return;
                }

                EditorLogging.Print("Setting scratch area to \"{0}\".", LoggingLevel.Verbose, Program.Settings.ScratchPath);

                // Update with the new scratch path.
                Program.Settings.Save();
            }

            ScratchArea.InitializeScratch();

            // Get only the providers that are not disabled.
            var plugIns = from plugIn in Gorgon.PlugIns
                          where plugIn is GorgonFileSystemProviderPlugIn &&
                          PlugIns.UserDisabledPlugIns.All(name => !string.Equals(name, plugIn.Name, StringComparison.OrdinalIgnoreCase))
                          select plugIn;

            foreach (GorgonPlugIn plugIn in plugIns)
            {
                ScratchArea.ScratchFiles.Providers.LoadProvider(plugIn.Name);
            }
        }
Example #4
0
        /// <summary>
        /// Function to load the plug-ins for the application.
        /// </summary>
        /// <param name="callback">The function to call back to when a plug-in is loaded.</param>
        /// <returns>The number of plug-ins loaded.</returns>
        public static int LoadPlugIns(Action <string> callback)
        {
            var plugInDirectory = new DirectoryInfo(PlugInPath);

            if (!plugInDirectory.Exists)
            {
                plugInDirectory.Create();
            }

            IList <GorgonPlugIn> plugIns = LoadAssemblies(plugInDirectory, callback);

            if (plugIns.Count == 0)
            {
                return(0);
            }

            // Process each plug-in.
            foreach (var plugIn in plugIns)
            {
                if (UserDisabledPlugIns.Any(item => String.Equals(item, plugIn.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    EditorLogging.Print("Found plug-in: \"{0}\".  But it is disabled by the user.", plugIn.Description);

                    _disabled.Add(new DisabledPlugIn(plugIn, APIResources.GOREDIT_TEXT_DISABLED_BY_USER));

                    continue;
                }

                // Check for a file system provider first.
                var fileReader = plugIn as GorgonFileSystemProviderPlugIn;

                if (fileReader != null)
                {
                    EditorLogging.Print("Found a file system provider plug-in: \"{0}\".", fileReader.Name);


                    _readerPlugIns[fileReader.Name] = fileReader;
                    continue;
                }

                var editorPlugIn = (EditorPlugIn)plugIn;

                var validationData = editorPlugIn.ValidatePlugIn();

                if (!String.IsNullOrWhiteSpace(validationData))
                {
                    EditorLogging.Print("Found a {0} plug-in: \"{1}\".  But it is disabled for the following reasons:",
                                        editorPlugIn.PlugInType,
                                        editorPlugIn.Description);
                    EditorLogging.Print("{0}", validationData);

                    _disabled.Add(new DisabledPlugIn(plugIn, validationData));
                    continue;
                }

                EditorLogging.Print("Found a {0} plug-in: \"{1}\".", editorPlugIn.PlugInType, editorPlugIn.Description);

                // Categorize the editor plug-ins.
                switch (editorPlugIn.PlugInType)
                {
                case PlugInType.Content:
                    var contentPlugIn = editorPlugIn as ContentPlugIn;

                    if (contentPlugIn != null)
                    {
                        _contentPlugIns[editorPlugIn.Name] = contentPlugIn;
                    }
                    break;

                case PlugInType.FileWriter:
                    var writerPlugIn = editorPlugIn as FileWriterPlugIn;

                    if (writerPlugIn != null)
                    {
                        _writerPlugIns[editorPlugIn.Name] = writerPlugIn;
                    }
                    break;

                default:
                    EditorLogging.Print("Found a {0} plug-in: \"{1}\".  But it is disabled for the following reasons:",
                                        editorPlugIn.PlugInType,
                                        editorPlugIn.Description);
                    EditorLogging.Print("Plug-in type is unknown.", LoggingLevel.Verbose);

                    _disabled.Add(new DisabledPlugIn(editorPlugIn, APIResources.GOREDIT_TEXT_UNKNOWN_PLUG_IN_TYPE));
                    break;
                }
            }

            return(plugIns.Count);
        }