コード例 #1
0
        public void Run(bool firstRun)
        {
            Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
            isBusy = true;

            var endTask = new ActionTask <GitInstaller.GitInstallationState>(CancellationToken,
                                                                             (_, state) => InitializeEnvironment(state))
            {
                Affinity = TaskAffinity.UI
            };

            ITask <string> setExistingEnvironmentPath;

            if (Environment.IsMac)
            {
                setExistingEnvironmentPath = new SimpleProcessTask(CancellationToken, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
                                             .Configure(ProcessManager, dontSetupGit: true)
                                             .Catch(e => true) // make sure this doesn't throw if the task fails
                                             .Then((success, path) => success ? path?.Split(new[] { "\"" }, StringSplitOptions.None)[1] : null);
            }
            else
            {
                setExistingEnvironmentPath = new FuncTask <string>(CancellationToken, () => null);
            }

            setExistingEnvironmentPath.OnEnd += (t, path, success, ex) =>
            {
                if (path != null)
                {
                    Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
                    Environment.Path = path;
                }
            };

            var setupOctorun          = new OctorunInstaller(Environment, TaskManager).SetupOctorunIfNeeded();
            var setOctorunEnvironment = new ActionTask <NPath>(CancellationToken,
                                                               (s, octorunPath) => Environment.OctorunScriptPath = octorunPath);

            var getGitFromSettings = new FuncTask <NPath>(CancellationToken, () =>
            {
                var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
                if (gitExecutablePath.HasValue && gitExecutablePath.Value.FileExists()) // we have a git path
                {
                    Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
                    return(gitExecutablePath.Value);
                }
                return(NPath.Default);
            });

            getGitFromSettings.OnEnd += (t, path, _, __) =>
            {
                if (path.IsInitialized)
                {
                    var state = new GitInstaller.GitInstallationState {
                        GitExecutablePath = path,
                        GitIsValid        = true
                    };
                    endTask.PreviousResult = state;
                    endTask.Start();
                    return;
                }
                Logger.Trace("Using portable git");

                var setupGit = new GitInstaller(Environment, ProcessManager, TaskManager).SetupGitIfNeeded();
                t.Then(setupGit);
                setupGit.Finally((s, state) =>
                {
                    endTask.PreviousResult = state;
                    endTask.Start();
                });
                setupGit.Progress(progressReporter.UpdateProgress);
                // append installer task to top chain
            };

            var setupChain = setExistingEnvironmentPath.Then(setupOctorun);

            setupChain.OnEnd += (t, path, _, __) =>
            {
                t.GetEndOfChain().Then(setOctorunEnvironment).Then(getGitFromSettings);
            };

            setupChain.Start();
        }