lzh文件解压缩

lzh文件解压缩

 lzh文件解压缩,需要下载UNLHA32.DLL文件
下载地址:http://www2.nsknet.or.jp/~micco/micindex.html

执行例:   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

    
'取得DLL的版本
    <DllImport("unlha32")> _
    
Private Shared Function UnlhaGetVersion() As UInt16
    
End Function


    
'取得DLL的执行情况
    <DllImport("unlha32")> _
    
Private Shared Function UnlhaGetRunning() As Boolean
    
End Function


    
'文件检查
    <DllImport("unlha32")> _
    
Private Shared Function UnlhaCheckArchive( _
        
ByVal szFileName As String, _
        
ByVal iMode As IntegerAs Boolean
    
End Function


    
'文件解压缩
    <DllImport("unlha32")> _
    
Private Shared Function Unlha( _
        
ByVal hwnd As Integer, _
        
ByVal szCmdLine As String, _
        
ByVal szOutput As String, _
        
ByVal dwSize As IntegerAs Integer
    
End Function


    
Public Shared Sub UnCompress(ByVal archiveFile As StringByVal 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, 0Then
            
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), Nothing0)

        
'结果
        If ret <> 0 Then
            
If ret = 32800 Then
                
Throw New ApplicationException("文件解压缩取消")
            
Else
                
Throw New ApplicationException("文件解压缩异常结束")
            
End If
        
End If

    
End Sub


End Class

 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值