コード例 #1
0
        private List <PluginWrapper> UpdateSinglePlugin(
            PluginUpdateSettings plugin,
            PluginSourceDownloader pluginSourceDownloader,
            PluginFilter pluginFilter,
            PluginCompiler pluginCompiler,
            PluginLoader pluginLoader
            )
        {
            pluginSourceDownloader.Update(plugin);
            var sourcePluginDirectory   = new DirectoryInfo(Path.Combine(SourcePluginsDirectory, plugin.Name?.Value));
            var compiledPluginDirectory = new DirectoryInfo(Path.Combine(CompiledPluginsDirectory, plugin.Name?.Value));

            if (!pluginFilter.ShouldCompilePlugin(sourcePluginDirectory, compiledPluginDirectory))
            {
                return(null);
            }

            var dependencyTasks  = PluginCopyFiles.CopyDependencies(sourcePluginDirectory, compiledPluginDirectory);
            var settingsTasks    = PluginCopyFiles.CopySettings(sourcePluginDirectory, compiledPluginDirectory);
            var staticFilesTasks = PluginCopyFiles.CopyStaticFiles(sourcePluginDirectory, compiledPluginDirectory);

            Task.WaitAll(dependencyTasks?.ToArray());
            var assembly = pluginCompiler.CompilePlugin(sourcePluginDirectory, compiledPluginDirectory.FullName);

            Task.WaitAll(settingsTasks?.ToArray());
            Task.WaitAll(staticFilesTasks?.ToArray());
            var pluginWrapper = pluginLoader.Load(compiledPluginDirectory, assembly);

            return(pluginWrapper);
        }
コード例 #2
0
        public void Update(PluginUpdateSettings plugin)
        {
            if (!plugin.Enable)
            {
                DebugWindow.LogMsg($"{plugin.Name?.Value}: Update disabled in settings!");
                return;
            }
            var sw = Stopwatch.StartNew();

            DebugWindow.LogDebug($"{plugin.Name?.Value}: Start update.");
            var repositoryPath = Path.Combine(SourceDirectory, plugin.Name?.Value);

            if (!Repository.IsValid(repositoryPath))
            {
                DebugWindow.LogMsg($"{plugin.Name?.Value}: No valid repository at: {repositoryPath}. Starting to clone...");
                try
                {
                    Clone(plugin.SourceUrl?.Value, repositoryPath);
                    sw.Stop();
                    DebugWindow.LogMsg($"{plugin.Name?.Value}: Clone successful in {sw.ElapsedMilliseconds} ms.");
                    return;
                }
                catch (Exception e)
                {
                    DebugWindow.LogError($"{plugin.Name?.Value} -> Clone failed. Make sure the folder Plugins/Source/{plugin.Name?.Value} does not exist. Skipped!");
                    DebugWindow.LogDebug($"{plugin.Name?.Value} -> {e.Message}");
                    return;
                }
            }

            var repository = new Repository(repositoryPath);

            try
            {
                var status = Pull(repository);
                sw.Stop();
                if (status == MergeStatus.UpToDate)
                {
                    DebugWindow.LogMsg($"{plugin.Name?.Value}: Already up to date, checked in {sw.ElapsedMilliseconds} ms.");
                    return;
                }
                else if (status == MergeStatus.FastForward || status == MergeStatus.NonFastForward)
                {
                    DebugWindow.LogMsg($"{plugin.Name?.Value}: Update successful in {sw.ElapsedMilliseconds} ms.");
                    return;
                }
                else
                {
                    throw new Exception(status.ToString());
                }
            }
            catch (Exception e)
            {
                DebugWindow.LogError($"{plugin.Name?.Value}: Update failed. Skipped!");
                DebugWindow.LogDebug($"{plugin.Name?.Value} -> {e.Message}");
            }
        }