Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions dotnet/src/webdriver/Remote/RemoteWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ public DevToolsSession GetDevToolsSession(int protocolVersion)
public IReadOnlyList<string> GetDownloadableFiles()
{
var enableDownloads = this.Capabilities.GetCapability(CapabilityType.EnableDownloads);
if (enableDownloads == null || !(bool) enableDownloads) {
if (enableDownloads == null || !(bool)enableDownloads)
{
throw new WebDriverException("You must enable downloads in order to work with downloadable files.");
}

Expand All @@ -494,7 +495,8 @@ public IReadOnlyList<string> GetDownloadableFiles()
public void DownloadFile(string fileName, string targetDirectory)
{
var enableDownloads = this.Capabilities.GetCapability(CapabilityType.EnableDownloads);
if (enableDownloads == null || !(bool) enableDownloads) {
if (enableDownloads == null || !(bool)enableDownloads)
{
throw new WebDriverException("You must enable downloads in order to work with downloadable files.");
}

Expand All @@ -508,20 +510,19 @@ public void DownloadFile(string fileName, string targetDirectory)
byte[] fileData = Convert.FromBase64String(contents);

Directory.CreateDirectory(targetDirectory);
string tempFile = Path.Combine(targetDirectory, "temp.zip");
File.WriteAllBytes(tempFile, fileData);

using (ZipArchive archive = ZipFile.OpenRead(tempFile))
using (var memoryReader = new MemoryStream(fileData))
{
foreach (ZipArchiveEntry entry in archive.Entries)
using (var zipArchive = new ZipArchive(memoryReader, ZipArchiveMode.Read))
{
string destinationPath = Path.Combine(targetDirectory, entry.FullName);
foreach (ZipArchiveEntry entry in zipArchive.Entries)
{
string destinationPath = Path.Combine(targetDirectory, entry.FullName);

entry.ExtractToFile(destinationPath);
entry.ExtractToFile(destinationPath);
}
}
}

File.Delete(tempFile);
}

/// <summary>
Expand All @@ -530,7 +531,8 @@ public void DownloadFile(string fileName, string targetDirectory)
public void DeleteDownloadableFiles()
{
var enableDownloads = this.Capabilities.GetCapability(CapabilityType.EnableDownloads);
if (enableDownloads == null || !(bool) enableDownloads) {
if (enableDownloads == null || !(bool)enableDownloads)
{
throw new WebDriverException("You must enable downloads in order to work with downloadable files.");
}

Expand Down