mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
reorganizing a bit
This commit is contained in:
61
CUETools.Compression.Zip/ZipCompressionProvider.cs
Normal file
61
CUETools.Compression.Zip/ZipCompressionProvider.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using CUETools.Compression;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
|
||||
namespace CUETools.Compression.Zip
|
||||
{
|
||||
[CompressionProviderClass("zip")]
|
||||
public class ZipCompressionProvider : ICompressionProvider
|
||||
{
|
||||
private ZipFile _zipFile;
|
||||
|
||||
public ZipCompressionProvider(string path)
|
||||
{
|
||||
_zipFile = new ZipFile(path);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (_zipFile != null) _zipFile.Close();
|
||||
_zipFile = null;
|
||||
}
|
||||
|
||||
~ZipCompressionProvider()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
public Stream Decompress(string file)
|
||||
{
|
||||
ZipEntry zipEntry = _zipFile.GetEntry(file);
|
||||
if (zipEntry == null)
|
||||
throw new Exception("Archive entry not found.");
|
||||
//if (zipEntry.IsCrypted && PasswordRequired != null)
|
||||
//{
|
||||
// CompressionPasswordRequiredEventArgs e = new CompressionPasswordRequiredEventArgs();
|
||||
// PasswordRequired(this, e);
|
||||
// if (e.ContinueOperation && e.Password.Length > 0)
|
||||
// _zipFile.Password = e.Password;
|
||||
//}
|
||||
SeekableZipStream stream = new SeekableZipStream(_zipFile, zipEntry);
|
||||
stream.PasswordRequired += PasswordRequired;
|
||||
stream.ExtractionProgress += ExtractionProgress;
|
||||
return stream;
|
||||
}
|
||||
|
||||
public IEnumerable<string> Contents
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (ZipEntry e in _zipFile)
|
||||
if (e.IsFile)
|
||||
yield return (e.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<CompressionPasswordRequiredEventArgs> PasswordRequired;
|
||||
public event EventHandler<CompressionExtractionProgressEventArgs> ExtractionProgress;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user