private static async Task <List <string> > ExtractSoloArchive(string archivePath, string targetDir) { if (!SetLibraryPath(EXTRACTOR_LIB)) { return(null); } var tcs = new TaskCompletionSource <List <string> >(); var zpr = new SevenZipExtractor(archivePath); var list = new List <string>(); zpr.FileExtractionFinished += (s, e) => list.Add(e.FileInfo.FileName); zpr.ExtractionFinished += (s, e) => tcs.SetResult(list); zpr.ExtractArchive(targetDir); var contents = await tcs.Task; if (contents == null) { return(Alerter.Warn("Content list is NULL.")); } if (contents.Count == 0) { return(Alerter.Warn("Archive did not contain any file.")); } return(contents); }
private R1Executable FindLocalExe() { var exePath = ""; var args = Environment.GetCommandLineArgs(); if (args.Length > 1) { exePath = args[1]; if (!File.Exists(exePath)) { return(Alerter.Warn( $"Exe path from argument is invalid:{L.f} {exePath}")); } } else { var exes = ValidExeFile.FindAll(); if (exes.Count != 1) { return(Alerter.Warn((exes.Count == 0 ? "No" : "More than 1") + " .exe file found.")); } exePath = exes[0]; } var exe = R1Exe.FromFile(exePath); return(exe); }
private async Task <byte[]> GetPartContentByHash(string partHash) { var list = await ViewsList <SplitPartContentByHashDTO>(partHash); if (list == null) { return(null); } if (list.Count == 0) { return(Alerter.Warn($"No content found for ‹{partHash}›")); } return(Convert.FromBase64String(list[0].Base64Content)); }
private async Task <bool> ValidateDownload(List <R1SplitPart> splitParts, string expectedHash) { var downloaded = await _downloadr.DownloadAndExtract(splitParts, expectedHash); if (downloaded.IsBlank()) { return(Alerter.Warn("Failed to download/assemble/validate the file.", false)); } //if (downloaded.SHA1ForFile() != expectedHash) // return Alerter.Warn("Hash of downloaded file is different.", false); File.Delete(downloaded); Status = "Uploaded files validated successfully."; return(true); }
internal async Task <bool> UploadNew (R1Executable localExe, double?maxVolumeSizeMB) { IsBusy = true; Status = "Compressing ..."; var tmpCopy = CopyToTemp(localExe.FullPathOrURL); var splitParts = new List <R1SplitPart>(); var partPaths = await SevenZipper1.Compress(tmpCopy, null, maxVolumeSizeMB, ".data"); for (int i = 0; i < partPaths.Count; i++) { Status = $"Uploading part {i + 1} of {partPaths.Count} ..."; var r1Part = FilePart.ToR1Part(partPaths[i], localExe, i + 1, partPaths.Count); var node = await Create(r1Part, () => GetSplitPartIDsByHash(r1Part.PartHash)); if (node == null) { return(false); } splitParts.Add(r1Part); } var ok = await ValidateDownload(splitParts, localExe.FileHash); if (!ok) { //todo: delete corrupted uploaded parts return(Alerter.Warn("Uploaded parts are invalid.", false)); } IsBusy = false; return(true); }