VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cPack"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" _
   Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
   ByVal lpszShortPath As String, ByVal cchBuffer As Long) _
   As Long

Public Sub ZipDir(sDirectory As String, sPacketName As String)
  
  If Right(sDirectory, 1) <> "\" Then sDirectory = sDirectory & "\"
  Dim x As String
  Dim y As String
  sDirectory = GetShortFileName(sDirectory)
  x = GetShortFileName(App.Path & "\rar.exe")
  y = GetShortFileName(App.Path & "\")
  ShellExecute 0, "open", x, " a -df " & y & sPacketName & ".rar" & " " & sDirectory & "*.*", "", 0
  'Debug.Print Chr(34) & App.Path & "\rar.exe" & Chr(34) & " a " & sPacketName & ".rar " & sDirectory & "*.*"
End Sub

Public Sub UnZipDir(sFile As String)
    Dim x As String
    Dim y As String
    x = GetShortFileName(App.Path & "\rar.exe")
    y = GetShortFileName(App.Path & "\")
    
    ShellExecute 0, "open", x, "x -y " & y & sFile & ".rar" & " " & y, "", 0
    Debug.Print Chr(34) & App.Path & "\rar.exe" & Chr(34) & " x " & Chr(34) & App.Path & "\" & sPacketName & ".rar " & Chr(34) & " " & sFile & "\"
End Sub

Private Function GetShortFileName(ByVal FullPath As String) As String
Dim lAns As Long
Dim sAns As String
Dim iLen As Integer
   
On Error Resume Next


    If Dir(FullPath) = "" Then Exit Function

    sAns = Space(255)
    lAns = GetShortPathName(FullPath, sAns, 255)
    GetShortFileName = Left(sAns, lAns)
    
End Function

