private ITask <string> RunCredentialHelper(string action, string[] lines)
        {
            SimpleProcessTask task;

            if (credHelper.StartsWith('!'))
            {
                // it's a separate app, run it as such
                task = new SimpleProcessTask(taskManager.Token, credHelper.Substring(1).ToNPath(), action);
            }
            else
            {
                var args = $"credential-{credHelper} {action}";
                task = new SimpleProcessTask(taskManager.Token, args);
            }

            task.Configure(processManager, true);

            task.OnStartProcess += proc =>
            {
                foreach (var line in lines)
                {
                    proc.StandardInput.WriteLine(line);
                }
                proc.StandardInput.Close();
            };

            return(task);
        }
Esempio n. 2
0
        private ITask <NPath[]> CalculateFolderDiff(ChangesTreeNode node)
        {
            var rightFile    = node.Path.ToNPath();
            var tmpDir       = Manager.Environment.UnityProjectPath.Combine("Temp").CreateTempDirectory();
            var changedFiles = treeChanges.GetLeafNodes(node).Select(x => x.Path.ToNPath()).ToList();

            return(new FuncTask <List <NPath>, NPath[]>(TaskManager.Token, (s, files) =>
            {
                var leftFolder = tmpDir.Combine("left", rightFile.FileName);
                var rightFolder = tmpDir.Combine("right", rightFile.FileName);
                foreach (var file in files)
                {
                    var txt = new SimpleProcessTask(TaskManager.Token, "show HEAD:\"" + file.ToString(SlashMode.Forward) + "\"")
                              .Configure(Manager.ProcessManager, false)
                              .Catch(_ => true)
                              .RunSynchronously();
                    if (txt != null)
                    {
                        leftFolder.Combine(file.RelativeTo(rightFile)).WriteAllText(txt);
                    }
                    if (file.FileExists())
                    {
                        rightFolder.Combine(file.RelativeTo(rightFile)).WriteAllText(file.ReadAllText());
                    }
                }
                return new NPath[] { leftFolder, rightFolder };
            }, () => changedFiles)
            {
                Message = "Calculating diff..."
            });
        }
        public void Run()
        {
            isBusy = true;
            progress.UpdateProgress(0, 100, "Initializing...");

            if (firstRun)
            {
                UsageTracker.IncrementNumberOfStartups();
            }

            var thread = new Thread(() =>
            {
                GitInstallationState state = new GitInstallationState();
                try
                {
                    if (Environment.IsMac)
                    {
                        var getEnvPath = new SimpleProcessTask(TaskManager.Token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
                                         .Configure(ProcessManager, dontSetupGit: true)
                                         .Catch(e => true); // make sure this doesn't throw if the task fails
                        var path = getEnvPath.RunSynchronously();
                        if (getEnvPath.Successful)
                        {
                            Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
                            Environment.Path = path?.Split(new[] { "\"" }, StringSplitOptions.None)[1];
                        }
                    }

                    progress.UpdateProgress(20, 100, "Setting up octorun...");

                    Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
                                                    .SetupOctorunIfNeeded();

                    progress.UpdateProgress(50, 100, "Setting up git...");

                    state = Environment.GitInstallationState;
                    if (!state.GitIsValid && !state.GitLfsIsValid && FirstRun)
                    {
                        // importing old settings
                        NPath gitExecutablePath = Environment.SystemSettings.Get(Constants.GitInstallPathKey, NPath.Default);
                        if (gitExecutablePath.IsInitialized)
                        {
                            Environment.SystemSettings.Unset(Constants.GitInstallPathKey);
                            state.GitExecutablePath          = gitExecutablePath;
                            state.GitInstallationPath        = gitExecutablePath.Parent.Parent;
                            Environment.GitInstallationState = state;
                        }
                    }


                    var installer = new GitInstaller(Environment, ProcessManager, TaskManager.Token);
                    installer.Progress(progressReporter.UpdateProgress);
                    if (state.GitIsValid && state.GitLfsIsValid)
                    {
                        if (firstRun)
                        {
                            installer.ValidateGitVersion(state);
                            if (state.GitIsValid)
                            {
                                installer.ValidateGitLfsVersion(state);
                            }
                        }
                    }

                    if (!state.GitIsValid || !state.GitLfsIsValid)
                    {
                        state = installer.RunSynchronously();
                    }

                    SetupGit(state);

                    progress.UpdateProgress(80, 100, "Initializing repository...");

                    if (state.GitIsValid && state.GitLfsIsValid)
                    {
                        RestartRepository();
                    }

                    progress.UpdateProgress(100, 100, "Initialized");
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "A problem ocurred setting up Git");
                    progress.UpdateProgress(90, 100, "Initialization failed");
                }

                new ActionTask <bool>(TaskManager.Token, (s, gitIsValid) =>
                {
                    InitializationComplete();
                    if (gitIsValid)
                    {
                        InitializeUI();
                    }
                },
                                      () => state.GitIsValid && state.GitLfsIsValid)
                {
                    Affinity = TaskAffinity.UI
                }
                .Start();
            });

            thread.Start();
        }