Пример #1
0
        private GitInstallationState ExtractGit(GitInstallationState state)
        {
            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 =>
                {
                    LogHelper.Trace(e, "Failed to unzip " + installDetails.GitZipPath);
                    return(true);
                });
                unzipTask.Progress(p => Progress.UpdateProgress(40 + (long)(20 * p.Percentage), 100, unzipTask.Message));
                unzipTask.RunSynchronously();
                var target = state.GitInstallationPath;
                if (unzipTask.Successful)
                {
                    Logger.Trace("Moving Git source:{0} target:{1}", gitExtractPath.ToString(), target.ToString());

                    CopyHelper.Copy(gitExtractPath, target);

                    state.GitIsValid = true;

                    state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
                }
            }

            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 =>
                {
                    LogHelper.Trace(e, "Failed to unzip " + installDetails.GitLfsZipPath);
                    return(true);
                });
                unzipTask.Progress(p => Progress.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Message));
                unzipTask.RunSynchronously();
                var target = state.GitLfsInstallationPath;
                if (unzipTask.Successful)
                {
                    Logger.Trace("Moving GitLFS source:{0} target:{1}", gitLfsExtractPath.ToString(), target.ToString());

                    CopyHelper.Copy(gitLfsExtractPath, target);

                    state.GitLfsIsValid = true;
                }
            }

            tempZipExtractPath.DeleteIfExists();
            return(state);
        }
Пример #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;
            })));
        }
Пример #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);
        }