private void _backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
//nb: we want exceptions to be uncaught, to be transferred up to the worker completed event
_folderName = GetRootFolderName();
if (_folderName == null)
return;
// ZipFile internally converts all \ separators to / (at least on Linux). So using
// ZipFile instead of FastZip fixes https://jira.sil.org/browse/BL-1213.
ZipFile zip = null;
try
{
zip = new ZipFile(_path);
byte[] buffer = new byte[4096]; // 4K is optimum
foreach (ZipEntry entry in zip)
{
var fullOutputPath = Path.Combine(ProjectContext.GetInstalledCollectionsDirectory(), entry.Name);
if (entry.IsDirectory)
{
Directory.CreateDirectory(fullOutputPath);
// In the SharpZipLib code, IsFile and IsDirectory are not defined exactly as inverse: a third
// (or fourth) type of entry might be possible. In practice in BloomPacks, this should not be
// an issue.
continue;
}
var directoryName = Path.GetDirectoryName(fullOutputPath);
if (!String.IsNullOrEmpty(directoryName))
Directory.CreateDirectory(directoryName);
using (var instream = zip.GetInputStream(entry))
using (var writer = RobustFile.Create(fullOutputPath))
{
ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(instream, writer, buffer);
}
}
}
catch (Exception ex)
{
// Report a corrupt file instead of crashing. See http://issues.bloomlibrary.org/youtrack/issue/BL-2485.
if (InvokeRequired)
Invoke(new ReportBadBloomPack(ReportErrorUnzippingBloomPack));
else
ReportErrorUnzippingBloomPack();
return;
}
finally
{
if (zip != null)
zip.Close();
}
var newlyAddedFolderOfThePack = Path.Combine(ProjectContext.GetInstalledCollectionsDirectory(), _folderName);
CopyXMatterFoldersToWhereTheyBelong(newlyAddedFolderOfThePack);
ToolboxView.CopyToolSettingsForBloomPack(newlyAddedFolderOfThePack);
}