Skip to content

Commit

Permalink
Removing custom zip archive code from .NET
Browse files Browse the repository at this point in the history
Instead of using the custom ZipStorer class, we can now use the built-in
.NET zip archive handling classes. This is possible because we no longer
support .NET versions less than 4.5.
  • Loading branch information
jimevans committed Apr 11, 2019
1 parent 3f4b1c2 commit f4f2b4f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 791 deletions.
10 changes: 2 additions & 8 deletions dotnet/src/webdriver/Firefox/FirefoxExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,9 @@ public void Install(string profileDirectory)
// First, expand the .xpi archive into a temporary location.
Directory.CreateDirectory(tempFileName);
Stream zipFileStream = ResourceUtilities.GetResourceStream(this.extensionFileName, this.extensionResourceId);
using (ZipStorer extensionZipFile = ZipStorer.Open(zipFileStream, FileAccess.Read))
using (ZipArchive extensionZipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Read))
{
List<ZipStorer.ZipFileEntry> entryList = extensionZipFile.ReadCentralDirectory();
foreach (ZipStorer.ZipFileEntry entry in entryList)
{
string localFileName = entry.FilenameInZip.Replace('/', Path.DirectorySeparatorChar);
string destinationFile = Path.Combine(tempFileName, localFileName);
extensionZipFile.ExtractFile(entry, destinationFile);
}
extensionZipArchive.ExtractToDirectory(tempFileName);
}

// Then, copy the contents of the temporarly location into the
Expand Down
16 changes: 5 additions & 11 deletions dotnet/src/webdriver/Firefox/FirefoxProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,9 @@ public static FirefoxProfile FromBase64String(string base64)
byte[] zipContent = Convert.FromBase64String(base64);
using (MemoryStream zipStream = new MemoryStream(zipContent))
{
using (ZipStorer profileZipArchive = ZipStorer.Open(zipStream, FileAccess.Read))
using (ZipArchive profileZipArchive = new ZipArchive(zipStream, ZipArchiveMode.Read))
{
List<ZipStorer.ZipFileEntry> entryList = profileZipArchive.ReadCentralDirectory();
foreach (ZipStorer.ZipFileEntry entry in entryList)
{
string fileName = entry.FilenameInZip.Replace('/', Path.DirectorySeparatorChar);
string destinationFile = Path.Combine(destinationDirectory, fileName);
profileZipArchive.ExtractFile(entry, destinationFile);
}
profileZipArchive.ExtractToDirectory(destinationDirectory);
}
}

Expand Down Expand Up @@ -208,13 +202,13 @@ public string ToBase64String()

using (MemoryStream profileMemoryStream = new MemoryStream())
{
using (ZipStorer profileZipArchive = ZipStorer.Create(profileMemoryStream, string.Empty))
using (ZipArchive profileZipArchive = new ZipArchive(profileMemoryStream, ZipArchiveMode.Create, true))
{
string[] files = Directory.GetFiles(this.profileDir, "*.*", SearchOption.AllDirectories);
foreach (string file in files)
{
string fileNameInZip = file.Substring(this.profileDir.Length).Replace(Path.DirectorySeparatorChar, '/');
profileZipArchive.AddFile(ZipStorer.CompressionMethod.Deflate, file, fileNameInZip, string.Empty);
string fileNameInZip = file.Substring(this.profileDir.Length + 1).Replace(Path.DirectorySeparatorChar, '/');
profileZipArchive.CreateEntryFromFile(file, fileNameInZip);
}
}

Expand Down

0 comments on commit f4f2b4f

Please sign in to comment.