Example #1
0
        public MonoInstallTrigger(Lifetime lifetime, ILogger logger, ISolutionLoadTasksScheduler scheduler,
                                  ISolution solution, UnitySolutionTracker unitySolutionTracker, UnityHost host)
        {
            if (PlatformUtil.RuntimePlatform != PlatformUtil.Platform.MacOsX)
            {
                return;
            }

            scheduler.EnqueueTask(new SolutionLoadTask("Check mono runtime", SolutionLoadTaskKinds.AfterDone, () =>
            {
                if (!unitySolutionTracker.IsUnityGeneratedProject.Value)
                {
                    return;
                }

                if (!HasModernUnityProjects(solution))
                {
                    return;
                }

                solution.Locks.Tasks.Queue(lifetime, () =>
                {
                    var wellKnownMonoRuntimes = MonoRuntimeDetector.DetectWellKnownMonoRuntimes();
                    var installedValidMono    = wellKnownMonoRuntimes
                                                .Any(runtime =>
                    {
                        var parsedVersion = string.Empty;
                        try
                        {
                            parsedVersion = ProcessOutputUtil.ExtractMonoVersion(runtime.ExePath);
                        }
                        catch (Exception e)
                        {
                            logger.Warn(e);
                        }

                        // if we fail to parse version - consider it is old
                        if (Version.TryParse(parsedVersion, out var version))
                        {
                            return(version.Major >= 5 && version.Minor >= 16);    // mono 5.16+ supports C# 7.3
                        }
                        logger.Warn("Failed to parse ProcessOutputUtil.ExtractMonoVersion output.");
                        return(false);
                    });

                    if (!installedValidMono)
                    {
                        solution.Locks.ExecuteOrQueue(lifetime, "Show install mono dialog",
                                                      () => { host.PerformModelAction(model => model.ShowInstallMonoDialog()); });
                    }
                });
            }));
        }
        public MonoInstallTrigger(Lifetime lifetime, ILogger logger, ISolutionLoadTasksScheduler scheduler,
                                  ISolution solution, UnitySolutionTracker unitySolutionTracker, UnityHost host,
                                  NotificationsModel notificationsModel)
        {
            if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.Windows)
            {
                return;
            }

            scheduler.EnqueueTask(new SolutionLoadTask("Check mono runtime", SolutionLoadTaskKinds.AfterDone, () =>
            {
                if (!unitySolutionTracker.IsUnityGeneratedProject.Value)
                {
                    return;
                }

                if (!HasModernUnityProjects(solution))
                {
                    return;
                }

                solution.Locks.Tasks.Queue(lifetime, () =>
                {
                    var wellKnownMonoRuntimes = MonoRuntimeDetector.DetectWellKnownMonoRuntimes();
                    var installedValidMono    = wellKnownMonoRuntimes
                                                .Any(runtime =>
                    {
                        var parsedVersion = string.Empty;
                        try
                        {
                            parsedVersion = ProcessOutputUtil.ExtractMonoVersion(runtime.ExePath);
                        }
                        catch (Exception e)
                        {
                            logger.Warn(e);
                        }

                        // if we fail to parse version - consider it is old
                        if (Version.TryParse(parsedVersion, out var version))
                        {
                            return(version >= new Version(5, 16));    // mono 5.16+ supports C# 7.3
                        }
                        logger.Warn("Failed to parse ProcessOutputUtil.ExtractMonoVersion output.");
                        return(false);
                    });

                    if (installedValidMono)
                    {
                        return;
                    }

                    if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.MacOsX)
                    {
                        solution.Locks.ExecuteOrQueue(lifetime, "Show install mono dialog",
                                                      () => { host.PerformModelAction(model => model.ShowInstallMonoDialog()); });
                    }
                    else if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.Linux)
                    {
                        var notification = new NotificationModel("Mono 5.16+ is required",
                                                                 "<html>Project requires new Mono with MSBuild for new C# language features support.<br>" +
                                                                 RiderContextNotificationHelper.MakeOpenSettingsLink(
                                                                     WellKnownSettingPages.Environment,
                                                                     "Install the latest Mono")
                                                                 + ".<br>" +
                                                                 "If a Mono runtime is available in a non-standard location, please " +
                                                                 RiderContextNotificationHelper.MakeOpenSettingsLink(
                                                                     WellKnownSettingPages.ToolsetAndBuild,
                                                                     "specify the custom runtime location in settings")
                                                                 + ".</html>"

                                                                 , true,
                                                                 RdNotificationEntryType.WARN);
                        solution.Locks.ExecuteOrQueue(lifetime, "MonoInstallTrigger.Notify", () => notificationsModel.Notification(notification));
                    }
                });
            }));
        }