Пример #1
0
        private void InstallPluginIfRequired()
        {
            if (!myUnitySolutionTracker.IsUnityProjectFolder.Value)
            {
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                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(() => { myRefresher.Refresh(false); });
        }
        public UnityPluginInstaller(
            Lifetime lifetime,
            ILogger logger,
            ISolution solution,
            IShellLocks shellLocks,
            UnityPluginDetector detector,
            NotificationsModel notifications,
            ISettingsStore settingsStore,
            PluginPathsProvider pluginPathsProvider,
            UnityVersion unityVersion,
            UnityHost unityHost,
            UnitySolutionTracker unitySolutionTracker,
            UnityRefresher refresher)
        {
            myPluginInstallations = new JetHashSet <FileSystemPath>();

            myLifetime             = lifetime;
            myLogger               = logger;
            mySolution             = solution;
            myShellLocks           = shellLocks;
            myDetector             = detector;
            myNotifications        = notifications;
            myPluginPathsProvider  = pluginPathsProvider;
            myUnityVersion         = unityVersion;
            myUnitySolutionTracker = unitySolutionTracker;
            myRefresher            = refresher;

            myBoundSettingsStore = settingsStore.BindToContextLive(myLifetime, ContextRange.Smart(solution.ToDataContext()));
            myQueue = new ProcessingQueue(myShellLocks, myLifetime);

            unityHost.PerformModelAction(rdUnityModel =>
            {
                rdUnityModel.InstallEditorPlugin.AdviseNotNull(lifetime, x =>
                {
                    myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "UnityPluginInstaller.InstallEditorPlugin", () =>
                    {
                        var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion);
                        QueueInstall(installationInfo, true);
                    });
                });
            });

            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }
                myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "IsAbleToEstablishProtocolConnectionWithUnity", InstallPluginIfRequired);
                BindToInstallationSettingChange();
            });
        }
Пример #3
0
        private void InstallPluginIfRequired(ICollection <IProject> projects)
        {
            if (projects.Count == 0)
            {
                return;
            }

            InstallFromResource(@"Library\resharper-unity-libs\nunit3.5.0\nunit.framework.dll", ".Unity3dRider.Library.resharper_unity_libs.nunit3._5._0.nunit.framework.dll");
            InstallFromResource(@"Library\resharper-unity-libs\pdb2mdb.exe", ".Unity3dRider.Library.resharper_unity_libs.pdb2mdb.exe");

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                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(projects, 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;
            }

            myQueue.Enqueue(() =>
            {
                Install(installationInfo);
                myPluginInstallations.Add(mySolution.SolutionFilePath);
            });
        }
        private void InstallPluginIfRequired()
        {
            if (!myUnitySolutionTracker.IsUnityProjectFolder.Value)
            {
                return;
            }

            if (myPluginInstallations.Contains(mySolution.SolutionFilePath))
            {
                return;
            }

            if (!myBoundSettingsStore.GetValue((UnitySettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            // Unity 2019.2+ is expected to have com.unity.ide.rider package, which loads EditorPlugin directly from Rider installation
            var manifestJsonFile = mySolution.SolutionDirectory.Combine("Packages/manifest.json");

            if (manifestJsonFile.ExistsFile)
            {
                var text = manifestJsonFile.ReadAllText2().Text;
                //"com.unity.ide.rider": "1.0.7"
                var match = Regex.Match(text, @"""com\.unity\.ide\.rider""\s*:\s*""(?<version>.*)""", RegexOptions.Multiline);
                if (match.Success)
                {
                    if (Version.TryParse(match.Groups["version"].Value, out var version))
                    {
                        if (version >= new Version(1, 0, 7))
                        {
                            myLogger.Verbose($"com.unity.ide.rider version {version}. Skip EditorPlugin installation.");
                            return;
                        }

                        myLogger.Verbose($"com.unity.ide.rider version {version}. EditorPlugin installation continues.");
                    }
                }
            }

            var localPackage = mySolution.SolutionDirectory.Combine("Packages/com.unity.ide.rider/package.json");

            if (localPackage.ExistsFile)
            {
                myLogger.Verbose("Local package com.unity.ide.rider detected, skip EditorPlugin installation.");
                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.MainDispatcher,
                                                () => myRefresher.Refresh(RefreshType.Normal));
            });
        }
Пример #5
0
        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));
            });
        }
Пример #6
0
        private void InstallPluginIfRequired(Lifetime lifetime, [NotNull] IProject project)
        {
            if (!myBoundSettingsStore.GetValue((UnityPluginSettings s) => s.InstallUnity3DRiderPlugin))
            {
                return;
            }

            if (myPluginInstallations.Contains(project.ProjectFileLocation))
            {
                return;
            }

            var installationInfo = myDetector.GetInstallationInfo(project);

            if (!installationInfo.ShouldInstallPlugin)
            {
                return;
            }

            var currentVersion = typeof(UnityPluginInstaller).Assembly.GetName().Version;

            if (currentVersion <= installationInfo.Version)
            {
                return;
            }

            var isFreshInstall = installationInfo.Version == new Version();

            if (isFreshInstall)
            {
                myLogger.LogMessage(LoggingLevel.INFO, "Fresh install");
            }

            lock (mySyncObj)
            {
                if (myPluginInstallations.Contains(project.ProjectFileLocation))
                {
                    return;
                }

                FileSystemPath installedPath;

                if (!TryInstall(installationInfo, out installedPath))
                {
                    myLogger.LogMessage(LoggingLevel.WARN, "Plugin was not installed");
                }
                else
                {
                    string userTitle;
                    string userMessage;

                    if (isFreshInstall)
                    {
                        userTitle   = "Unity: plugin installed";
                        userMessage =
                            $@"Rider plugin v{currentVersion} for the Unity Editor was automatically installed for the project '{mySolution.Name}'
This allows better integration between the Unity Editor and Rider IDE.
The plugin file can be found on the following path:
{installedPath.MakeRelativeTo(mySolution.SolutionFilePath)}";
                    }
                    else
                    {
                        userTitle   = "Unity: plugin updated";
                        userMessage = $"Rider plugin was succesfully upgraded from version {installationInfo.Version} to {currentVersion}";
                    }

                    myLogger.LogMessage(LoggingLevel.INFO, userTitle);

                    var notification = new RdNotificationEntry(userTitle,
                                                               userMessage, true,
                                                               RdNotificationEntryType.INFO);
                    myNotifications.Notification.Fire(notification);
                }

                myPluginInstallations.Add(project.ProjectFileLocation);
            }
        }