Imports SevenZipLib
Public Class Form1
Private WithEvents archive As SevenZipArchive
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fileName As String = "C:\Users\heropa\Downloads\SevenZipLib_9.13.2.zip"
archive = New SevenZipArchive(fileName)
Try
Debug.Print("SevenZipArchive:FilesCount:{0}", archive.Count)
Debug.Print("SevenZipArchive:FileName:{0}", archive.FileName)
Debug.Print("SevenZipArchive:Format:{0}", archive.Format)
Debug.Print("SevenZipArchive:HasSubArchive:{0}", archive.HasSubArchive)
Debug.Print("SevenZipArchive:IsClosed:{0}", archive.IsClosed)
Debug.Print("SevenZipArchive:IsEncrypted:{0}", archive.IsEncrypted)
Debug.Print("SevenZipArchive:IsReadOnly:{0}", archive.IsReadOnly)
Debug.Print("SevenZipArchive:PackedSize:{0}", archive.PackedSize)
Debug.Print("SevenZipArchive:Password:{0}", archive.Password)
Debug.Print("SevenZipArchive:UnpackedSize:{0}", archive.UnPackedSize)
For Each aprop As ArchiveProperty In archive.Properties
Debug.Print("ArchiveProperty:{0}:{1}", aprop.PropertyName, aprop.Value)
Next
For Each entry As ArchiveEntry In archive
Debug.Print("ArchiveEntry:FileName:{0}", entry.FileName)
Debug.Print("ArchiveEntry:IsDirectory:{0}", entry.IsDirectory)
Debug.Print("ArchiveEntry:IsEncrypted:{0}", entry.IsEncrypted)
Debug.Print("ArchiveEntry:Size:{0}", entry.Size)
Debug.Print("ArchiveEntry:Attributes:{0}", ToStringFromFileAttributes(entry.Attributes))
Debug.Print("ArchiveEntry:Comment:{0}", entry.Comment)
Debug.Print("ArchiveEntry:Crc:{0}", entry.Crc)
Debug.Print("ArchiveEntry:CreationTime:{0}", entry.CreationTime)
Debug.Print("ArchiveEntry:LastWriteTime:{0}", entry.LastWriteTime)
Debug.Print("ArchiveEntry:LastAccessTime:{0}", entry.LastAccessTime)
Next
Catch ex As Exception
Finally
archive.Dispose()
End Try
End Sub
Private Function ToStringFromFileAttributes(ByVal attr As System.IO.FileAttributes?) As String
Dim result As New List(Of String)()
If (attr And IO.FileAttributes.Archive) = IO.FileAttributes.Archive Then result.Add("Archive")
If (attr And IO.FileAttributes.Compressed) = IO.FileAttributes.Compressed Then result.Add("Compressed")
If (attr And IO.FileAttributes.Device) = IO.FileAttributes.Device Then result.Add("Device")
If (attr And IO.FileAttributes.Directory) = IO.FileAttributes.Directory Then result.Add("Directory")
If (attr And IO.FileAttributes.Encrypted) = IO.FileAttributes.Encrypted Then result.Add("Encrypted")
If (attr And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then result.Add("Hidden")
If (attr And IO.FileAttributes.Normal) = IO.FileAttributes.Normal Then result.Add("Normal")
If (attr And IO.FileAttributes.NotContentIndexed) = IO.FileAttributes.NotContentIndexed Then result.Add("NotContentIndexed")
If (attr And IO.FileAttributes.Offline) = IO.FileAttributes.Offline Then result.Add("Offline")
If (attr And IO.FileAttributes.ReadOnly) = IO.FileAttributes.ReadOnly Then result.Add("ReadOnly")
If (attr And IO.FileAttributes.ReparsePoint) = IO.FileAttributes.ReparsePoint Then result.Add("ReparsePoint")
If (attr And IO.FileAttributes.SparseFile) = IO.FileAttributes.SparseFile Then result.Add("SparseFile")
If (attr And IO.FileAttributes.System) = IO.FileAttributes.System Then result.Add("System")
If (attr And IO.FileAttributes.Temporary) = IO.FileAttributes.Temporary Then result.Add("Temporary ")
Return String.Join(",", result.ToArray())
End Function
End Class
う〜ん...。Attributesがちゃんと取れない...。SevenZipSharpと同じ7-zipのDLLを呼んでいるようなので、SevenZipSharpのやり方が正しいんだろうな...。取得できる項目も、SevenZipSharpとほとんど変わらない。ソースを見ると、圧縮後のファイルサイズや、メソッド(Zipファイルなら、Deflateとかの文字列)も取れる。
SevenZipLib自体を修正して使うか?
それなら、ソースごとプロジェクトに取り込んでしまえば良いような気がするが、SevenZipLibはC#で書かれているので取り込めない。
ライセンスの問題もあるだろうし。(SevenZipLibは、LGPL)
0 件のコメント:
コメントを投稿