Пример #1
0
        public NPath SetupOctorunIfNeeded()
        {
            NPath path = NPath.Default;
            var   isOctorunExtracted = IsOctorunExtracted();

            if (isOctorunExtracted)
            {
                return(installDetails.ExecutablePath);
            }

            GrabZipFromResources();

            var tempZipExtractPath = NPath.CreateTempDirectory("octorun_extract_archive_path");
            var unzipTask          = new UnzipTask(taskManager.Token, installDetails.ZipFile,
                                                   tempZipExtractPath, sharpZipLibHelper,
                                                   fileSystem)
                                     .Catch(e => { Logger.Error(e, "Error extracting octorun"); return(true); });
            var extractPath = unzipTask.RunSynchronously();

            if (unzipTask.Successful)
            {
                path = MoveOctorun(extractPath.Combine("octorun"));
            }
            return(path);
        }
Пример #2
0
        private ITask CreateDownloadTask()
        {
            var tempZipPath = NPath.CreateTempDirectory("git_zip_paths");

            gitArchiveFilePath = tempZipPath.Combine("git.zip");
            gitLfsArchivePath  = tempZipPath.Combine("git-lfs.zip");

            var downloadGitMd5Task = new DownloadTextTask(TaskManager.Instance.Token, environment.FileSystem,
                                                          installDetails.GitZipMd5Url, tempZipPath);

            var downloadGitTask = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem,
                                                   installDetails.GitZipUrl, tempZipPath);

            var downloadGitLfsMd5Task = new DownloadTextTask(TaskManager.Instance.Token, environment.FileSystem,
                                                             installDetails.GitLfsZipMd5Url, tempZipPath);

            var downloadGitLfsTask = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem,
                                                      installDetails.GitLfsZipUrl, tempZipPath);

            return
                (downloadGitMd5Task.Then((b, s) => { downloadGitTask.ValidationHash = s; })
                 .Then(downloadGitTask)
                 .Then(downloadGitLfsMd5Task)
                 .Then((b, s) => { downloadGitLfsTask.ValidationHash = s; })
                 .Then(downloadGitLfsTask));
        }
Пример #3
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();
        }
Пример #4
0
        public ITask <NPath> SetupOctorunIfNeeded()
        {
            //Logger.Trace("SetupOctorunIfNeeded");

            var task = new FuncTask <NPath>(taskManager.Token, () =>
            {
                var isOctorunExtracted = IsOctorunExtracted();
                Logger.Trace("isOctorunExtracted: {0}", isOctorunExtracted);
                if (isOctorunExtracted)
                {
                    return(installDetails.ExecutablePath);
                }
                GrabZipFromResources();
                return(NPath.Default);
            });

            task.OnEnd += (t, path, _, __) =>
            {
                if (!path.IsInitialized)
                {
                    var tempZipExtractPath = NPath.CreateTempDirectory("octorun_extract_archive_path");
                    var unzipTask          = new UnzipTask(taskManager.Token, installDetails.ZipFile,
                                                           tempZipExtractPath, sharpZipLibHelper,
                                                           fileSystem)
                                             .Then((success, extractPath) => MoveOctorun(extractPath.Combine("octorun")));
                    t.Then(unzipTask);
                }
            };

            return(task);
        }
Пример #5
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);
        }
Пример #6
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;
            })));
        }
Пример #7
0
 public DownloadTask(CancellationToken token,
                     IFileSystem fileSystem, UriString url,
                     NPath targetDirectory = null,
                     string filename       = null,
                     string validationHash = null, int retryCount = 0)
     : base(token)
 {
     this.fileSystem = fileSystem;
     ValidationHash  = validationHash;
     RetryCount      = retryCount;
     Url             = url;
     Filename        = filename ?? url.Filename;
     TargetDirectory = targetDirectory ?? NPath.CreateTempDirectory("ghu");
     Name            = nameof(DownloadTask);
 }
Пример #8
0
        public async Task <bool> SetupIfNeeded(IProgress <float> zipFileProgress = null, IProgress <long> estimatedDurationProgress = null)
        {
            logger.Trace("SetupIfNeeded");

            cancellationToken.ThrowIfCancellationRequested();

            NPath tempPath = null;

            try
            {
                tempPath = NPath.CreateTempDirectory(TempPathPrefix);

                cancellationToken.ThrowIfCancellationRequested();

                var ret = await SetupGitIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);

                cancellationToken.ThrowIfCancellationRequested();

                ret &= await SetupGitLfsIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);

                tempPath.Delete();
                return(ret);
            }
            catch (Exception ex)
            {
                logger.Trace(ex);
                return(false);
            }
            finally
            {
                try
                {
                    if (tempPath != null)
                    {
                        tempPath.DeleteIfExists();
                    }
                }
                catch {}
            }
        }
Пример #9
0
 private NPath GetTemporaryPath()
 {
     return(NPath.CreateTempDirectory(TempPathPrefix));
 }
Пример #10
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);
        }