home *** CD-ROM | disk | FTP | other *** search
- Option Explicit
-
- ' Variable to communicate to the ExtractDialog form
-
- Global ExtractDialogCanceled As Integer
-
- ' Constants to determine characteristics of Zip Open Dialog
-
- Global Const OpenZip = 0
- Global Const NewZip = 1
- Global Const TestZip = 2
- Global Const FixZip = 3
- Global Const DeleteZip = 4
- Global Const SelectBin = 5
-
- ' Constants to determine command executed by ExecuteSelFilesCmd
-
- Global Const SF_Delete = 0
- Global Const SF_Extract = 1
-
- ' Function to send a windows message
-
- Declare Function SendMessage Lib "user" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, Lparam As Any) As Long
-
- ' Other constants for listboxes, dialog boxes and windows calls
-
- Global Const WM_USER = &H400
- Global Const LB_GETSELCOUNT = WM_USER + 17
- Global Const LB_GETCOUNT = WM_USER + 12
- Global Const LB_SELITEMRANGE = WM_USER + 28
- Global Const WM_SETREDRAW = &HB
- Global Const MB_ICONINFORMATION = 64
- Global Const MB_ICONSTOP = 16
- Global Const MB_ICONEXCLAMATION = 48
- Global Const MB_ICONQUESTION = 32
- Global Const MB_OKCANCEL = 1
- Global Const MB_YESNO = 4
- Global Const MB_YESNOCANCEL = 3
- Global Const MB_OK = 0
- Global Const ID_YES = 6
- Global Const ID_NO = 7
- Global Const ID_CANCEL = 2
- Global Const OFN_OVERWRITEPROMPT = &H2
- Global Const OFN_FILEMUSTEXIST = &H1000
- Global Const OFN_ALLOWMULTISELECT = &H200
- Global Const OFN_NOCHANGEDIR = &H8
- Global Const OFN_HIDEREADONLY = &H4
- Global Const FRM_MINIMIZED = 1
- Global Const FRM_MAXIMIZED = 2
-
- ' This function counts the number of files in the list of files
- ' of the type returned by the SelectFilesToProcess function.
- '
- Function CountFilesInList (ByVal FileList As String) As Integer
-
- Dim Count As Integer
- Dim Pos As Integer
-
- Count = 0
- For Pos = 1 To Len(FileList)
- If Mid$(FileList, Pos, 1) = " " Then Count = Count + 1
- Next Pos
-
- If Count = 0 Then Count = 1
-
- CountFilesInList = Count
-
- End Function
-
- ' Returns the number of items in a listbox (API call, fast)
- '
- Function GetCount (ListBox As Control) As Integer
-
- GetCount = SendMessage(ListBox.hWnd, LB_GETCOUNT, 0, 0)
-
- End Function
-
- ' This function takes a list of files of the type that is returned by
- ' the SelectFilesToProcess function, and returns a single file (with
- ' pathname).
- '
- Function GetFileFromList (ByVal FileList As String, FileNumber As Integer) As String
-
- Dim Pos As Integer
- Dim Count As Integer
- Dim FNStart As Integer
- Dim FNLen As Integer
- Dim Path As String
-
- If InStr(FileList, " ") = 0 Then
- GetFileFromList = FileList
- Else
- Count = 0
- Path = Left$(FileList, InStr(FileList, " ") - 1)
- If Right$(Path, 1) <> "\" Then Path = Path + "\"
- FileList = FileList + " "
- For Pos = 1 To Len(FileList)
- If Mid$(FileList, Pos, 1) = " " Then
- Count = Count + 1
- If Count = FileNumber Then FNStart = Pos + 1
- If Count = (FileNumber + 1) Then
- FNLen = Pos - FNStart
- Exit For
- End If
- End If
- Next Pos
- GetFileFromList = Path + Mid$(FileList, FNStart, FNLen)
- End If
-
- End Function
-
- ' Returns the number of selected items in a listbox. (API call, fast)
- '
- Function GetSelCount (ListBox As Control) As Integer
-
- GetSelCount = SendMessage(ListBox.hWnd, LB_GETSELCOUNT, 0, 0)
-
- End Function
-
- ' This is a generic error handling procedure for the Xceed Zip VBX.
- ' It opens a message box containing a brief description of an
- ' error that has occured when manipulating Zip files.
- '
- ' Pass the return code from any method (like CmdAdd, CmdExtract...)
- ' in the ErrorCode parameter, and one word describing the current
- ' operation in the DoingWhat parameter.
- '
- Sub HandleError (ErrorCode As Integer, DoingWhat As String)
-
- Dim EDesc As String ' Error description text
- Dim InfoOnly As Integer ' False=Error, True=Warning
-
- EDesc = "" ' If this stays empty, we will not show a MsgBox
- InfoOnly = False
-
- If ErrorCode <> XcdSuccess Then
-
- Select Case ErrorCode
-
- Case XcdWarningGeneral, XcdWarningNoZipFile, XcdErrorNothingToDo
- Rem Do not show a MsgBox for these codes
- Case XcdWarningFilesSkipped
- EDesc = "Some files were skipped while " + DoingWhat + "."
- InfoOnly = True
- Case XcdWarningEmptyZipFile
- EDesc = "The Zip file is empty."
- InfoOnly = True
- Case XcdErrorUserAbort
- EDesc = "The " + DoingWhat + " operation was aborted."
- InfoOnly = True
- Case XcdErrorNoZipFile
- EDesc = "Could not find the archive file."
- Case XcdErrorEOF, XcdErrorZipStruct
- EDesc = "The archive file is corrupted. Try using the Fix option on it."
- Case XcdErrorMemory
- EDesc = "Ran out of memory while " + DoingWhat + "."
- Case XcdErrorDiskFull
- If MainForm.MainXZ.MultidiskMode Then
- EDesc = "A full disk was inserted instead of an empty one."
- Else
- EDesc = "Disk full while " + DoingWhat + "."
- End If
- Case XcdErrorTestFailed
- EDesc = "Test failed - Errors in the archive."
- Case XcdErrorZeroTested
- EDesc = "No files ended up being tested in the archive."
- Case XcdErrorDLLNotFound
- EDesc = "The XCDZIP.DLL or the XCDUNZIP.DLL file could not be found."
- Case XcdErrorTempFile
- EDesc = "Problem with the temporary file."
- Case XcdErrorLatest
- EDesc = "Could not update the Zip archive date. Archive only contains directories or is empty."
- Case XcdErrorLibInUse
- EDesc = "Another application is currently performing a similar task. Wait until the other application has completed its operation."
- Case XcdErrorParentDir
- EDesc = "Attempt to remove parent directory."
- Case XcdErrorDosError
- EDesc = "Read/Write error with the Zip file or one of the files to process."
- Case XcdErrorNameRepeat
- EDesc = "Names repeated in archive after discarding pathnames."
- Case XcdErrorMultidisk
- EDesc = "Cannot work on multiple-disk archives when not in Multidisk mode."
- Case XcdErrorWrongDisk
- EDesc = "Wrong disk was inserted too many times."
- Case XcdErrorMultiDiskBadCall
- EDesc = "Operation not supported for Multidisk Zip archives."
- Case XcdErrorCantOpenBinary
- EDesc = "Could not open the self-extractor binary."
- Case XcdErrorCantOpenSFXConfig
- EDesc = "Could not open the self-extractor configuration file"
- Case XcdErrorInvalidEventParam
- EDesc = "Invalid command parameter passed to an Xceed Zip event."
- Case XcdErrorCantWriteSfx
- EDesc = "Not enough space on first disk to write self-extractor."
- Case XcdErrorRead
- EDesc = "Problem reading from file while " + DoingWhat + "."
- Case XcdErrorWrite
- EDesc = "Problem writing to file while " + DoingWhat + "."
- Case XcdErrorBinaryVersion
- EDesc = "Invalid self-extractor binary version."
- Case XcdErrorNotLicensed
- EDesc = "This application was created with an unlicensed copy of the Xceed Zip component. It will only run in design mode."
- Case XcdErrorCantCreateDir
- EDesc = "Problem creating destination directory while " + DoingWhat + "."
- Case XcdErrorBadCall ' Programming error in this application
- EDesc = "Invalid property settings. Programming error."
- Case Else
- EDesc = "An error occured while " + DoingWhat + " the specified files."
- End Select
-
- End If
-
- If Len(EDesc) > 0 Then
- If InfoOnly Then
- MsgBox EDesc, MB_ICONEXCLAMATION ' A warning
- Else
- MsgBox EDesc, MB_ICONSTOP ' An error
- End If
- End If
-
- End Sub
-
- ' This function opens a dialog and lets the user select multiple
- ' files to be operated on.
- '
- ' This function will return the full path and filename of each
- ' and every selected file, all concatenated in one big string.
- ' If the Cancel button was used, then the function will return
- ' an empty string.
- '
- Function SelectFilesToProcess (Title As String) As String
-
- MainForm.SelectFilesDialog.CancelError = False
- MainForm.SelectFilesDialog.Filename = ""
-
- MainForm.SelectFilesDialog.Flags = OFN_FILEMUSTEXIST + OFN_ALLOWMULTISELECT + OFN_NOCHANGEDIR + OFN_HIDEREADONLY
-
- MainForm.SelectFilesDialog.DialogTitle = Title
- MainForm.SelectFilesDialog.Action = 1
-
- If Len(MainForm.SelectFilesDialog.Filename) > 0 Then
- SelectFilesToProcess = MainForm.SelectFilesDialog.Filename
- End If
-
- End Function
-
- ' This function opens up a 'Open File' Dialog to have the
- ' user select a Zip file. Depending on the DialogType parameter,
- ' the behavior of the dialog is different.
- '
- ' This function will return the full path and filename of the
- ' selected Zip file. If the Cancel button was used, then the
- ' function will return an empty string.
- '
- Function SelectZipFile (DialogType As Integer) As String
-
- MainForm.SelectZipDialog.Filename = ""
- MainForm.SelectZipDialog.Flags = OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_HIDEREADONLY
- MainForm.SelectZipDialog.Filter = "Zip archives (*.zip)|*.zip|Self-extracting Zip archives (*.exe)|*.exe|All files (*.*)|*.*"
- Select Case DialogType
- Case OpenZip
- MainForm.SelectZipDialog.DialogTitle = "Open Archive"
- MainForm.SelectZipDialog.Action = 1
- Case NewZip
- MainForm.SelectZipDialog.Flags = OFN_OVERWRITEPROMPT + OFN_NOCHANGEDIR + OFN_HIDEREADONLY
- MainForm.SelectZipDialog.DialogTitle = "New Archive"
- MainForm.SelectZipDialog.Action = 2 ' Pretend we are saving file
- Case TestZip
- MainForm.SelectZipDialog.DialogTitle = "Test Archive"
- MainForm.SelectZipDialog.Action = 1
- Case FixZip
- MainForm.SelectZipDialog.DialogTitle = "Fix Archive"
- MainForm.SelectZipDialog.Action = 1
- Case DeleteZip
- MainForm.SelectZipDialog.DialogTitle = "Delete Archive"
- MainForm.SelectZipDialog.Action = 1
- Case SelectBin
- MainForm.SelectZipDialog.Filename = ""
- MainForm.SelectZipDialog.Filter = "Self-extractor binary (*.bin)|*.bin|All files (*.*)|*.*"
- MainForm.SelectZipDialog.DialogTitle = "Select self-extractor binary"
- MainForm.SelectZipDialog.Action = 1
- Case Else
- End Select
-
- SelectZipFile = MainForm.SelectZipDialog.Filename
-
- End Function
-
- ' Turn on/off screen updating of a listbox. This is necessary
- ' to increase the speed that items are added into a listbox
- ' because simply setting the listbox .Visible property to
- ' False is not enough.
- '
- Sub SetRedraw (ListBox As Control, RedrawState As Integer)
-
- Dim Void As Long
-
- ListBox.Visible = RedrawState
- Void = SendMessage(ListBox.hWnd, WM_SETREDRAW, RedrawState, 0&)
-
- End Sub
-
- ' This function takes a string containing a path and tries to make it
- ' fit into a given control's display space (i.e: Panel and label captions.)
- ' Note: It considers a '\' to indicate the presence of a path in the string.
- '
- Function ShortenPathForDisplay (aString As String, aForm As Form, aWidth As Single) As String
-
- Dim TempString As String
- Dim Pos As Long
- Dim Pos2 As Long
-
- TempString = aString
-
- While aForm.TextWidth(TempString) > aWidth
-
- Pos = InStr(1, TempString, "...")
- If Pos > 0 Then
- TempString = Left$(TempString, Pos - 1) + Right$(TempString, Len(TempString) - Pos - 3)
- End If
-
- Pos = InStr(3, TempString, "\")
- Pos2 = InStr(Pos + 1, TempString, "\")
-
- If Pos2 = 0 Then
- ShortenPathForDisplay = Left$(TempString, Pos) + "..." + Right$(TempString, Len(TempString) - Pos + 1)
- Exit Function
- End If
-
- TempString = Left$(TempString, Pos) + "..." + Right$(TempString, Len(TempString) - Pos2 + 1)
-
- Wend
- ShortenPathForDisplay = TempString
-
- End Function
-
-