Ejemplo n.º 1
0
        private void ExtractPortableGit(ActionTask <NPath> onSuccess, ITask onFailure)
        {
            ITask downloadFilesTask = null;

            if ((gitArchiveFilePath == null) || (gitLfsArchivePath == null))
            {
                downloadFilesTask = CreateDownloadTask();
            }

            var tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
            var gitExtractPath     = tempZipExtractPath.Combine("git").CreateDirectory();
            var gitLfsExtractPath  = tempZipExtractPath.Combine("git-lfs").CreateDirectory();

            var resultTask = new UnzipTask(cancellationToken, gitArchiveFilePath, gitExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails.GitExtractedMD5)
                             .Then(new UnzipTask(cancellationToken, gitLfsArchivePath, gitLfsExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails.GitLfsExtractedMD5))
                             .Then(s => MoveGitAndLfs(gitExtractPath, gitLfsExtractPath, tempZipExtractPath));

            resultTask.Then(onFailure, TaskRunOptions.OnFailure);
            resultTask.Then(onSuccess, TaskRunOptions.OnSuccess);

            if (downloadFilesTask != null)
            {
                resultTask = downloadFilesTask.Then(resultTask);
            }

            resultTask.Start();
        }
Ejemplo n.º 2
0
        private FuncTask <NPath> ExtractPortableGit(GitInstallationState state)
        {
            ITask <NPath> task = null;
            var           tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
            var           gitExtractPath     = tempZipExtractPath.Combine("git").CreateDirectory();

            if (!state.GitIsValid)
            {
                ITask <NPath> unzipTask = new UnzipTask(cancellationToken, installDetails.GitZipPath, gitExtractPath, sharpZipLibHelper,
                                                        environment.FileSystem);
                unzipTask.Progress(p => installationTask.UpdateProgress(40 + (long)(20 * p.Percentage), 100, unzipTask.Name));

                unzipTask = unzipTask.Then((s, path) =>
                {
                    var source = path;
                    var target = installDetails.GitInstallationPath;
                    target.DeleteIfExists();
                    target.EnsureParentDirectoryExists();
                    Logger.Trace($"Moving '{source}' to '{target}'");
                    source.Move(target);
                    state.GitExists  = installDetails.GitExecutablePath.FileExists();
                    state.GitIsValid = s;
                    return(path);
                });
                task = unzipTask;
            }

            var gitLfsExtractPath = tempZipExtractPath.Combine("git-lfs").CreateDirectory();

            if (!state.GitLfsIsValid)
            {
                ITask <NPath> unzipTask = new UnzipTask(cancellationToken, installDetails.GitLfsZipPath, gitLfsExtractPath, sharpZipLibHelper,
                                                        environment.FileSystem);
                unzipTask.Progress(p => installationTask.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Name));

                unzipTask = unzipTask.Then((s, path) =>
                {
                    var source = path.Combine(installDetails.GitLfsExecutable);
                    var target = installDetails.GetGitLfsExecutablePath(installDetails.GitInstallationPath);
                    target.DeleteIfExists();
                    target.EnsureParentDirectoryExists();
                    Logger.Trace($"Moving '{source}' to '{target}'");
                    source.Move(target);
                    state.GitExists  = target.FileExists();
                    state.GitIsValid = s;
                    return(path);
                });
                task = task?.Then(unzipTask) ?? unzipTask;
            }

            return(task.Finally(new FuncTask <NPath>(cancellationToken, (success) =>
            {
                tempZipExtractPath.DeleteIfExists();
                return installDetails.GitInstallationPath;
            })));
        }
Ejemplo n.º 3
0
        private void ExtractPortableGit(ITask <GitInstallationState> thisTask,
                                        GitInstallationState state, bool s, Exception exception)
        {
            ITask <NPath> task = null;
            var           tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");

            if (state.GitZipExists && !state.GitIsValid)
            {
                var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
                var unzipTask      = new UnzipTask(cancellationToken, installDetails.GitZipPath,
                                                   gitExtractPath, sharpZipLibHelper,
                                                   environment.FileSystem)
                                     .Catch(e => true);
                unzipTask.Progress(p => installationTask.UpdateProgress(40 + (long)(20 * p.Percentage), 100, unzipTask.Name));

                unzipTask = unzipTask.Then((success, path) =>
                {
                    var target = installDetails.GitInstallationPath;
                    if (success)
                    {
                        var source = path;
                        target.DeleteIfExists();
                        target.EnsureParentDirectoryExists();
                        Logger.Trace($"Moving '{source}' to '{target}'");
                        source.Move(target);
                        state.GitInstallationPath = installDetails.GitInstallationPath;
                        state.GitExecutablePath   = installDetails.GitExecutablePath;
                        state.GitIsValid          = success;
                    }
                    return(target);
                });
                task = unzipTask;
            }

            if (state.GitLfsZipExists && !state.GitLfsIsValid)
            {
                var gitLfsExtractPath = tempZipExtractPath.Combine("git-lfs").CreateDirectory();
                var unzipTask         = new UnzipTask(cancellationToken, installDetails.GitLfsZipPath,
                                                      gitLfsExtractPath, sharpZipLibHelper,
                                                      environment.FileSystem)
                                        .Catch(e => true);
                unzipTask.Progress(p => installationTask.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Name));

                unzipTask = unzipTask.Then((success, path) =>
                {
                    var target = installDetails.GetGitLfsExecutablePath(state.GitInstallationPath);
                    if (success)
                    {
                        var source = path.Combine(installDetails.GitLfsExecutable);
                        target.DeleteIfExists();
                        target.EnsureParentDirectoryExists();
                        Logger.Trace($"Moving '{source}' to '{target}'");
                        source.Move(target);
                        state.GitLfsInstallationPath = state.GitInstallationPath;
                        state.GitLfsExecutablePath   = target;
                        state.GitLfsIsValid          = success;
                    }
                    return(target);
                });
                task = task?.Then(unzipTask) ?? unzipTask;
            }

            var endTask = new FuncTask <GitInstallationState>(cancellationToken, (success) =>
            {
                tempZipExtractPath.DeleteIfExists();
                return(state);
            });

            if (task != null)
            {
                endTask = task.Then(endTask);
            }

            thisTask
            .Then(endTask)
            .Then(installationTask);
        }