Example #1
0
        private void DownloadPlugins()
        {
            _log.Info("Downloading plugins");
            var updater = new PluginUpdater(this);

            var folders  = Directory.GetDirectories(PluginDir);
            var taskList = new List <Task>();

            if (_torch.Config.RedownloadPlugins)
            {
                _log.Warn("Force downloading all plugins because the RedownloadPlugins flag is set in the config");
            }

            foreach (var folder in folders)
            {
                var manifestPath = Path.Combine(folder, "manifest.xml");
                if (!File.Exists(manifestPath))
                {
                    _log.Info($"No manifest in {folder}, skipping");
                    continue;
                }

                _log.Info($"Checking for updates for {folder}");
                var manifest = PluginManifest.Load(manifestPath);
                taskList.Add(updater.CheckAndUpdate(manifest, _torch.Config.RedownloadPlugins));
            }

            Task.WaitAll(taskList.ToArray());
            _torch.Config.RedownloadPlugins = false;
        }
Example #2
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);
        }
Example #3
0
        private static int StartApplication(SingleApplicationHelper.IMutex mutex, string fileToOpen, Stopwatch stopwatch)
        {
            ApplicationSettings settings = ApplicationSettings.Create();

            settings.Restore(out var neededPatching);
            settings.AllowSave = false;             //< We will allow saving once the app is fully booted

            if (neededPatching)
            {
                // TODO: Save settings right again to complete the upgrade
                //       (maybe we should preserve an old version)
            }

            var bookmarks = Bookmarks.Create();

            bookmarks.Restore();

            var services = new ServiceContainer();

            services.RegisterInstance <ILogFileSettings>(settings.LogFile);

            var actionCenter = new ActionCenter();

            using (var taskScheduler = new DefaultTaskScheduler())
                using (var serialTaskScheduler = new SerialTaskScheduler())
                {
                    services.RegisterInstance <ITaskScheduler>(taskScheduler);
                    services.RegisterInstance <ISerialTaskScheduler>(serialTaskScheduler);
                    var navigationService = new NavigationService();
                    services.RegisterInstance <INavigationService>(navigationService);

                    var filesystem = new Filesystem(taskScheduler);
                    services.RegisterInstance <IFilesystem>(filesystem);

                    using (var pluginArchiveLoader = new PluginArchiveLoader(filesystem, Constants.PluginPath, Constants.DownloadedPluginsPath))
                    {
                        var pluginUpdater = new PluginUpdater(pluginArchiveLoader);
                        services.RegisterInstance <IPluginUpdater>(pluginUpdater);

                        var pluginSystem = CreatePluginSystem(pluginArchiveLoader);
                        services.RegisterInstance <IPluginLoader>(pluginSystem);

                        var logFileFormatRegistry = new LogFileFormatRegistry(pluginSystem, settings.CustomFormats);
                        services.RegisterInstance <ILogFileFormatRepository>(logFileFormatRegistry);
                        services.RegisterInstance <ILogFileFormatRegistry>(logFileFormatRegistry);

                        var logFileFormatMatcher = new LogFileFormatMatcher(services);
                        services.RegisterInstance <ILogFileFormatMatcher>(logFileFormatMatcher);

                        var textLogFileParserPlugin = new LogEntryParserFactory(services);
                        services.RegisterInstance <ILogEntryParserPlugin>(textLogFileParserPlugin);

                        var propertyPresenter = new PropertyPresenterRegistry(pluginSystem);
                        services.RegisterInstance <IPropertyPresenterPlugin>(propertyPresenter);

                        var fileLogSourceFactory = new StreamingTextLogSourceFactory(filesystem, taskScheduler);
                        services.RegisterInstance <IRawFileLogSourceFactory>(fileLogSourceFactory);

                        var parsingLogSourceFactory = new ParsingLogSourceFactory(services);
                        services.RegisterInstance <ILogSourceParserPlugin>(parsingLogSourceFactory);

                        var customDataSourcePlugins = pluginSystem.LoadAllOfTypeWithDescription <ICustomDataSourcePlugin>();
                        var logFileFactory          = new PluginLogSourceFactory(services, customDataSourcePlugins);
                        using (var dataSources = new DataSources(logFileFactory, taskScheduler, filesystem, settings.DataSources, bookmarks))
                            using (var updater = new AutoUpdater(actionCenter, settings.AutoUpdate))
                            {
                                if (fileToOpen != null)
                                {
                                    if (File.Exists(fileToOpen))
                                    {
                                        // Not only do we want to add this file to the list of data sources,
                                        // but we also want to select it so the user can view it immediately, regardless
                                        // of what was selected previously.
                                        var dataSource = dataSources.AddFile(fileToOpen);
                                        settings.DataSources.SelectedItem = dataSource.Id;
                                    }
                                    else
                                    {
                                        Log.ErrorFormat("File '{0}' does not exist, won't open it!", fileToOpen);
                                    }
                                }

                                if (settings.AutoUpdate.CheckForUpdates)
                                {
                                    // Our initial check for updates is not due to a user action
                                    // and therefore we don't need to show a notification when the
                                    // application is up-to-date.
                                    updater.CheckForUpdates(addNotificationWhenUpToDate: false);
                                }

                                var quickFilters = new QuickFilters(settings.QuickFilters);
                                var highlighters = new HighlighterCollection();
                                services.RegisterInstance <IHighlighters>(highlighters);

                                actionCenter.Add(Build.Current);
                                actionCenter.Add(Change.Merge(Changelog.MostRecentPatches));
                                var application  = new App();
                                var dispatcher   = Dispatcher.CurrentDispatcher;
                                var uiDispatcher = new UiDispatcher(dispatcher);
                                services.RegisterInstance <IDispatcher>(uiDispatcher);

                                dispatcher.UnhandledException         += actionCenter.ReportUnhandledException;
                                TaskScheduler.UnobservedTaskException += actionCenter.ReportUnhandledException;

                                var windowViewModel = new MainWindowViewModel(services,
                                                                              settings,
                                                                              dataSources,
                                                                              quickFilters,
                                                                              actionCenter,
                                                                              updater);
                                navigationService.MainWindow = windowViewModel;

                                var window = new MainWindow(settings, windowViewModel);

                                settings.MainWindow.ClipToBounds(Desktop.Current);
                                settings.MainWindow.RestoreTo(window);
                                settings.AllowSave = true;

                                stopwatch.Stop();
                                Log.InfoFormat("Tailviewer started (took {0}ms), showing window...", stopwatch.ElapsedMilliseconds);

                                window.Show();
                                mutex?.SetListener(window);

                                return(application.Run());
                            }
                    }
                }
        }