public void Run(bool firstRun) { Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory); var initEnvironmentTask = new ActionTask <NPath>(CancellationToken, (_, path) => InitializeEnvironment(path)) { Affinity = TaskAffinity.UI }; isBusy = true; var octorunInstaller = new OctorunInstaller(Environment, TaskManager); var setupTask = octorunInstaller .SetupOctorunIfNeeded() .Then((s, octorunPath) => { Environment.OctorunScriptPath = octorunPath; }); var initializeGitTask = 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); }); initializeGitTask.OnEnd += (t, path, _, __) => { if (path.IsInitialized) { return; } Logger.Trace("Using portable git"); var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager); var task = gitInstaller.SetupGitIfNeeded(); task.Progress(progressReporter.UpdateProgress); task.OnEnd += (thisTask, result, success, exception) => { thisTask.GetEndOfChain().Then(initEnvironmentTask, taskIsTopOfChain: true); }; // append installer task to top chain t.Then(task, taskIsTopOfChain: true); }; setupTask.Then(initializeGitTask).Start(); }
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(); }