您的位置:首页 > 其它

处理sevenzipsharp 检查密码函数的Bug

2016-04-10 21:20 330 查看
using (SevenZipExtractor extr = new SevenZipExtractor(tbPackagePath.Text, "www.pc6.com"))
{

if (extr.Check())
{
MessageBox.Show("密码正确");
}
else
{
MessageBox.Show("密码不正确");
}
}


这一段是检查压缩包密码是否正确,发现360压缩的zip,不管正不正确,都返回true,

修改以下源码(ArchiveExtractCallback.cs),避免此错误

public void SetOperationResult(OperationResult operationResult)
{
if (operationResult != OperationResult.Ok && ReportErrors)
{
switch (operationResult)
{
case OperationResult.CrcError:
AddException(new ExtractionFailedException("File is corrupted. Crc check has failed."));
break;
case OperationResult.DataError:
AddException(new ExtractionFailedException("File is corrupted. Data error has occured."));
break;
case OperationResult.UnsupportedMethod:
AddException(new ExtractionFailedException("Unsupported method error has occured."));
break;
default:
AddException(new ExtractionFailedException("An unknown error."));
break;
}
}
else
{
if (_fileStream != null && !_fileIndex.HasValue)
{
try
{
_fileStream.BytesWritten -= IntEventArgsHandler;
_fileStream.Dispose();
}
catch (ObjectDisposedException) { }
_fileStream = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
var iea = new FileInfoEventArgs(
_extractor.ArchiveFileData[_currentIndex], PercentDoneEventArgs.ProducePercentDone(_doneRate));
OnFileExtractionFinished(iea);
if (iea.Cancel)
{
Canceled = true;
}
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: