不要使用WriteEntryToDirectory保存文件,因为它不包含回调进度,而是使用FileStream然后获取未压缩文件的完整大小并切片保存进度好吗?
这是一个简单的例子:
thread = new Thread(
new ThreadStart(() =>
{
using (Archive = RarArchive.Open(streams, new ReaderOptions() { Password = password, LookForHeader = true }))
{
Archive.EntryExtractionBegin += EntryExtractionBeginEvet;
Archive.CompressedBytesRead += CompressedBytesReadEvent;
FilesTotalCount = Archive.Entries.Count();
TotalSize = Archive.TotalSize;
foreach (IArchiveEntry ArchiveEntry in Archive.Entries.Where(entry => !entry.IsDirectory))
{
Directory.CreateDirectory(Path.GetDirectoryName(@"" + path + "\\" + ArchiveEntry.Key));
using (Stream archiveStream = ArchiveEntry.OpenEntryStream())
using (FileStream fileStream = new FileStream(@"" + path + "\\" + ArchiveEntry.Key, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
int byteSizes = 0;
byte[] buffer = new byte[bufferLenght];
while (ThreadState == ThreadState.Running && (byteSizes = archiveStream.Read(buffer, 0, buffer.Length)) > 0)
fileStream.Write(buffer, 0, byteSizes);
}
}
}
IO.CloseStreams(streams);
}
));
thread.Start();