如何在 C# 中使用 SevenZipSharp/Unrar 知道哪个 rar 是多个 rar 存档中的第一个?
我正在尝试在 C# WinForms .NET 3.5 中使用 SevenZipSharp 或/和 Unrar 库。我遇到了具有不同命名的多个 rar 存档的问题,例如:
- .rar、r01、r02、r03 等(这很简单)
somefile01.rar、somefile02.rar、somefile03.rar
.001、.002、003 等。
如果我将 Unrar 或 SevenZipSharp 指向错误的存档,它将解压该特定存档并保留其余部分未解压。所以我必须指出正确的(除非我做错了什么)。
检查这一点的最佳方法是什么?现在我正在检查目录中是否有多个 .rar 文件,如果有,我检查 01.rar。如果只有一个 .rar 和几个 r01 那么我得到 .rar 但这似乎有点错误。
有没有办法让 SevenZip 或 Unrar 通过指向任何 .rar 文件来实际解压整个多 rar 包?或.001?
MadBoy
编辑:
我尝试使用以下代码来获取一个答案中建议的信息,但它无法提供承诺的信息。 extr.ArchiveFileData 对于 zip 返回 0,对于任何提供的 rar(无论是 rar 还是 r01)返回 32。
using (SevenZipExtractor extr = new SevenZipExtractor(fileName)) {
foreach (var var in extr.ArchiveProperties) {
string attributes = var.Name;
object test = var.Value;
if (test == null) {
test = "THIS";
}
MessageBox.Show(attributes.ToString(), test.ToString());
}
foreach (var var in extr.ArchiveFileData) {
MessageBox.Show(var.Attributes.ToString());
}
}
I am trying to use SevenZipSharp or/and Unrar library in C# WinForms .NET 3.5. I have this problem with multi rar archives that have diffrent naming for example:
- .rar, r01, r02, r03 and so on (this is easy)
somefile01.rar, somefile02.rar, somefile03.rar
.001, .002, 003 and so on.
If i point Unrar or SevenZipSharp to wrong archive it will unpack that particular archive and leave rest unpacked. So i have to point the right one (unless i am doing something wrong).
What would be the best way to check for that? For now i am checking if there are more then one .rar files inside directory then if so i check for 01.rar. If there's only one and .rar and couple of r01 then i get .rar but this seems a bit wrong.
Is there a way to make SevenZip or Unrar to actually unpack whole multi rar pack just by pointing to any .rar file? or .001 ?
MadBoy
EDIT:
I tried to use following code to get information as suggested in one answer but it fails to deliver promised information. extr.ArchiveFileData returns 0 for zip, and 32 for any provided rar whether it's rar or r01.
using (SevenZipExtractor extr = new SevenZipExtractor(fileName)) {
foreach (var var in extr.ArchiveProperties) {
string attributes = var.Name;
object test = var.Value;
if (test == null) {
test = "THIS";
}
MessageBox.Show(attributes.ToString(), test.ToString());
}
foreach (var var in extr.ArchiveFileData) {
MessageBox.Show(var.Attributes.ToString());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您可以使用
SevenZipExtractor.ArchiveFileData
属性,然后迭代标头数据以查找相关信息。RAR 标头结构的一部分:
编辑:
当我下载 SevenZipSharp(1 小时前)时,发现
SevenZipExtractor
类包含一个列出卷中每个文件的属性 (VolumeFileNames )。我想‘太棒了!那很容易!”,嗯……从来没有那么容易。看来
VolumeFileNames
工作得很好,但前提是你将它指向卷中的第一个 rar :(wokraround :
我创建了一个方法来猜测和验证第一个卷:
它快速且肮脏,但有效您可以根据您的需要进一步完善它,
我希望这会有所帮助。
I believe that you could use
SevenZipExtractor.ArchiveFileData
property and then iterate through header data to find the relevant information.Part of the RAR header structure :
Edit :
When I downloaded SevenZipSharp(1 hour ago) and found that
SevenZipExtractor
class contains a property that lists every file in volume (VolumeFileNames
). I thought 'Great! That was easy!', well... it's never that easy. It seems thatVolumeFileNames
works perfectly but only if you point it to the first rar in volume :(The wokraround :
I've created a method to guess and verify the first volume :
It's quick&dirty but works and you can refine it further according to your needs.
I hope this helps.
使用 SharpCompress
Using SharpCompress