Skip to content

Commit 4680a96

Browse files
committed
Replacing DotNetZip with ZipStorer library
The replacement library uses the internal System.IO.Compression classes along with custom code for reading and writing the central directory structure of .zip files. The resulting .zip files created may be slightly larger than those produced via DotNetZip, but we will sacrifice that small size difference in exchange for cross-platform usability.
1 parent 1660076 commit 4680a96

File tree

10 files changed

+1605
-33
lines changed

10 files changed

+1605
-33
lines changed

Diff for: dotnet/src/webdriver/Firefox/FirefoxExtension.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
using System.IO;
2222
using System.Text;
2323
using System.Xml;
24-
using Ionic.Zip;
2524
using OpenQA.Selenium.Internal;
25+
using System.IO.Compression;
2626

2727
namespace OpenQA.Selenium.Firefox
2828
{
@@ -83,10 +83,15 @@ public void Install(string profileDir)
8383
// First, expand the .xpi archive into a temporary location.
8484
Directory.CreateDirectory(tempFileName);
8585
Stream zipFileStream = ResourceUtilities.GetResourceStream(this.extensionFileName, this.extensionResourceId);
86-
using (ZipFile extensionZipFile = ZipFile.Read(zipFileStream))
86+
using (ZipStorer extensionZipFile = ZipStorer.Open(zipFileStream, FileAccess.Read))
8787
{
88-
extensionZipFile.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
89-
extensionZipFile.ExtractAll(tempFileName);
88+
List<ZipStorer.ZipFileEntry> entryList = extensionZipFile.ReadCentralDir();
89+
foreach (ZipStorer.ZipFileEntry entry in entryList)
90+
{
91+
string localFileName = entry.FilenameInZip.Replace('/', Path.DirectorySeparatorChar);
92+
string destinationFile = Path.Combine(tempFileName, localFileName);
93+
extensionZipFile.ExtractFile(entry, destinationFile);
94+
}
9095
}
9196

9297
// Then, copy the contents of the temporarly location into the
@@ -103,7 +108,7 @@ public void Install(string profileDir)
103108

104109
// By deleting the staging directory, we also delete the temporarily
105110
// expanded extension, which we copied into the profile.
106-
Directory.Delete(stagingDirectoryName, true);
111+
FileUtilities.DeleteDirectory(stagingDirectoryName);
107112
}
108113

109114
private static string ReadIdFromInstallRdf(string root)

Diff for: dotnet/src/webdriver/Firefox/FirefoxProfile.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
using System.Text;
2424
using System.Xml;
2525
using System.Xml.XPath;
26-
using Ionic.Zip;
2726
using Newtonsoft.Json;
2827
using OpenQA.Selenium.Internal;
2928
using OpenQA.Selenium.Remote;
29+
using System.IO.Compression;
3030

3131
namespace OpenQA.Selenium.Firefox
3232
{
@@ -195,10 +195,15 @@ public static FirefoxProfile FromBase64String(string base64)
195195
byte[] zipContent = Convert.FromBase64String(base64);
196196
using (MemoryStream zipStream = new MemoryStream(zipContent))
197197
{
198-
using (ZipFile profileZipArchive = ZipFile.Read(zipStream))
198+
using (ZipStorer profileZipArchive = ZipStorer.Open(zipStream, FileAccess.Read))
199199
{
200-
profileZipArchive.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
201-
profileZipArchive.ExtractAll(destinationDirectory);
200+
List<ZipStorer.ZipFileEntry> entryList = profileZipArchive.ReadCentralDir();
201+
foreach (ZipStorer.ZipFileEntry entry in entryList)
202+
{
203+
string fileName = entry.FilenameInZip.Replace('/', Path.DirectorySeparatorChar);
204+
string destinationFile = Path.Combine(destinationDirectory, fileName);
205+
profileZipArchive.ExtractFile(entry, destinationFile);
206+
}
202207
}
203208
}
204209

@@ -333,15 +338,20 @@ public string ToBase64String()
333338
{
334339
string base64zip = string.Empty;
335340
this.WriteToDisk();
336-
using (ZipFile profileZipFile = new ZipFile())
341+
342+
using (MemoryStream profileMemoryStream = new MemoryStream())
337343
{
338-
profileZipFile.AddDirectory(this.profileDir);
339-
using (MemoryStream profileMemoryStream = new MemoryStream())
344+
using (ZipStorer profileZipArchive = ZipStorer.Create(profileMemoryStream, string.Empty))
340345
{
341-
profileZipFile.Save(profileMemoryStream);
342-
base64zip = Convert.ToBase64String(profileMemoryStream.ToArray());
346+
string[] files = Directory.GetFiles(this.profileDir, "*.*", SearchOption.AllDirectories);
347+
foreach (string file in files)
348+
{
349+
string fileNameInZip = file.Substring(this.profileDir.Length).Replace(Path.DirectorySeparatorChar, '/');
350+
profileZipArchive.AddFile(ZipStorer.Compression.Deflate, file, fileNameInZip, string.Empty);
351+
}
343352
}
344353

354+
base64zip = Convert.ToBase64String(profileMemoryStream.ToArray());
345355
this.Clean();
346356
}
347357

0 commit comments

Comments
 (0)