public void QueToDownload(uint256 hash) { using (BlocksFolderLock.Lock()) using (BlocksToDownloadLock.Lock()) { var filePaths = Directory.EnumerateFiles(BlocksFolderPath); var fileNames = filePaths.Select(x => Path.GetFileName(x)); var hashes = fileNames.Select(x => new uint256(x)); if (!hashes.Contains(hash)) { if (!BlocksToDownload.Contains(hash)) { BlocksToDownload.Add(hash); } } } }
/// <remarks> /// Use it at reorgs. /// </remarks> public void TryRemove(uint256 hash) { using (BlocksFolderLock.Lock()) using (BlocksToDownloadLock.Lock()) { if (BlocksToDownload.Contains(hash)) { BlocksToDownload.Remove(hash); } var filePaths = Directory.EnumerateFiles(BlocksFolderPath); var fileNames = filePaths.Select(x => Path.GetFileName(x)); var hashes = fileNames.Select(x => new uint256(x)); if (hashes.Contains(hash)) { File.Delete(Path.Combine(BlocksFolderPath, hash.ToString())); } } }