public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher, ILogger logger, IFileSystemTracker fileSystemTracker, UnityHost host, UnitySolutionTracker unitySolutionTracker) { myLogger = logger; if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null) { return; } unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args => { if (!args) { return; } // Rgc.Guarded - beware RIDER-15577 myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherGroupingEvent", TimeSpan.FromMilliseconds(500), Rgc.Guarded, () => { refresher.StartRefresh(RefreshType.Normal); }); host.PerformModelAction(rd => rd.Refresh.Advise(lifetime, force => { if (force) { refresher.StartRefresh(RefreshType.ForceRequestScriptReload); } else { myGroupingEvent.FireIncoming(); } })); }); unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args => { if (!args) { return; } var protocolSolution = solution.GetProtocolSolution(); protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ => { logger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved"); myGroupingEvent.FireIncoming(); }); fileSystemTracker.RegisterPrioritySink(lifetime, FileSystemChange, HandlingPriority.Other); }); }
private void InstallPluginIfRequired() { if (!myUnitySolutionTracker.IsUnityProjectFolder.Value) { return; } if (myPluginInstallations.Contains(mySolution.SolutionFilePath)) { return; } if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin)) { return; } var versionForSolution = myUnityVersion.ActualVersionForSolution.Value; if (versionForSolution >= new Version("2019.2")) // 2019.2+ would not work fine either without Rider package, and when package is present it loads EditorPlugin directly from Rider installation. { var installationInfoToRemove = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty); if (!installationInfoToRemove.PluginDirectory.IsAbsolute) { return; } var pluginDll = installationInfoToRemove.PluginDirectory.Combine(PluginPathsProvider.BasicPluginDllFile); if (pluginDll.ExistsFile) { myQueue.Enqueue(() => { myLogger.Info($"Remove {pluginDll}. Rider package should be used instead."); pluginDll.DeleteFile(); FileSystemPath.Parse(pluginDll.FullPath + ".meta").DeleteFile(); // jetbrainsDir is usually "Assets\Plugins\Editor\JetBrains", however custom locations were also possible var jetbrainsDir = installationInfoToRemove.PluginDirectory; if (jetbrainsDir.GetChildren().Any() || jetbrainsDir.Name != "JetBrains") { return; } jetbrainsDir.DeleteDirectoryNonRecursive(); FileSystemPath.Parse(jetbrainsDir.FullPath + ".meta").DeleteFile(); var pluginsEditorDir = jetbrainsDir.Directory; if (pluginsEditorDir.GetChildren().Any() || pluginsEditorDir.Name != "Editor") { return; } pluginsEditorDir.DeleteDirectoryNonRecursive(); FileSystemPath.Parse(pluginsEditorDir.FullPath + ".meta").DeleteFile(); var pluginsDir = pluginsEditorDir.Directory; if (pluginsDir.GetChildren().Any() || pluginsDir.Name != "Plugins") { return; } pluginsDir.DeleteDirectoryNonRecursive(); FileSystemPath.Parse(pluginsDir.FullPath + ".meta").DeleteFile(); }); } return; } // forcing fresh install due to being unable to provide proper setting until InputField is patched in Rider // ReSharper disable once ArgumentsStyleNamedExpression var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion, previousInstallationDir: FileSystemPath.Empty); if (!installationInfo.ShouldInstallPlugin) { myLogger.Info("Plugin should not be installed."); if (installationInfo.ExistingFiles.Count > 0) { myLogger.Info("Already existing plugin files:\n{0}", string.Join("\n", installationInfo.ExistingFiles)); } return; } QueueInstall(installationInfo); myQueue.Enqueue(() => { mySolution.Locks.Tasks.StartNew(myLifetime, Scheduling.MainGuard, () => myRefresher.StartRefresh(RefreshType.Normal)); }); }