public void Download(bool force) { var downloader = new Downloader(); var filepath = this.Pogo.ArchivePath(this.uri); if (force) { if (filepath.ExistsFile()) { filepath.DeleteFile(); } else if (filepath.ExistsDirectory()) { PathNameTools.RemoveDirectory(filepath); } } if (filepath.ExistsDirectory()) { throw PathNameErrors.EntityExistsButIsNotFile(filepath); } if (!filepath.ExistsFile()) { var bytes = downloader.GetBytes(this.uri); if (bytes != null) { filepath.Parent.CreateDirectory(); filepath.WriteAllBytes(bytes); } } }
public bool Extract(bool force) { var archivePath = Pogo.ArchivePath(this.uri); var extractPath = Pogo.SourcePath(this.uri); if (!archivePath.ExistsFile()) { throw PathNameErrors.FileNotFoundException(archivePath); } if (extractPath.ExistsDirectory()) { if (!force) { return(true); } Terminal.Write("clean ", extractPath.Name, ": "); PathNameTools.RemoveDirectory(extractPath); Terminal.ClearLine(); } if (extractPath.ExistsFile()) { throw PathNameErrors.EntityExistsButIsNotDirectory(extractPath); } PathName extractPathTmp = extractPath.Full + ".tmp"; if (extractPathTmp.ExistsDirectory()) { Terminal.Write("clean ", extractPathTmp.Name, ": "); PathNameTools.RemoveDirectory(extractPathTmp); Terminal.ClearLine(); } if (extractPathTmp.ExistsFile()) { throw PathNameErrors.EntityExistsButIsNotDirectory(extractPathTmp); } extractPathTmp.CreateDirectory(); Terminal.Write("extract ", archivePath.Name, ": "); var xtract = Bash.TarExtract(archivePath, extractPathTmp); Terminal.ClearLine(); var dirs = extractPathTmp.EnumerateDirectories().ToList(); var files = extractPathTmp.EnumerateFiles().ToList(); if (dirs.Count == 1 && files.Count == 0) { dirs.First().MoveDirectory(extractPath); extractPathTmp.DeleteDirectory(); } else { extractPathTmp.MoveDirectory(extractPath); } Terminal.WriteLine("extract ", xtract.Ok ? "OK: " : "FAIL: ", archivePath.Name); return(xtract.Ok); }