Exemplo n.º 1
0
        internal static void Internal_Dispose(Assembly assembly)
        {
            bool changed = false;

            for (int i = _editorPlugins.Count - 1; i >= 0 && _editorPlugins.Count > 0; i--)
            {
                var plugin = _editorPlugins[i];
                if (plugin.GetType().Assembly == assembly)
                {
                    InvokeDeinitialize(plugin);
                    _editorPlugins.RemoveAt(i);
                    changed = true;
                }
            }

            for (int i = _gamePlugins.Count - 1; i >= 0 && _gamePlugins.Count > 0; i--)
            {
                var plugin = _gamePlugins[i];
                if (plugin.GetType().Assembly == assembly)
                {
                    InvokeDeinitialize(plugin);
                    _gamePlugins.RemoveAt(i);
                    changed = true;
                }
            }

            if (changed)
            {
                PluginsChanged?.Invoke();
            }
        }
Exemplo n.º 2
0
        internal static void Internal_Dispose()
        {
            int pluginsCount = _editorPlugins.Count + _gamePlugins.Count;

            if (pluginsCount == 0)
            {
                return;
            }
            Debug.Write(LogType.Info, string.Format("Unloading {0} plugins", pluginsCount));

            for (int i = _editorPlugins.Count - 1; i >= 0 && _editorPlugins.Count > 0; i--)
            {
                var plugin = _editorPlugins[i];
                InvokeDeinitialize(plugin);
                _editorPlugins.RemoveAt(i);
            }

            for (int i = _gamePlugins.Count - 1; i >= 0 && _gamePlugins.Count > 0; i--)
            {
                var plugin = _gamePlugins[i];
                InvokeDeinitialize(plugin);
                _gamePlugins.RemoveAt(i);
            }

            PluginsChanged?.Invoke();
        }
Exemplo n.º 3
0
        public void LoadPluginAssembly(string assemblyPath)
        {
            var      flag = CopyToMemory;
            Assembly asm;

            if (flag)
            {
                var rawAssembly = FileUtil.Read(assemblyPath);
                asm = Assembly.Load(rawAssembly);
            }
            else
            {
                asm = Assembly.LoadFrom(assemblyPath);
            }

            var list = ReflectionUtil.LoadDerivedInstance <IPlugin <inT> >(asm);

            foreach (var plugin in list)
            {
                _dicPlugins.Add(plugin.PluginKey, plugin);
                plugin.OnLoading();
            }

            PluginsChanged?.Invoke();
        }
Exemplo n.º 4
0
        internal static void Internal_LoadPlugin(Type type, bool isEditor)
        {
            if (type == null)
            {
                throw new ArgumentNullException();
            }

            // Create and check if use it
            var plugin = (Plugin)Activator.CreateInstance(type);
            var desc   = plugin.Description;

            if (!CanLoadPlugin(ref desc))
            {
                Debug.Write(LogType.Info, "Skip loading plugin " + plugin);
                return;
            }

            if (!isEditor)
            {
                _gamePlugins.Add((GamePlugin)plugin);
#if !FLAX_EDITOR
                InvokeInitialize(plugin);
#endif
            }
#if FLAX_EDITOR
            else
            {
                _editorPlugins.Add(plugin);
                InvokeInitialize(plugin);
            }
#endif
            PluginsChanged?.Invoke();
        }
Exemplo n.º 5
0
        private void FileSystemWatcherOnCreated(object sender, FileSystemEventArgs fileSystemEventArgs)
        {
            foreach (var directoryCatalog in _directoryCatalogs)
            {
                directoryCatalog.Refresh();
            }

            AudioConnectors = _container.GetExportedValues <IAudioConnector>();
            PluginsChanged?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 6
0
        public void DynRemovePlugin(string pluginKey)
        {
            var plugin = GetPlugin(pluginKey);

            if (plugin == null)
            {
                return;
            }
            plugin.BeforeTerminating();
            _dicPlugins.Remove(pluginKey);
            PluginsChanged?.Invoke();
        }
Exemplo n.º 7
0
        public void LoadAllPlugins(string pluginFolderPath, bool searchChildFolder)
        {
            var list = ReflectionUtil.LoadDerivedType(typeof(IPlugin <inT>), pluginFolderPath, searchChildFolder,
                                                      CopyToMemory);

            foreach (var type in list)
            {
                var plugin = (IPlugin <inT>)Activator.CreateInstance(type);
                _dicPlugins.Add(plugin.PluginKey, plugin);
                plugin.OnLoading();
            }

            PluginsChanged?.Invoke();
        }
Exemplo n.º 8
0
        public void Clear()
        {
            foreach (var plugin in _dicPlugins.Values)
            {
                try
                {
                    plugin.BeforeTerminating();
                }
                catch
                {
                    // ignored
                }
            }

            _dicPlugins.Clear();
            PluginsChanged?.Invoke();
        }
        /// <summary>
        ///     Triggers the reloader to reload all plugins in the plugins directory
        /// </summary>
        private void ReloadPlugins()
        {
            RunAfterCheckStartState(() =>
            {
                lock (LockObject)
                {
                    if (!_justStarted)
                    {
                        PluginsChanged?.Invoke();
                    }
                    else
                    {
                        _justStarted = false;
                    }

                    _changeTime = new DateTime(0);
                }
            });
        }
Exemplo n.º 10
0
 protected virtual void OnPluginsChanged()
 {
     PluginsChanged?.Invoke(this, new PluginsChangedEventArgs <T> {
         AvailablePlugins = CurrentlyAvailable
     });
 }
 public void FireEvent(PluginManager plug, EventArgs args) => PluginsChanged?.Invoke(plug, args);
Exemplo n.º 12
0
 protected void OnPluginsChanged(PluginsChangedEventArgs e)
 {
     PluginsChanged?.Invoke(this, e);
 }
Exemplo n.º 13
0
 protected virtual void OnPluginsChanged()
 {
     PluginsChanged?.Invoke(this, new PluginsChangedEventArgs <string> {
         AvailablePlugins = CurrentlyAvailable.ToArray()
     });
 }