public static string EnsureDownloaded(NodeDownloadData downloadData) { if (!Directory.Exists("TestData")) { Directory.CreateDirectory("TestData"); } var osDownloadData = downloadData.GetCurrentOSDownloadData(); if (osDownloadData == null) { throw new Exception("This platform does not support tests involving this crypto currency, DownloadData for this OS are unavailable"); } var bitcoind = Path.Combine("TestData", String.Format(osDownloadData.Executable, downloadData.Version)); var zip = Path.Combine("TestData", String.Format(osDownloadData.Archive, downloadData.Version)); if (File.Exists(bitcoind)) { return(bitcoind); } string url = String.Format(osDownloadData.DownloadLink, downloadData.Version); HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMinutes(10.0); var data = client.GetByteArrayAsync(url).GetAwaiter().GetResult(); CheckHash(osDownloadData, data); File.WriteAllBytes(zip, data); var extractDirectory = "TestData"; if (osDownloadData.CreateFolder != null) { if (!Directory.Exists(osDownloadData.CreateFolder)) { Directory.CreateDirectory(osDownloadData.CreateFolder); } extractDirectory = Path.Combine(extractDirectory, string.Format(osDownloadData.CreateFolder, downloadData.Version)); } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { ZipFile.ExtractToDirectory(zip, extractDirectory); } else { Process.Start("tar", "-zxvf " + zip + " -C " + extractDirectory).WaitForExit(); } File.Delete(zip); return(bitcoind); }
public static NodeBuilder Create(NodeDownloadData downloadData, Network network = null, [CallerMemberNameAttribute] string caller = null, bool showNodeConsole = false) { network = network ?? Network.RegTest; var isFilePath = downloadData.Version.Length >= 2 && downloadData.Version[1] == ':'; var path = isFilePath ? downloadData.Version : EnsureDownloaded(downloadData); if (!Directory.Exists(caller)) { Directory.CreateDirectory(caller); } return(new NodeBuilder(caller, path) { Network = network, NodeImplementation = downloadData, ShowNodeConsole = showNodeConsole }); }