Jump to content

7-Zip ProgressBar Ex:(ProcessWaitClose/StdoutRead)


 Share

Recommended Posts

I try to add a progress bar.. ==> failing! 😔

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>

#Region ### START Koda GUI section ### Form=
$FormName = "7-Zip Compressore"
$Form1 = GUICreate($FormName, 550, 275, -1, -1)
$Inp = GUICtrlCreateInput("", 8, 8, 465, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Out = GUICtrlCreateInput("", 8, 40, 465, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Pass = GUICtrlCreateInput("", 40, 72, 433, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
$BtnBrowse = GUICtrlCreateButton("B", 480, 6, 25, 25, $BS_ICON)
$BtnBrowseFile = GUICtrlCreateButton("F", 515, 6, 25, 25, $BS_ICON)
$BtnSave = GUICtrlCreateButton("S", 480, 38, 25, 25, $BS_ICON)
$BtnCompress = GUICtrlCreateButton("OK", 480, 70, 25, 25, $BS_ICON)
$BtnCancPass = GUICtrlCreateButton("X", 8, 70, 25, 25, $BS_ICON)
$Group1 = GUICtrlCreateGroup("Sets level of compression", 8, 120, 257, 145)
$Slider = GUICtrlCreateSlider(20, 146, 230, 25)
GUICtrlSetLimit(-1, 5)
GUICtrlSetData($Slider, '0')
$CompLabel = GUICtrlCreateLabel("Ultra", 31, 182, 116, 15)
$LabelSize = GUICtrlCreateLabel("", 31, 226, 200, 29)
$progressbar = GUICtrlCreateProgress(8, 100, 465, 14)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$sFileName = @ScriptDir &"\pass.txt"
$hFilehandle = FileOpen($sFileName, $FO_OVERWRITE)
Local $7zDir = '"' & @ScriptDir & '\Bin\7z.exe"'
Local $sFileVersion = FileGetVersion (@ScriptDir & "\Bin\7z.exe",$FV_FILEVERSION)
Local $progressbar,$cmd

$SliderCorrente = 5
    
While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $BtnBrowse
        $sSelectFolder = FileSelectFolder("Select Folder", "")      
        If @error Then continueloop
        GUICtrlSetData($Inp, $sSelectFolder)
        $iSize = DirGetSize($sSelectFolder) 
        GUICtrlSetData($LabelSize,"Dim: " & _GetDisplaySize($iSize))
        
        Case $BtnBrowseFile
        $sFileOpenDialog = FileOpenDialog("Select files", @DesktopDir , "All (*.*)", $FD_FILEMUSTEXIST)
        If @error Then continueloop
        GUICtrlSetData($Inp, $sFileOpenDialog)
        $iSize =  FileGetSize($sFileOpenDialog) 
        GUICtrlSetData($LabelSize,"Dimensione: " & _GetDisplaySize($iSize))
        
        Case $BtnSave
        $sFileSaveDialog = FileSaveDialog("Save files with name ", @DesktopDir , "Files type (*.7z)|Files type (*.zip)", $FD_PATHMUSTEXIST)
        GUICtrlSetData($Out, $sFileSaveDialog)
        If @error Then continueloop 
        
       Case $BtnCompress 
       GUICtrlSetData($progressbar,$cmd)
       If GUICtrlRead($Inp) = "" Then
       MsgBox(48, $FormName, "The boxes must not be empty!")
       ContinueLoop
       EndIf
       If GUICtrlRead($Out) = "" Then
       MsgBox(48, $FormName, "The boxes must not be empty!")
       ContinueLoop
       EndIf 
    _Seven_Zip()    

    Case $BtnCancPass
    GUICtrlSetData($pass,"")
    
    EndSwitch
        If GUICtrlRead($Slider) <> $SliderCorrente Then
        $SliderCorrente = GUICtrlRead($Slider)
        Select
            Case $SliderCorrente = 5
                GUICtrlSetData($CompLabel, "Ultra")
                $livello = 9
            Case $SliderCorrente = 4
                GUICtrlSetData($CompLabel, "Maximum")
                $livello = 7
            Case $SliderCorrente = 3
                GUICtrlSetData($CompLabel, "Normal")
                $livello = 5
            Case $SliderCorrente = 2
                GUICtrlSetData($CompLabel, "Fast")
                $livello = 3
            Case $SliderCorrente = 1
                GUICtrlSetData($CompLabel, "Fastest")
                $livello = 1
            Case $SliderCorrente = 0
                GUICtrlSetData($CompLabel, "Copy")
                $livello = 0
        EndSelect
    EndIf
WEnd

Func _GetDisplaySize($iSize, $iPlaces = 2)
    Local $aBytes[5] = [' Bytes', ' KB', ' MB', ' GB', ' TB']
    For $i = 4 To 1 Step -1
        If $iSize >= 1024 ^ $i Then
            Return Round($iSize / 1024 ^ $i, $iPlaces) & $aBytes[$i]
        EndIf
    Next
    Return $iSize & ' Bytes'
EndFunc


Func _Seven_Zip()   
If GUICtrlRead($pass) = "" Then
$cmd = Run($7zDir & ' a -mx "' & GUICtrlRead($Out) & '" "' & GUICtrlRead($Inp) & '"',"",@SW_HIDE,$STDERR_MERGED)
else
$cmd = Run($7zDir & ' a -mx "' & GUICtrlRead($Out) & '" "' & '"-p"' & GUICtrlRead($pass) & '" "' & GUICtrlRead($Inp) & '\*"',"",@SW_HIDE,$STDERR_MERGED)
GUICtrlSetData($progressbar,100)
ProcessWaitClose ($cmd)
Return StdoutRead($cmd)
endif
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...