ZipForge 和无效档案
我有 ZipForge for Delphi XE2 &德尔福XE2。
我尝试测试任何无效的 zip 存档(例如未完全下载),就像在他们的演示中一样:
procedure TfmMain.bnStartClick(Sender: TObject);
begin
with Archiver do
begin
FileName := 'c:\2.zip';
OpenArchive;
try
TestFiles('*.*');
except
MessageDlg('Errors occurred in the archive file', mtError, [mbOk], 0);
end;
CloseArchive;
end;
end;
但是我的异常没有触发; ZipForge 的对话框代替我的对话框被触发。
我尝试了 Abbrevia 组件 但它甚至无法识别存档是否无效...
请帮助我使我的例外工作(不是 ZipForge 的例外)或建议我一个更好的具有测试功能的 zip 文件组件。谢谢!
I have ZipForge for Delphi XE2 & Delphi XE2.
I try to test any invalid zip archives (e.g. not fully downloaded) like in their demo:
procedure TfmMain.bnStartClick(Sender: TObject);
begin
with Archiver do
begin
FileName := 'c:\2.zip';
OpenArchive;
try
TestFiles('*.*');
except
MessageDlg('Errors occurred in the archive file', mtError, [mbOk], 0);
end;
CloseArchive;
end;
end;
But my exception doesn't fire; ZipForge's dialog fires instead of mine.
I tried Abbrevia Component but it even can't recognize if an archive is invalid...
Please help me to make my exception working (not ZipForge's one) or suggest me a better component for zip files with a test feature. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,您可以修改 ZIP 文件,例如通过稍微截断它们,ZIP 文件仍然有效。在我的测试文件中,我删除了最后 5000 字节,结果报告为有效。我使用 ZIP 程序成功提取了它。当然,提取的内容是错误的,不是原始内容。也许这就是发生在你身上的事情。也许您尝试损坏 ZIP 文件实际上并没有将其变成无效的 ZIP 文件。
Delphi XE2 附带了一个内置的 ZIP 组件,该组件在我的简单测试中运行良好,并在我截断文件足以使其真正损坏后成功检测到无效文件。
我使用
IsValid
方法检查有效性。这是我非常简单的测试程序。Be aware that you can modify ZIP files, e.g. by truncating them somewhat, the ZIP file will still be valid. With my test file, I removed the final 5000 bytes and it was reported as valid. I extracted it successfully using my ZIP program. Of course the extracted contents were incorrect and not the original contents. Perhaps this is what was happening for you. Maybe your attempts to corrupt your ZIP file were not in fact making it into an invalid ZIP file.
Delphi XE2 comes with a built in ZIP component that worked well in my simple test and successfully detected an invalid file, once I had truncated the file enough to make it truly corrupt.
I used the
IsValid
method to check validity. Here is my very simple test program.如果您的 ZIP 文件无效,则对
OpenArchive
的调用很可能会失败。只要您的执行处理不涵盖这种情况,您就会得到您所描述的结果。更新:在
TestFiles
或任何其他方法期间捕获异常的建议方法是连接OnProcessFileFailure
事件处理程序。If you have an invalid ZIP file, it is most likely that the call to
OpenArchive
will fail. As long as your execption handling doesn't cover that case, you will get the result you describe.Update: The suggested way to catch exceptions during
TestFiles
or any other method is to connect anOnProcessFileFailure
event handler.