lzh文件解压缩
执行例: Common.LhaUtils.UnCompress("d:/test.lzh", "d:/out/")
Imports
System.Runtime.InteropServices
'
'' <summary>
'
'' LZH文件解压缩
'
'' 需要UNLHA32.DLL文件
'
'' 下载地址:http://www2.nsknet.or.jp/~micco/micindex.html
'
'' </summary>
'
'' <remarks></remarks>

Public
Class LhaUtils
Class LhaUtils
'取得DLL的版本
<DllImport("unlha32")> _
Private Shared Function UnlhaGetVersion()Function UnlhaGetVersion() As UInt16
End Function
'取得DLL的执行情况
<DllImport("unlha32")> _
Private Shared Function UnlhaGetRunning()Function UnlhaGetRunning() As Boolean
End Function
'文件检查
<DllImport("unlha32")> _
Private Shared Function UnlhaCheckArchive()Function UnlhaCheckArchive( _
ByVal szFileName As String, _
ByVal iMode As Integer) As Boolean
End Function
'文件解压缩
<DllImport("unlha32")> _
Private Shared Function Unlha()Function Unlha( _
ByVal hwnd As Integer, _
ByVal szCmdLine As String, _
ByVal szOutput As String, _
ByVal dwSize As Integer) As Integer
End Function

Public Shared Sub UnCompress()Sub UnCompress(ByVal archiveFile As String, ByVal extractDir As String)
'文件检查
If Not System.IO.File.Exists(archiveFile) Then
Throw New ApplicationException("文件不存在")
End If
'DLL检查
Try
Dim ver As UInt16 = UnlhaGetVersion()
'Console.WriteLine("版本:{0}", ver)
Catch
Throw New ApplicationException("没找到Unlha32.dll文件")
End Try
'执行检查
If UnlhaGetRunning() Then
Throw New ApplicationException("DLL正在执行")
End If
'解压缩检查
If Not UnlhaCheckArchive(archiveFile, 0) Then
Throw New ApplicationException("文件不能被解压缩")
End If
'文件名和文件夹名
If archiveFile.IndexOf(" "c) > 0 Then
archiveFile = """" + archiveFile + """"
End If
If Not extractDir.EndsWith("") Then
extractDir += ""
End If
If extractDir.IndexOf(" "c) > 0 Then
extractDir = """" + extractDir + """"
End If
'解压缩
Dim ret As Integer = Unlha(0, _
String.Format("x {0} {1} *", archiveFile, extractDir), Nothing, 0)
'结果
If ret <> 0 Then
If ret = 32800 Then
Throw New ApplicationException("文件解压缩取消")
Else
Throw New ApplicationException("文件解压缩异常结束")
End If
End If
End Sub
End Class

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/122310.html