Esempio n. 1
0
        private void RemoveChangedPlugins(PluginsUpdateSettings settings, PluginsUpdateSettings dumpSettings)
        {
            if (dumpSettings == null)
            {
                return;
            }

            foreach (var plugin in settings.Plugins)
            {
                var fittingPluginFromDump = dumpSettings.Plugins
                                            .Where(d => d.Name?.Value == plugin.Name?.Value)
                                            .Where(d => d.SourceUrl?.Value == plugin.SourceUrl?.Value)
                                            .FirstOrDefault();
                // unchanged entry
                if (fittingPluginFromDump != null)
                {
                    continue;
                }

                try
                {
                    DebugWindow.LogMsg($"PluginManager -> Remove old files from {plugin.Name?.Value}");
                    DeleteFilesFromPlugin(plugin.Name?.Value);
                }
                catch (Exception e)
                {
                    DebugWindow.LogError($"PluginManager -> Remove old files from {plugin.Name?.Value} failed");
                    DebugWindow.LogDebug($"PluginManager -> {e.Message}");
                }
            }
        }
Esempio n. 2
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;
        }
Esempio n. 3
0
        private List <Task <List <PluginWrapper> > > RunPluginAutoUpdate(
            PluginLoader pluginLoader,
            PluginsUpdateSettings pluginsUpdateSettings)
        {
            var pluginUpdater = new PluginUpdater(
                pluginsUpdateSettings,
                RootDirectory,
                Directories[CompiledPluginsDirectory],
                Directories[SourcePluginsDirectory],
                pluginLoader
                );

            var pluginTasks = pluginUpdater.UpdateAndLoadAllAsync();

            return(pluginTasks);
        }
Esempio n. 4
0
        private List <Task <List <PluginWrapper> > > LoadCompiledDirPlugins(PluginLoader pluginLoader, PluginsUpdateSettings pluginsUpdateSettings, bool forceLoadCompiledOnly)
        {
            List <string> excludedNames = new List <string>();

            if (pluginsUpdateSettings != null && pluginsUpdateSettings.Enable && !forceLoadCompiledOnly)
            {
                var excluded = pluginsUpdateSettings.Plugins?
                               .Where(p => p.Enable)
                               .Select(p => p.Name?.Value);
                excludedNames.AddRange(excluded);
            }
            var compiledDirectories = new DirectoryInfo(Directories[CompiledPluginsDirectory])
                                      .GetDirectories()
                                      .Where(di => !excludedNames.Any(excludedName => excludedName.Equals(di.Name, StringComparison.InvariantCultureIgnoreCase)));

            var loadTasks = new List <Task <List <PluginWrapper> > >();

            foreach (var compiledDirectory in compiledDirectories)
            {
                loadTasks.Add(Task.Run(() => pluginLoader.Load(compiledDirectory)));
            }
            return(loadTasks);
        }