public UnrealPluginInstaller(Lifetime lifetime, ILogger logger, UnrealPluginDetector pluginDetector,
                                     PluginPathsProvider pathsProvider, ISolution solution, ISettingsStore settingsStore,
                                     IShellLocks shellLocks, UnrealHost unrealHost)
        {
            myLifetime           = lifetime;
            myLogger             = logger;
            myPathsProvider      = pathsProvider;
            myShellLocks         = shellLocks;
            myUnrealHost         = unrealHost;
            myBoundSettingsStore = settingsStore.BindToContextLive(myLifetime, ContextRange.Smart(solution.ToDataContext()));
            myPluginDetector     = pluginDetector;

            myPluginDetector.InstallInfoProperty.Change.Advise_NewNotNull(myLifetime, installInfo =>
            {
                myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "UnrealPluginInstaller.CheckAllProjectsIfAutoInstallEnabled",
                                                      () =>
                {
                    var unrealPluginInstallInfo = installInfo.New;
                    if (unrealPluginInstallInfo.EnginePlugin.IsPluginAvailable)
                    {
                        // TODO: add install plugin to Engine
                    }
                    ;

                    if (!myBoundSettingsStore.GetValue((UnrealLinkSettings s) => s.InstallRiderLinkPlugin))
                    {
                        foreach (var installDescription in unrealPluginInstallInfo.ProjectPlugins)
                        {
                            if (installDescription.IsPluginAvailable == false ||
                                installDescription.PluginVersion != myPathsProvider.CurrentPluginVersion)
                            {
                                myUnrealHost.PerformModelAction(model => model.OnEditorModelOutOfSync());
                            }
                        }

                        return;
                    }

                    InstallPluginIfRequired(unrealPluginInstallInfo);
                });
            });
            BindToInstallationSettingChange();
            BindToNotificationFixAction();
        }
Esempio n. 2
0
        public RiderBackendToUnrealEditor(Lifetime lifetime, IShellLocks locks, IScheduler dispatcher, ILogger logger,
                                          UnrealHost unrealHost, UnrealLinkResolver linkResolver, EditorNavigator editorNavigator,
                                          UnrealPluginDetector pluginDetector)
        {
            myComponentLifetime          = lifetime;
            myLocks                      = locks;
            myConnectionLifetimeProducer = new SequentialLifetimes(lifetime);
            myDispatcher                 = dispatcher;
            myLogger                     = logger;
            myUnrealHost                 = unrealHost;
            myLinkResolver               = linkResolver;
            myEditorNavigator            = editorNavigator;

            myLogger.Info("RiderBackendToUnrealEditor building started");

            pluginDetector.InstallInfoProperty.View(myComponentLifetime, (lt, pluginInfo) =>
            {
                if (pluginInfo == null)
                {
                    return;
                }

                var portDirectoryFullPath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "..",
                    "Local", "Jetbrains", "Rider", "Unreal", "Ports");

                Directory.CreateDirectory(portDirectoryFullPath);

                var watcher = new FileSystemWatcher(portDirectoryFullPath)
                {
                    NotifyFilter = NotifyFilters.LastWrite
                };
                var projects = pluginInfo.ProjectPlugins.Select(it => it.UprojectFilePath.NameWithoutExtension)
                               .ToList();

                FileSystemEventHandler handler = (obj, fileSystemEvent) =>
                {
                    var path = FileSystemPath.Parse(fileSystemEvent.FullPath);
                    if (projects.Contains(path.NameWithoutExtension) && myComponentLifetime.IsAlive)
                    {
                        myLocks.ExecuteOrQueue(myComponentLifetime, "CreateProtocol", () => CreateProtocols(path));
                    }
                };

                watcher.Changed += handler;
                watcher.Created += handler;

                // Check if it's even possible to happen
                lt.Bracket(() => { }, () => { watcher.Dispose(); });

                StartWatcher(watcher);

                foreach (var projectName in projects)
                {
                    var portFileFullPath = Path.Combine(portDirectoryFullPath, projectName);
                    CreateProtocols(FileSystemPath.Parse(portFileFullPath));
                }
            });

            myLogger.Info("RiderBackendToUnrealEditor building finished");
        }