private void ExtractFile() { ArchiveIterator iterator = null; try { using (Stream stream = new FileStream(outFileName, FileMode.Open, FileAccess.Read)) { iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Zip, stream); DotNetZipZipIterator zipIterator = iterator as DotNetZipZipIterator; if (zipIterator != null) { zipIterator.CurrentFileExtractProgressChanged += archiveIterator_CurrentFileExtractProgressChanged; } while (iterator.HasNext()) { if (Path.GetExtension(iterator.CurrentFileName()) == ".xsupdate") { string path = Path.Combine(Path.GetDirectoryName(outFileName), iterator.CurrentFileName()); using (Stream outputStream = new FileStream(path, FileMode.Create)) { iterator.ExtractCurrentFile(outputStream); PatchPath = path; break; } } } if (zipIterator != null) { zipIterator.CurrentFileExtractProgressChanged -= archiveIterator_CurrentFileExtractProgressChanged; } } } catch (Exception e) { log.ErrorFormat("Exception occurred when extracting downloaded archive: {0}", e.Message); throw new Exception(Messages.DOWNLOAD_AND_EXTRACT_ACTION_EXTRACTING_ERROR); } finally { if (iterator != null) { iterator.Dispose(); } File.Delete(outFileName); } if (string.IsNullOrEmpty(PatchPath)) { MarkCompleted(new Exception(Messages.DOWNLOAD_AND_EXTRACT_ACTION_FILE_NOT_FOUND)); log.DebugFormat("File '{0}{1}' could not be located in downloaded archive", updateName, ".xsupdate"); } }
private void ExtractFile() { ArchiveIterator iterator = null; try { using (Stream stream = new FileStream(outputFileName, FileMode.Open, FileAccess.Read)) { iterator = ArchiveFactory.Reader(ArchiveFactory.Type.Zip, stream); DotNetZipZipIterator zipIterator = iterator as DotNetZipZipIterator; if (zipIterator != null) { zipIterator.CurrentFileExtractProgressChanged += archiveIterator_CurrentFileExtractProgressChanged; } while (iterator.HasNext()) { string currentExtension = Path.GetExtension(iterator.CurrentFileName()); if (updateFileSuffixes.Any(item => item == currentExtension)) { string path = downloadUpdate ? Path.Combine(Path.GetDirectoryName(outputFileName), iterator.CurrentFileName()) : Path.Combine(Path.GetTempPath(), iterator.CurrentFileName()); log.InfoFormat( "Found '{0}' in the downloaded archive when looking for a '{1}' file. Extracting...", iterator.CurrentFileName(), currentExtension); using (Stream outputStream = new FileStream(path, FileMode.Create)) { iterator.ExtractCurrentFile(outputStream); PatchPath = path; log.InfoFormat("Update file extracted to '{0}'", path); break; } } } if (zipIterator != null) { zipIterator.CurrentFileExtractProgressChanged -= archiveIterator_CurrentFileExtractProgressChanged; } } } catch (Exception e) { log.ErrorFormat("Exception occurred when extracting downloaded archive: {0}", e.Message); throw new Exception(Messages.DOWNLOAD_AND_EXTRACT_ACTION_EXTRACTING_ERROR); } finally { if (iterator != null) { iterator.Dispose(); } if (downloadUpdate) { try { File.Delete(outputFileName); } catch { } } } if (string.IsNullOrEmpty(PatchPath) && downloadUpdate) { MarkCompleted(new Exception(Messages.DOWNLOAD_AND_EXTRACT_ACTION_FILE_NOT_FOUND)); log.InfoFormat( "The downloaded archive does not contain a file with any of the following extensions: {0}", string.Join(", ", updateFileSuffixes)); } }