#cs
------------------------------------------
 Functions for use with 7-zip32.dll
 Version 0.4.1
 Copyright (C) 2006 JAK-Software.org. Released under GNU LGPL.

 Please Note:	To use the functions, the 7-zip32.dll file must be in the path. If you saved it into a subfolder use SetEnv and GetEnv

 Changes:
 0.4.1:	- Replaced last parameter: "str", 0 ==> "int", 0

 0.4:	- Added Hwnd Argument
	- Modified Variable Names
	- Added SetError(1) and Return 0 for Errors

 0.3:	- Removed @ScriptDir in DllOpen
------------------------------------------
#ce
;===============================================================================
;
; Description:      Adds Files to an Archive/Creates an Archiv
; Parameter(s):     $sArchive    - The Archive to use
;                   $sOutDir    - Where to extract the files
;                   $sFilter    - Files to extract from the Archive (e.g. *.exe)
;                   $sCMDLine   - Optional Options
;                   $hWnd       - The Window
; Requirement(s):   None
; Return Value(s):  On Success - Return 1
;                   On Failure - Return 0
; Author(s):        JAK-Software.org
; Note(s):          Need 7-zip32.dll in the path
;
;===============================================================================
Func _SevenZipAdd($sArchive, $sFiles, $iLevel = 6, $sType = "7z", $sCMDLine = "", $hWnd = 0)
	$dll = DllOpen("7-zip32.dll")
	$result = DllCall($dll, "int", "SevenZip", "hwnd", $hWnd, "str", 'a ' & $sCMDLine & '  -mx' & $iLevel & ' -t' & $sType & ' ' & $sArchive & ' ' & $sFiles, "int", 0)
	$error = @error
	DllClose($dll)
	If $error Then
		Return 0
	Else
		Return 1
	EndIf
EndFunc   ;==>_SevenZipAdd
;===============================================================================
;
; Description:      Executes 7-zip Commands (Syntax Like in 7z.exe/7za.exe)
; Parameter(s):     $sCMDLine   - The Commandline
;                   $hWnd       - The Window
; Requirement(s):   None
; Return Value(s):  On Success - Return 1
;                   On Failure - Return 0
; Author(s):        JAK-Software.org
; Note(s):          Needs 7-zip32.dll in the path
;
;===============================================================================
Func _SevenZipCMD($sCMDLine, $hWnd = 0)
	$dll = DllOpen("7-zip32.dll")
	DllCall($dll, "int", "SevenZip", "hwnd", $hWnd, "str", $sCMDLine, "int", 0)
	$error = @error
	DllClose($dll)
	If $error Then
		Return 0
	Else
		Return 1
	EndIf
EndFunc   ;==>_SevenZipCMD
;===============================================================================
;
; Description:      Extracts files from an archive
; Parameter(s):     $sArchive    - The Archive to use
;                   $sOutDir    - Where to extract the files
;                   $sFilter    - Files to extract from the Archive (e.g. *.exe)
;                   $sCMDLine   - Optional Options
;                   $hWnd       - The Window
; Requirement(s):   None
; Return Value(s):  On Success - Return 1
;                   On Failure - Return 0
; Author(s):        JAK-Software.org
; Note(s):          Needs 7-zip32.dll in the path
;
;===============================================================================
Func _SevenZipExtract($sArchive, $sOutDir = ".", $sFilter = '*', $sCMDLine = '', $hWnd = 0)
	$dll = DllOpen("7-zip32.dll")
	DllCall($dll, "int", "SevenZip", "hwnd", $hWnd, "str", 'x ' & $sCMDLine & ' -o' & $sOutDir & ' ' & $sArchive & ' ' & $sFilter, "int", 0)
	$error = @error
	DllClose($dll)
	If $error Then
		Return 0
	Else
		Return 1
	EndIf
EndFunc   ;==>_SevenZipExtract
