Ejemplo n.º 1
0
        private void LoadPlugins(GameController gameController)
        {
            var pluginLoader = new PluginLoader(_gameController, _graphics, this);

            var pluginUpdateSettings          = _settingsContainer.PluginsUpdateSettings;
            var loadPluginTasks               = new List <Task <List <PluginWrapper> > >();
            var stopLoadFromCompiledDirectory = new List <string>();

            // check for changes in the updateSettings. Delete changed repositories, to make sure all changes are acted upon
            if (pluginUpdateSettings.Enable)
            {
                var file = new FileInfo(AutoPluginUpdateSettingsPathDump);
                PluginsUpdateSettings dumpPluginUpdateSettings = null;
                if (file.Exists)
                {
                    dumpPluginUpdateSettings = SettingsContainer.LoadSettingFile <PluginsUpdateSettings>(AutoPluginUpdateSettingsPathDump);
                }

                RemoveChangedPlugins(pluginUpdateSettings, dumpPluginUpdateSettings);
                SettingsContainer.SaveSettingFile(AutoPluginUpdateSettingsPathDump, pluginUpdateSettings);
                try
                {
                    var pluginAutoUpdates = RunPluginAutoUpdate(pluginLoader, pluginUpdateSettings);
                    loadPluginTasks.AddRange(pluginAutoUpdates);

                    stopLoadFromCompiledDirectory = pluginUpdateSettings
                                                    .Plugins
                                                    .Select(p => p.Name?.Value)
                                                    .ToList();
                }
                catch (Exception e)
                {
                    DebugWindow.LogError("PluginManager -> AutoUpdate failed, load all compiled plugins.");
                    DebugWindow.LogError($"PluginManager -> {e.Message}");
                    stopLoadFromCompiledDirectory = new List <string>();
                }
            }

            loadPluginTasks.AddRange(LoadCompiledDirPlugins(pluginLoader, stopLoadFromCompiledDirectory));

            Task.WaitAll(loadPluginTasks?.ToArray());

            Plugins = loadPluginTasks
                      .Where(t => t.Result != null)
                      .SelectMany(t => t.Result)
                      .OrderBy(x => x.Order)
                      .ThenByDescending(x => x.CanBeMultiThreading)
                      .ThenBy(x => x.Name)
                      .ToList();

            AddPluginInfoToDevTree();

            InitialisePlugins(gameController);

            AreaOnOnAreaChange(gameController.Area.CurrentArea);
            AllPluginsLoaded = true;
        }