⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 7zip.au3

📁 7zip script for auto-compression
💻 AU3
📖 第 1 页 / 共 3 页
字号:
	If $sYes Then $iSwitch &= " -y"
	
	Local $tOutBuffer = DllStructCreate("char[32768]")
	
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZip", _
											 "hwnd", $hWnd, _
											 "str", "x " & $sArcName & " " & $iSwitch, _
											 "ptr", DllStructGetPtr($tOutBuffer), _
											 "int", DllStructGetSize($tOutBuffer))
	
	If Not $aRet[0] Then Return SetError(0, 0, DllStructGetData($tOutBuffer, 1))
	Return SetError(1, 0, 0)
EndFunc   ;==>_7ZIPExtractEx

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZIPUpdate
; Description ...: Update older files in the archive and add files that are new to the archive
; Syntax.........: _7ZIPUpdate($hWnd, $sArcName, $sFileName[, $sHide = 0[, $sCompress = 5[, $sRecurse = 1[, _
;				   			   $sIncludeFile = 0[, $sExcludeFile = 0[, $sPassword = 0[, $sSFX = 0[, $sWorkDir = 0]]]]]]]])
; Parameters ....: $hWnd         - Handle to parent or owner window
;				   $sArcName     - Archive file name
;				   $sFileName    - File names to archive up
;				   $sHide        - Use this switch if you want the CallBack function to be called
;				   $sCompress    - Compress level 0-9
;				   $sRecurse     - Recurse method: 0 - Disable recursion
;												   1 - Enable recursion
;												   2 - Enable recursion only for wildcard names
;				   $sIncludeFile - Include filenames, specifies filenames and wildcards or list file that specify processed files
;				   $sExcludeFile - Exclude filenames, specifies what filenames or (and) wildcards must be excluded from operation
;				   $sPassword    - Specifies password
;				   $sSFX         - Creates self extracting archive
;				   $sWorkDir     - Sets working directory for temporary base archive
; Return values .: Success       - Returns the string with results
;                  Failure       - Returns 0 and and sets the @error flag to 1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipUpdate($hWnd, $sArcName, $sFileName, $sHide = 0, $sCompress = 5, $sRecurse = 1, $sIncludeFile = 0, $sExcludeFile = 0, _
				 $sPassword = 0, $sSFX = 0, $sWorkDir = 0)
	
	$sArcName = '"' & $sArcName & '"'
	$sFileName = '"' & $sFileName & '"'
	
	Local $iSwitch = ""
	
	If $sHide Then $iSwitch &= " -hide"
	
	$iSwitch = " -mx" & $sCompress
	$iSwitch &= _RecursionSet($sRecurse)
	
	If $sIncludeFile Then $iSwitch &= _IncludeFileSet($sIncludeFile)
	If $sExcludeFile Then $iSwitch &= _ExcludeFileSet($sExcludeFile)
	
	If $sPassword Then $iSwitch &= " -p" & $sPassword
	If FileExists($sSFX) Then $iSwitch &= " -sfx" & $sSFX
	If $sWorkDir Then $iSwitch &= " -w" & $sWorkDir
	
	Local $tOutBuffer = DllStructCreate("char[32768]")
	
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZip", _
											 "hwnd", $hWnd, _
											 "str", "u " & $sArcName & " " & $sFileName & " " & $iSwitch, _
											 "ptr", DllStructGetPtr($tOutBuffer), _
											 "int", DllStructGetSize($tOutBuffer))
	
	If Not $aRet[0] Then Return SetError(0, 0, DllStructGetData($tOutBuffer, 1))
	Return SetError(1, 0, 0)
EndFunc   ;==>_7ZIPUpdate

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipSetOwnerWindowEx
; Description ...: Appoints the call-back function in order to receive the information of the compressing/unpacking
; Syntax.........: _7ZipSetOwnerWindowEx($hWnd, $sProcFunc)
; Parameters ....: $hWnd      - Handle to parent or owner window
;				   $sProcFunc - The call-back function name
; Return values .: Success  - Returns 1
;                  Failure  - Returns 0
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipSetOwnerWindowEx($hWnd, $sProcFunc)
	If $hArchiveProc Then DllCallbackFree($hArchiveProc)
	$hArchiveProc = DllCallbackRegister($sProcFunc, "int", "hwnd;uint;uint;ptr")
	If $hArchiveProc = 0 Then Return SetError(1, 0, 0)
	
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipSetOwnerWindowEx", _
											 "hwnd", $hWnd, _
											 "ptr", DllCallbackGetPtr($hArchiveProc))
	Return $aRet[0]
EndFunc   ;==>_7ZipSetOwnerWindowEx

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipKillOwnerWindowEx
; Description ...: Cancels a window owner
; Syntax.........: _7ZipKillOwnerWindowEx($hWnd)
; Parameters ....: $hWnd      - Handle to parent or owner window
; Return values .: Success  - Returns 1
;                  Failure  - Returns 0
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipKillOwnerWindowEx($hWnd)
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipKillOwnerWindowEx", _
											 "hwnd", $hWnd)
	Return $aRet[0]
EndFunc   ;==>_7ZipKillOwnerWindowEx

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipOpenArchive
; Description ...: Opens a arcive file
; Syntax.........: _7ZipOpenArchive($sArcName)
; Parameters ....: hWnd      - Handle to parent or owner window
;				   $sArcName - Archive file name
; Return values .: Success   - Returns a archive handle
;                  Failure   - Returns 0
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipOpenArchive($hWnd, $sArcName)
	Local $hArc = DllCall($hDLL_7ZIP, "hwnd", "SevenZipOpenArchive", "hwnd", $hWnd, "str", $sArcName, "int", 0)
	Return $hArc[0]
EndFunc   ;==>_7ZipOpenArchive

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipCloseArchive
; Description ...: Closes a previously opened archive handle
; Syntax.........: _7ZipCloseArchive($hArc)
; Parameters ....: $hArc - Archive handle
; Return values .: Success   - Returns 0
;                  Failure   - Returns -1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipCloseArchive($hArc)
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipCloseArchive", "hwnd", $hArc)
	Return $aRet[0]
EndFunc   ;==>_7ZipCloseArchive

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipFindFirst
; Description ...: Returns a $INDIVIDUALINFO structure with information of the first finded file
; Syntax.........: _7ZipFindFirst($hArc, $sSearch)
; Parameters ....: $hArc    - Archive handle
;				   $sSearch - File search string. (wildcards are supported)
; Return values .: Success  - Returns a $INDIVIDUALINFO structure
;                  Failure  - Returns -1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipFindFirst($hArc, $sSearch)
	Local $INDIVIDUALINFO = DllStructCreate($tagINDIVIDUALINFO)
	
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipFindFirst", _
											 "hwnd", $hArc, _
											 "str", $sSearch, _
											 "ptr", DllStructGetPtr($INDIVIDUALINFO))
	If $aRet[0] = -1 Then Return $aRet[0]
	Return $INDIVIDUALINFO
EndFunc   ;==>_7ZipFindFirst

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipFindNext
; Description ...: Returns a $tINDIVIDUALINFO structure according to a previous call to _7ZipFindFirst
; Syntax.........: _7ZipFindNext($hArc, $tINDIVIDUALINFO)
; Parameters ....: $hArc            - Archive handle
;				   $tINDIVIDUALINFO - The $tINDIVIDUALINFO structure
; Return values .: Success  - Returns a $INDIVIDUALINFO structure
;                  Failure  - Returns 0
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipFindNext($hArc, $tINDIVIDUALINFO)
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipFindNext", _
											 "hwnd", $hArc, _
											 "ptr", DllStructGetPtr($tINDIVIDUALINFO))
	If $aRet[0] = 0 Then Return $tINDIVIDUALINFO
EndFunc   ;==>SevenZipFindNext

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipGetFileName
; Description ...: Returns a file name
; Syntax.........: _7ZipGetFileName($hArc)
; Parameters ....: $hArc - Archive handle
; Return values .: Success - Returns a string with a file name
;                  Failure - Returns 0
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipGetFileName($hArc)
	Local $tNameBuffer = DllStructCreate("char[" & $FNAME_MAX32 + 1 & "]")
	
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipGetFileName", _
											 "hwnd", $hArc, _
											 "ptr", DllStructGetPtr($tNameBuffer), _
											 "int", DllStructGetSize($tNameBuffer))
	If $aRet[0] = 0 Then Return DllStructGetData($tNameBuffer, 1)
EndFunc   ;==>_7ZipGetFileName

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipGetArcOriginalSize
; Description ...: Returns a original size of files in an archive
; Syntax.........: _7ZipGetArcOriginalSize($hArc)
; Parameters ....: $hArc - Archive handle
; Return values .: Success - Returns a total size
;                  Failure - Returns -1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipGetArcOriginalSize($hArc)
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipGetArcOriginalSize", _
											 "hwnd", $hArc)
	Return $aRet[0]
EndFunc   ;==>_7ZipGetArcOriginalSize

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipGetArcCompressedSize
; Description ...: Returns a compressed size of files in an archive
; Syntax.........: _7ZipGetArcCompressedSize($hArc)
; Parameters ....: $hArc - Archive handle
; Return values .: Success - Returns a total size
;                  Failure - Returns -1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipGetArcCompressedSize($hArc)
	Local $aRet = DllCall($hDLL_7ZIP, "int", "SevenZipGetArcCompressedSize", _
											 "hwnd", $hArc)
	Return $aRet[0]
EndFunc   ;==>_7ZipGetArcCompressedSize

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipGetArcRatio
; Description ...: Returns a compressing ratio
; Syntax.........: _7ZipGetArcRatio($hArc)
; Parameters ....: $hArc - Archive handle
; Return values .: Success - Returns a compressing ratio
;                  Failure - Returns -1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipGetArcRatio($hArc)
	Local $aRet = DllCall($hDLL_7ZIP, "short", "SevenZipGetArcRatio", _
											 "hwnd", $hArc)
	Return $aRet[0]
EndFunc   ;==>_7ZipGetArcRatio

; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipGetDate
; Description ...: Returns a date of files in an archive
; Syntax.........: _7ZipGetDate($hArc)
; Parameters ....: $hArc - Archive handle
; Return values .: Success - Returns a date in an MSDOS format
;                  Failure - Returns -1
; Author ........: R. Gilman (rasim)
; ===============================================================================================================================
Func _7ZipGetDate($hArc)
	Local $aRet = DllCall($hDLL_7ZIP, "short", "SevenZipGetDate", _
												"hwnd", $hArc)
	If $aRet[0] = -1 Then Return $aRet[0]
	Return "0x" & Hex($aRet[0], 4)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -